KADABRA API

LARA API

LARA Common Language API

(.js)
laraImport("weaver.Query");

(.lara)
import weaver.Query;

Query

Query

Query

Class for selection of join points. Provides an API similar to the keyword 'select'.

Search functions of this class return weaver.Selector objects, please refer to that class for more details regarding available functions and search options.


Static Members

childrenFrom

childrenFrom($baseJp, type, [filter = {}])

Search the direct children of the given $baseJp.

Parameters

$baseJp: $jp - starting join point for the search.
type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. (optional)

Returns

weaver.Selector - the results of the search.

root

root()

Returns the root node of the current AST.

Returns

$jp - the root node

scopeFrom

scopeFrom($baseJp, type, [filter = {}])

If $baseJp has the concept of scope (e.g. if, loop), search the direct children of that scope.

Parameters

$baseJp: $jp - starting join point for the search.
type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. (optional)

Returns

weaver.Selector - the results of the search.

search

search(type, [filter = {}], [traversal = TraversalType.PREORDER])

The same as Query.searchFrom(), but uses the root node as $baseJp.

Parameters

type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. If the value is an object, each field of the object represents a rule that will be applied over the attribute that has the same name as the name of the field. If the value is not an object (e.g., String, Regex, Lambda), it is interpreted as a single rule that will be applied over the default attribute of the given type. E.g., if type is 'function', the value is a String 'foo' and the default attribute of function is 'name', this is equivalent as passing as value the object {'name':'foo'}. Rules can be a String (i.e., will match the value of the attribute against a string), a Regex (will match the value of the attribute against a regex) or a Function (i.e., function receives the value of the attribute and returns true if there is a match, or false otherwise). (optional)
traversal: String - AST traversal type, according to weaver.TraversalType (optional)

Returns

weaver.Selector - the results of the search.

searchFrom

searchFrom($baseJp, type, [filter = {}], [traversal = TraversalType.PREORDER])

In-depth search of nodes of the given type, starting from a base node (exclusive).

Parameters

$baseJp: $jp - starting join point for the search.
type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. If the value is an object, each field of the object represents a rule that will be applied over the attribute that has the same name as the name of the field. If the value is not an object (e.g., String, Regex, Lambda), it is interpreted as a single rule that will be applied over the default attribute of the given type. E.g., if type is 'function', the value is a String 'foo' and the default attribute of function is 'name', this is equivalent as passing as value the object {'name':'foo'}. Rules can be a String (i.e., will match the value of the attribute against a string), a Regex (will match the value of the attribute against a regex) or a Function (i.e., function receives the value of the attribute and returns true if there is a match, or false otherwise). (optional)
traversal: String - AST traversal type, according to weaver.TraversalType (optional)

Returns

weaver.Selector - the results of the search.

searchFromInclusive

searchFromInclusive($baseJp, type, [filter = {}], [traversal = TraversalType.PREORDER])

The same as Query.searchFrom(), but $baseJp is included in the search.

Parameters

$baseJp: $jp - starting join point for the search.
type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. (optional)
traversal: String - AST traversal type, according to weaver.TraversalType (optional)

Returns

weaver.Selector - the results of the search.

Global Functions

search

search(type, [filter = {}], [traversal = TraversalType.PREORDER])

The same as Query.search(), but available as a global function.

Parameters

type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. (optional)
traversal: String - AST traversal type, according to weaver.TraversalType (optional)

Returns

weaver.Selector - the results of the search.

searchFrom

searchFrom($baseJp, type, [filter = {}], [traversal = TraversalType.PREORDER])

The same as Query.searchFrom(), but available as a global function.

Parameters

$baseJp: $jp - starting join point for the search.
type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. (optional)
traversal: String - AST traversal type, according to weaver.TraversalType (optional)

Returns

weaver.Selector - the results of the search.

searchFromInclusive

searchFromInclusive($baseJp, type, [filter = {}], [traversal = TraversalType.PREORDER])

The same as Query.searchFromInclusive(), but available as a global function.

Parameters

$baseJp: $jp - starting join point for the search.
type: String - type of the join point to search.
filter: Object|String|Function|Regex - filter rules for the search. (optional)
traversal: String - AST traversal type, according to weaver.TraversalType (optional)

Returns

weaver.Selector - the results of the search.