Comparing version 1.6.4 to 1.7.0
{ | ||
"name": "astq", | ||
"version": "1.6.4", | ||
"version": "1.7.0", | ||
"description": "Abstract Syntax Tree (AST) Query Engine", | ||
@@ -5,0 +5,0 @@ "main": "lib/astq.browser.js", |
{ | ||
"name": "astq", | ||
"version": "1.6.4", | ||
"version": "1.7.0", | ||
"description": "Abstract Syntax Tree (AST) Query Engine", | ||
@@ -21,6 +21,6 @@ "keywords": [ "abstract", "syntax", "tree", "query", "engine", "adaptable" ], | ||
"pegjs": "~0.9.0", | ||
"pegjs-otf": "~1.1.3", | ||
"pegjs-util": "~1.3.3", | ||
"asty": "~1.4.4", | ||
"cache-lru": "~1.0.11" | ||
"pegjs-otf": "~1.1.4", | ||
"pegjs-util": "~1.3.5", | ||
"asty": "~1.4.5", | ||
"cache-lru": "~1.0.12" | ||
}, | ||
@@ -33,7 +33,7 @@ "devDependencies": { | ||
"grunt-browserify": "~5.0.0", | ||
"grunt-jscs": "~2.8.0", | ||
"grunt-jscs": "~3.0.1", | ||
"grunt-mocha-test": "~0.12.7", | ||
"grunt-eslint": "~18.1.0", | ||
"babel-eslint": "~6.0.4", | ||
"mocha": "~2.4.5", | ||
"babel-eslint": "~6.1.0", | ||
"mocha": "~2.5.3", | ||
"chai": "~3.5.0", | ||
@@ -40,0 +40,0 @@ "babelify": "~7.3.0", |
@@ -72,9 +72,9 @@ | ||
steps require it. A query step consists of an (optional) AST node search | ||
axis, a (mandatory) AST node type match and an (optional) AST node | ||
filter expression: | ||
axis, a (mandatory) AST node type match, an (optional) result marker "!" | ||
and an (optional) AST node filter expression: | ||
query ::= path (, path)* | ||
path ::= step-initial step-subsequent* | ||
step-initial ::= axis? match filter? | ||
step-subsequent ::= axis match filter? | ||
step-initial ::= axis? match result? filter? | ||
step-subsequent ::= axis match result? filter? | ||
@@ -138,2 +138,3 @@ The search axis can be either for direct (`/`) or any (`//`) child | ||
axis-type ::= ":" id | ||
result ::= "!" | ||
match ::= id | "*" | ||
@@ -159,6 +160,7 @@ filter ::= "[" expr "]" | ||
The result of a query are always all nodes which match against the last | ||
query step of any path. The queries in filter expressions just lead to | ||
a boolean decision for the filter, but never cause any resulting nodes | ||
theirself. | ||
The result of a query is always all nodes which match against the last | ||
query step of any path (in case of no result marker on any step in the | ||
path) or all nodes of matched steps with a result marker. The queries in | ||
filter expressions just lead to a boolean decision for the filter, but | ||
never cause any resulting nodes theirself. | ||
@@ -207,14 +209,14 @@ An expression can be either a ternary/binary conditional expression, | ||
Return type of current node. | ||
Example: `type() === "foo"` | ||
Example: `type() == "foo"` | ||
- `depth(): Number`:<br/> | ||
Return depth in AST of current node (counting from 1 for the root node). | ||
Example: `depth() <= 3` | ||
Example: `depth() <= 3` | ||
- `pos(): Number`:<br/> | ||
Return position of current node among sibling (counting from 1 first the first sibling). | ||
Example: `pos() === 2` | ||
Return position of current node among sibling (counting from 1 for the first sibling). | ||
Example: `pos() == 2` | ||
- `nth(pos: Number): Boolean`:<br/> | ||
Check whether position of current node among sibling is `pos` (counting from 1 fir | ||
Check whether position of current node among sibling is `pos` (counting from 1 for | ||
the first sibling). Negative values for `pos` count from the last sibling backward, | ||
@@ -237,3 +239,4 @@ i.e., `-1` is the last sibling. | ||
Checks whether current node is somewhere below `node`, i.e., | ||
whether current node is a child or descendant of `node`. | ||
whether current node is a child or descendant of `node`. Usually, | ||
this makes sense only if `node` is an externally passed-in parameter. | ||
Example: `below({node})`. | ||
@@ -245,2 +248,3 @@ | ||
depth-first tree visit (where parents are visited before childs). | ||
Usually, this makes sense only if `node` is an externally passed-in parameter. | ||
Example: `follows({node})`. | ||
@@ -250,16 +254,26 @@ | ||
Checks whether current node is in `nodes`. | ||
The `nodes` usually is either an externally passed-in parameter or a sub-query. | ||
Example: `in({nodes})` | ||
Usually, `nodes` is either an externally passed-in parameter or a sub-query. | ||
Example: `in({nodes})`. | ||
- `substr(str: String, pos: Number, len: Number): String`:<br/> | ||
Returns the sub-string of `str`, starting at `pos` with length `len`. | ||
Negative values for `pos` count from the end of the string, | ||
i.e., `-1` is the last character. | ||
Example: `substr(@foo, 0, 1) == "A"` | ||
- `index(str: String, sub: String, pos: Number): Number`:<br/> | ||
Returns the index position of sub-string `sub` in string `str`, starting at `pos`. | ||
Example: `indexof(@foo, "bar", 0) >= 0` | ||
- `trim(str: String): String`:<br/> | ||
Returns the string `str` with whitespaces removed from begin and end. | ||
Example: `trim(@foo) == "bar"` | ||
- `lc(str: String): String`:<br/> | ||
Returns the lower-case variant of `str`. | ||
Example: `lc(@foo) == "a"` | ||
Example: `lc(@foo) == "bar"` | ||
- `uc(str: String): String`:<br/> | ||
Returns the upper-case variant of `str`. | ||
Example: `uc(@foo) == "A"` | ||
Example: `uc(@foo) == "BAR"` | ||
@@ -266,0 +280,0 @@ Application Programming Interface (API) |
@@ -26,3 +26,3 @@ /* | ||
/* internal helper function: find position between siblings */ | ||
let pos = (A, T) => { | ||
const pos = (A, T) => { | ||
let parent = A.getParentNode(T, "*") | ||
@@ -39,3 +39,3 @@ if (parent === null) | ||
/* internal helper function: find parent nodes */ | ||
let parents = (A, T) => { | ||
const parents = (A, T) => { | ||
let parents = [] | ||
@@ -48,3 +48,3 @@ while ((T = A.getParentNode(T, "*")) !== null) | ||
/* the exported standard functions */ | ||
let stdfuncs = { | ||
const stdfuncs = { | ||
/* type name of node */ | ||
@@ -161,2 +161,12 @@ "type": (A, T) => { | ||
/* retrieve index of a sub-string */ | ||
"index": (A, T, str, sub, from) => { | ||
return String(str).indexOf(sub, from) | ||
}, | ||
/* remove whitespaces at begin and end of string */ | ||
"trim": (A, T, str) => { | ||
return String(str).trim() | ||
}, | ||
/* convert string to lower-case */ | ||
@@ -163,0 +173,0 @@ "lc": (A, T, str) => { |
@@ -40,5 +40,8 @@ /* | ||
let output = [] | ||
/* iterate over all query paths */ | ||
Q.childs().forEach((Q) => { | ||
output = output.concat(this.execPath(Q, T)) | ||
}) | ||
this.traceEnd(Q, T, output) | ||
@@ -51,2 +54,6 @@ return output | ||
let nodes = [ T ] | ||
let result = [] | ||
let resultExplicit = false | ||
/* iterate over all steps of a query path */ | ||
Q.childs().forEach((Q) => { | ||
@@ -58,5 +65,10 @@ let output = [] | ||
nodes = output | ||
if (Q.get("isResult")) { | ||
resultExplicit = true | ||
result = result.concat(nodes) | ||
} | ||
}) | ||
this.traceEnd(Q, T, nodes) | ||
return nodes | ||
return (resultExplicit ? result : nodes) | ||
} | ||
@@ -63,0 +75,0 @@ |
@@ -30,8 +30,8 @@ /* | ||
/* load external dependencies */ | ||
let ASTY = require("asty") | ||
let PEG = require("pegjs-otf") | ||
let PEGUtil = require("pegjs-util") | ||
const ASTY = require("asty") | ||
const PEG = require("pegjs-otf") | ||
const PEGUtil = require("pegjs-util") | ||
/* get query parser (by loading and on-the-fly compiling PEG.js grammar) */ | ||
let ASTQQueryParse = PEG.buildParserFromFile( | ||
const ASTQQueryParse = PEG.buildParserFromFile( | ||
__dirname + "/astq-query-parse.pegjs", | ||
@@ -57,3 +57,3 @@ { optimize: "speed", cache: true } | ||
console.log("ASTQ: compile: +---------------------------------------" + | ||
"----------------------------------------------------------------\n" + | ||
"----------------------------------------------------------------\n" + | ||
"ASTQ: compile: | " + selector) | ||
@@ -72,3 +72,3 @@ let result = PEGUtil.parse(ASTQQueryParse, selector, { | ||
console.log("ASTQ: compile: +---------------------------------------" + | ||
"----------------------------------------------------------------\n" + | ||
"----------------------------------------------------------------\n" + | ||
this.dump().replace(/\n$/, "").replace(/^/mg, "ASTQ: compile: | ")) | ||
@@ -87,3 +87,3 @@ return this | ||
console.log("ASTQ: execute: +---------------------------------------" + | ||
"-----------------------+----------------------------------------") | ||
"-----------------------+----------------------------------------") | ||
let qe = new ASTQQueryExec(adapter, params, funcs, trace) | ||
@@ -90,0 +90,0 @@ return qe.execQuery(this.ast, node) |
@@ -44,5 +44,5 @@ /* | ||
this._adapter = new ASTQAdapter() | ||
this._adapter.register(ASTQAdapterMOZAST) | ||
this._adapter.register(ASTQAdapterXMLDOM) | ||
this._adapter.register(ASTQAdapterASTY) | ||
.register(ASTQAdapterMOZAST) | ||
.register(ASTQAdapterXMLDOM) | ||
.register(ASTQAdapterASTY) | ||
@@ -49,0 +49,0 @@ /* create function registry and pre-register standard functions */ |
@@ -54,2 +54,14 @@ /* | ||
astq.func("add", function (a, b) { return a + b }) | ||
/* | ||
* node1 | ||
* node2 | ||
* node3 | ||
* node5 | ||
* node6 | ||
* node8 | ||
* node9 | ||
* node7 | ||
* node4 | ||
*/ | ||
var ASTY = require("asty") | ||
@@ -125,3 +137,11 @@ var asty = new ASTY() | ||
}) | ||
it("result marking", function () { | ||
expect(astq.query(node1, "* ! / * / * /*")).to.be.deep.equal([ node1 ]) | ||
expect(astq.query(node1, "* / * ! / * /*")).to.be.deep.equal([ node2, node3, node4 ]) | ||
expect(astq.query(node1, "* / * / * ! /*")).to.be.deep.equal([ node5, node6, node7 ]) | ||
expect(astq.query(node1, "* / * / * / * !")).to.be.deep.equal([ node8, node9 ]) | ||
expect(astq.query(node1, "* / * ! [ count(/ * ! / *) == 3 ]")).to.be.deep.equal([ node3 ]) | ||
}) | ||
}) | ||
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
555335
7319
444
Updatedasty@~1.4.5
Updatedcache-lru@~1.0.12
Updatedpegjs-otf@~1.1.4
Updatedpegjs-util@~1.3.5