This module implements the EBNF parser for native paths and
navigation/location functions.
This modules encapsules native syntaxes for JM2MP. It is invoked
exclusively for the
native query language
QueryAdapter;
there are no other sites of invocation (neither evaluator nor generic
validator).
A native path with text string syntax has following form:
root ( "." identifier | "[" array-index "]" | "[" named-property "]" )*
where root must be one of the following:
$: represents the source document's root value (root).@: represents the current context (ctx).%AliasName: represents a lexical alias bound using alettemplate command (alias).
native syntax also allows $path to be an array literal which
items will represent accessors (strings for named-properties of
objects and natural numbers for indexed-items in arrays); that allows
navigation/location without additional parsing.
In practice, native_paths are really similar to
JSONPointer (external) syntax, which
QueryAdapter
is developed in JSONPointer (module).
Source
Members
EXECUTION_ENVIRONMENT_FROMobject
It lists the starting points of a path from the execution environment.
Type
-
object
Source
Methods
navigate(value, accessors) → {*}
It applies the sequence of accessors to an initial JSON value, navigating/location inside of such value.
It follows the null absorption rule: if in any step the resulting
value is null or the accessor is not applicable (not named
property found, index out of range, dot navigation over scalar value,
...), then the final resultant value will be null.
Parameters
-
value
*The initial JSON value.
-
accessors
Array.<(string|number)>The list of accessors to be orderly applied.
Returns
-
*El valor tras la navegación, o null si la navegación falla. The resultant JSON value found after the navigation/locate.
Throws
-
Whenever ... is not supported.
- Type
-
EvaluationError
Source
parsePath(input) → {ParsedPath}
Parameters
-
input
stringThe input path to parse.
Default Value
- It parses 'input' string as a native path.
Returns
-
ParsedPathThe abstract syntax tree (AST) of 'input' path.
Throws
-
Whenever 'input' string were not a valid path.
Source
isDigit(ch) → {boolean}
True whenever 'ch' is an ASCII digit.
Parameters
-
ch
stringThe character to test.
Returns
-
booleanIs 'ch' in [0-9] ?
Source
isIdentifierContinue(ch) → {boolean}
True whenever 'ch' can continue an identifier (ASCII letter, digit or underline characters).
Parameters
-
ch
stringThe character to test.
Returns
-
booleanIs 'ch' in isIdentifierStart and isDigit ?
Source
isIdentifierStart(ch) → {boolean}
True whenever 'ch' can starts an identifier (ASCII letter or underline characters).
Parameters
-
ch
stringThe character to test.
Returns
-
booleanIs 'ch' in [A-Za-z_] ?
Source
readIdentifier(input, start) → {string|null}
It reads an identifier from 'input' with starting delimiter character
'start'. An identifier starts by [A-Za-z_] (see isIdentifierStart)
and continues by [A-Za-z_0-9] (see isIdentifierContinue).
It returns the identifier found, or null otherwise.
Parameters
-
input
stringThe input string containing the full path.
-
start
numberThe initial position to read the expected identifier.
Returns
-
stringnullThe identifier found, or
nullif no one valid is in such position.
Source
readNonNegativeInteger(input, start) → {Object}
It reads a natural number (non-negative integer) from 'start' position in 'input', and returns its numeric value.
Parameters
-
input
stringThe input string containing the full path.
-
start
numberThe initial position to read the expected natural number.
Returns
-
ObjectTuple with both: numeric value and number of characters consumed by the parser.
Source
readQuotedString(input, start) → {Object}
It reads an string quoted only as JSON supports ("e; is allowed
but not ') from 'input' path, starting at 'start' position
character. It also supports escaping characters like JSON:
\", \\, \/, \b, \f, \n, \r, \t, and \uXXXX.
Parameters
-
input
stringThe input string containing the full path.
-
start
integerThe initial position to read the quoted string, considering that
input[start]must be a"e;.
Returns
-
ObjectTuple with both: unquoted string value and the number of characters consumed by the parser reading the value (and both
"e;s).
Source
Type Definitions
ParsedPath
It represents a parsed path (from string-based syntax).
Type
-
object
Properties
-
kind
"root"|"ctx"|"alias"The base kind of the parsed path.
-
aliasName
string|nullThe name of the alias only if
kindis'alias'; otherwise, it isnull. -
accessors
Array.<(string|number)>The accessors after the base (it is always an array, empty or not).