Members
(constant) tokens
Tokens object: definitions
- Source:
Methods
buildLexer(regexps) → {Object}
Creates a lexical analyzer
Parameters:
| Name | Type | Description |
|---|---|---|
regexps |
array | An array of regular expressions.
Regexps must be named using a parenthesis. Example: |
- Source:
Throws:
-
Will throw if each regular expression isn't named or has more than one name
- Type
- Error
Returns:
The map of valid tokens and a lexical analyzer in form of a function
- Type
- Object
buildNestedApplies(parenExp, applies) → {Array}
Builds an array of nested applies.
Parameters:
| Name | Type | Description |
|---|---|---|
parenExp |
Array | The expression enclosed in parentheses. |
applies |
Array | The array of applies. |
- Source:
Returns:
- The array of nested applies.
- Type
- Array
buildNumberValue(token) → {Object}
Builds a number value object from a token.
Parameters:
| Name | Type | Description |
|---|---|---|
token |
Array | The token array containing the number value. |
- Source:
Returns:
The number value object.
- Type
- Object
buildStringValue(token) → {Object}
Builds a string value object from a token.
Parameters:
| Name | Type | Description |
|---|---|---|
token |
Array | The token array containing the string value. |
- Source:
Returns:
- The string value object with type, value, and raw properties.
- Type
- Object
buildWordApplies(wordApplies, wordApplies[0, wordApplies[1) → {Object}
Builds an Abstract Syntax Tree (AST) for a word and its applies.
Parameters:
| Name | Type | Description |
|---|---|---|
wordApplies |
Array | An array containing a word and its applies. |
wordApplies[0 |
Object | The word object. |
wordApplies[1 |
Array | An array of applies. |
- Source:
Returns:
- The constructed AST.
- Type
- Object
compile(origin, destinationopt) → {void}
Compiles the given origin file into an abstract syntax tree (AST) and writes it to the destination file. If no destination file is provided, it will use the same name as the origin file with a '.json' extension.
Parameters:
| Name | Type | Attributes | Description |
|---|---|---|---|
origin |
string | The path of the origin file to compile. |
|
destination |
string |
<optional> |
The path of the destination file to write the compiled AST. If not provided, a default destination file will be used. |
- Source:
Returns:
- Type
- void
formatError()
Returns a string with an error message describing the line/col of the offending token. You might like to include a preview of the line in question.
- Source:
next()
Returns e.g. {type, value, line, col, …}. Only the value attribute is required.
- Source:
parseFromFile(origin)
A function that parses a egg file
Parameters:
| Name | Type | Description |
|---|---|---|
origin |
string | The name of the origin file |
- Source:
Throws:
Will throw if there are errors in the program or if the files can't be opened
reset()
Sets the internal buffer to data, and restores line/col/state info taken from save(). Compatibility not tested
- Source:
save()
Returns an object describing the current line/col etc. This allows nearley.JS to preserve this information between feed() calls, and also to support Parser#rewind(). The exact structure is lexer-specific; nearley doesn't care what's in it.
- Source: