Comparing version 1.3.0 to 1.4.0
{ | ||
"name": "astq", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Abstract Syntax Tree (AST) Query Engine", | ||
@@ -5,0 +5,0 @@ "main": "lib/astq.browser.js", |
{ | ||
"name": "astq", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Abstract Syntax Tree (AST) Query Engine", | ||
@@ -5,0 +5,0 @@ "keywords": [ "abstract", "syntax", "tree", "query", "engine", "adaptable" ], |
@@ -82,3 +82,3 @@ | ||
axis ::= "//" | "/" | "+//" | "+/" | "-//" | "-/" | "../" | "..//" | ||
axis ::= ("//" | "/" | "+//" | "+/" | "-//" | "-/" | "../" | "..//") (":" id)? | ||
match ::= id | "*" | ||
@@ -134,3 +134,8 @@ filter ::= "[" expr "]" | ||
query-parameter ::= "{" id "}" | ||
id ::= /[a-zA-Z_][a-zA-Z0-9_-]*/ | ||
literal ::= string | regexp | number | value | ||
string ::= /"(\\"|.)*"/ | /'(\\'|.)*'/ | ||
regexp ::= /`(\\`|.)*`/ | ||
number ::= /\d+(\.\d+)?$/ | ||
value ::= "true" | "false" | "null" | "NaN" | "undefined" | ||
parenthesis ::= "(" expr ")" | ||
@@ -137,0 +142,0 @@ sub-query ::= path // <-- ESSENTIAL RECURSION !! |
@@ -32,6 +32,6 @@ /* | ||
} | ||
static getParentNode (node) { | ||
static getParentNode (node /*, type */) { | ||
return node.parent() | ||
} | ||
static getChildNodes (node) { | ||
static getChildNodes (node /*, type */) { | ||
return node.childs() | ||
@@ -38,0 +38,0 @@ } |
@@ -36,8 +36,13 @@ /* | ||
} | ||
static getParentNode (/* node */) { | ||
throw new Error("Mozilla SpiderMonkey AST does not support parent node traversal") | ||
static getParentNode (node, type) { | ||
if (type !== "*" && type !== "parent") | ||
throw new Error("no such axis named \"" + type + "\" for walking to parent nodes") | ||
if (typeof node.parent !== "undefined") | ||
return node.parent | ||
else | ||
throw new Error("Your Mozilla SpiderMonkey AST does not support parent node traversal") | ||
} | ||
static getChildNodes (node) { | ||
static getChildNodes (node, type) { | ||
let childs = [] | ||
for (let field in node) { | ||
let checkField = (node, field) => { | ||
if ( node.hasOwnProperty(field) | ||
@@ -55,2 +60,11 @@ && this.taste(node[field])) | ||
} | ||
if (type === "*") { | ||
for (let field in node) | ||
checkField(node, field) | ||
} | ||
else { | ||
if (typeof node[type] === "undefined") | ||
throw new Error("no such axis named \"" + type + "\" for walking to child nodes") | ||
checkField(node, type) | ||
} | ||
return childs | ||
@@ -57,0 +71,0 @@ } |
@@ -36,6 +36,6 @@ /* | ||
} | ||
static getParentNode (node) { | ||
static getParentNode (node /*, type */) { | ||
return node.parentNode | ||
} | ||
static getChildNodes (node) { | ||
static getChildNodes (node /*, type */) { | ||
return node.childNodes | ||
@@ -42,0 +42,0 @@ } |
@@ -35,3 +35,3 @@ /* | ||
let node = T | ||
while ((node = A.getParentNode(node)) !== null) | ||
while ((node = A.getParentNode(node, "*")) !== null) | ||
depth++ | ||
@@ -43,6 +43,6 @@ return depth | ||
"pos": (A, T) => { | ||
let parent = A.getParentNode(T) | ||
let parent = A.getParentNode(T, "*") | ||
if (parent === null) | ||
return 1 | ||
let pchilds = A.getChildNodes(parent) | ||
let pchilds = A.getChildNodes(parent, "*") | ||
for (let i = 0; i < pchilds.length; i++) | ||
@@ -57,5 +57,5 @@ if (pchilds[i] === T) | ||
num = parseInt(num, 10) | ||
let parent = A.getParentNode(T) | ||
let parent = A.getParentNode(T, "*") | ||
if (parent !== null) { | ||
let pchilds = A.getChildNodes(parent) | ||
let pchilds = A.getChildNodes(parent, "*") | ||
if (num < 0) | ||
@@ -62,0 +62,0 @@ num = pchilds - (num + 1) |
@@ -98,5 +98,6 @@ /* | ||
let op = axis.get("op") | ||
let t = axis.get("type") | ||
if (op === "/") { | ||
/* direct child nodes */ | ||
this.adapter.getChildNodes(T).forEach((T) => matchAndTake(T)) | ||
this.adapter.getChildNodes(T, t).forEach((T) => matchAndTake(T)) | ||
} | ||
@@ -107,11 +108,11 @@ else if (op === "//") { | ||
matchAndTake(T) | ||
this.adapter.getChildNodes(T).forEach((T) => walk(T)) /* RECURSION */ | ||
this.adapter.getChildNodes(T, t).forEach((T) => walk(T)) /* RECURSION */ | ||
} | ||
this.adapter.getChildNodes(T).forEach((T) => walk(T)) | ||
this.adapter.getChildNodes(T, t).forEach((T) => walk(T)) | ||
} | ||
else if (op === "-/") { | ||
/* direct left sibling */ | ||
let parent = this.adapter.getParentNode(T) | ||
let parent = this.adapter.getParentNode(T, "*") | ||
if (parent !== null) { | ||
let pchilds = this.adapter.getChildNodes(parent) | ||
let pchilds = this.adapter.getChildNodes(parent, t) | ||
let leftSibling = null | ||
@@ -128,5 +129,5 @@ for (let i = 0; i < pchilds.length; i++) { | ||
/* transitive left siblings */ | ||
let parent = this.adapter.getParentNode(T) | ||
let parent = this.adapter.getParentNode(T, "*") | ||
if (parent !== null) { | ||
let pchilds = this.adapter.getChildNodes(parent) | ||
let pchilds = this.adapter.getChildNodes(parent, t) | ||
for (let i = 0; i < pchilds.length; i++) { | ||
@@ -141,5 +142,5 @@ if (pchilds[i] === T) | ||
/* direct right sibling */ | ||
let parent = this.adapter.getParentNode(T) | ||
let parent = this.adapter.getParentNode(T, "*") | ||
if (parent !== null) { | ||
let pchilds = this.adapter.getChildNodes(parent) | ||
let pchilds = this.adapter.getChildNodes(parent, t) | ||
let i | ||
@@ -157,5 +158,5 @@ for (i = 0; i < pchilds.length; i++) | ||
/* transitive right siblings */ | ||
let parent = this.adapter.getParentNode(T) | ||
let parent = this.adapter.getParentNode(T, "*") | ||
if (parent !== null) { | ||
let pchilds = this.adapter.getChildNodes(parent) | ||
let pchilds = this.adapter.getChildNodes(parent, t) | ||
let i | ||
@@ -174,3 +175,3 @@ for (i = 0; i < pchilds.length; i++) | ||
/* direct parent */ | ||
let parent = this.adapter.getParentNode(T) | ||
let parent = this.adapter.getParentNode(T, t) | ||
if (parent !== null) | ||
@@ -183,3 +184,3 @@ matchAndTake(parent) | ||
while (true) { | ||
let parent = this.adapter.getParentNode(node) | ||
let parent = this.adapter.getParentNode(node, t) | ||
if (parent === null) | ||
@@ -186,0 +187,0 @@ break |
@@ -37,3 +37,3 @@ /* | ||
node = T | ||
while ((node = this.adapter.getParentNode(node)) !== null) | ||
while ((node = this.adapter.getParentNode(node, "*")) !== null) | ||
depth++ | ||
@@ -40,0 +40,0 @@ let prefix2 = util.pad("", 4 * depth) |
@@ -71,12 +71,16 @@ /* | ||
case "boolean": | ||
value = Boolean(value) | ||
if (typeof value !== "boolean") | ||
value = Boolean(value) | ||
break | ||
case "number": | ||
value = Number(value) | ||
if (typeof value !== "number") | ||
value = Number(value) | ||
break | ||
case "string": | ||
value = String(value) | ||
if (typeof value !== "string") | ||
value = String(value) | ||
break | ||
case "regexp": | ||
value = new RegExp(value) | ||
if (!(typeof value === "object" && value instanceof RegExp)) | ||
value = new RegExp(value) | ||
break | ||
@@ -83,0 +87,0 @@ } |
@@ -79,4 +79,5 @@ /* | ||
expect(astq.query(node1, "// * [ depth() == 3 ]", {}, true)).to.have.members([ node5, node6, node7 ]) | ||
expect(astq.query(node1, "/ node2 ../ node1 / node2")).to.have.members([ node2 ]) | ||
}) | ||
}) | ||
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
491334
6773
268