- grammar
- set
- union
- difference
- charset
- litteral
- nat
- not
- and
- any
- rule
- concat
- choice
- zeroOrOne
- optional
- zeroOrMore
- oneOrMore
- capture
- join
- string
- except
- anyExcept
- Grammar
- parser
- Parser
Return the charset as a string.
Return the union of this charset and the charset defined by specs.
specs...any
Return the difference between this charset and the charset defined by specs.
specs...any
Match one character if present in the given charset.
Charset may be specified either:
- as a range ("0-9");
- as string containing the individual charaters of the set ("0123456789");
- as any iterable over a string (including another Charset object).
specs...any
Match a string of characters.
Capture the entire string
str
Negative lookarround.
Move the token pointer relative to the current position and check the given program do not match. Can be used as a negative lookbehind (delta < 0) or lookafter (delta >= 0). In all cases, restore the input to its previous position on exit.
Capture nothing.
deltaprograms...any
The not predicate.
Succeed if the given program fails with the current input. Do not consume any character.
Capture nothing.
programs...any
The and predicate
Succeed if the given program succeed, but without consuming any character. Can be used as a positive lookahead.
Capture nothing.
programs...any
Match any character. Fail only if there is no more token to process.
Capture the matched character.
Match a rule of the grammar.
namestring The name of the rule to match. The rule does not have already exist. It might be defined later.
Concatenation of several programs.
Will match the sequence: programs[0],programs1,programs2..programs[n]
programs...any
Ordered choice.
Try to match each alternative in its own turn. Stop trying once there is a match. Fail if there is no match.
alternatives...any
The zero-or-one quantifier.
Match 0 or 1 repetition of a program.
If there is no match, capture the undefined special value.
programs...any
A variation of tThe zero-or-one quantifier.
This form takes only one program as an argument, but it allows specifying the default value to substitute if there is no match.
programdefaultValue
The zero-or-more quantifier.
Match 0, 1 or several repetitions of the same program.
programs...any
The one-or-more quantifier.
Match 1 or several repetitions of the same program.
programs...any
Capture the data from a sub-program into an array.
This allow data capture without requiring to define a new rule specifically for that.
programs...any
Capture the data from a sub-program into a string
This allow data capture without requiring to define a new rule specifically for that.
programs...any
Macro equivalent to join(oneOrMore(...)).
Match 1 or several repetition of a pattern and convert the capture into a string.
programs...any
Match any pattern except if ay of the rest PEG match.
Macro equivalent to `not(tail[0]), not(tail1), ... not(tail[n]), head());
headtail...any
Match any character except if ay of the rest PEG match.
Macro equivalent to `not(rest[0]), not(rest1), ... not(rest[n]), any());
rest...any
The Grammar class.
// Create a new grammar
const grammar = new peg.Grammar();Define a new rule.
namestring The name of the ruleprogramaction
Return a new Parser for the grammar.
startstring The name of the rule to match.context
The Parser class.
Dump debugging informations.
The debugging informations contains:
The disassembled code for the VM at the current position. A dump of the backtrack stack. A dump of the operational ("call") stack.
Push a value onto the stack.
value
Test for a character. Fail if it doesn't match.
c
Match any character in a string. Fail if it doesn't match.
set
Move the tx. Fail if it would move before the first token.
delta
Test for any character. Fail if there is no character at the current position (i.e.: before the first or after the last character).
Force a failure. Return to the last saved backtrack point or stop the machine and signal failure.
Stop the machine. Signal success.
Replace the current stack frame by the result of an external (JavaScript) function.
fct
Jump to subroutine (or subrule ?)
Save the current pc and code, then jump on the first instruction for the given nonterminal.
nonterminal
Return from a call.
fct
- **See: drop() **
- **See: reduce() **
Create a stack frame.
- **See: frame() **
- **See: reduce() **
Drop the current stack frame.
- **See: drop() **
- **See: frame() **
Reduce the current stack frame to only one item. If a callable is given as a parameter, replace the current stack frame by the result of the function applied to the data on the frame. If no user function is specified, pack the data in an array.
fctcallable? The callable to use to pack the data.
Create a backtracking entry on the stack
offset
Commit a choice. Discard the topmost backtrack stack entry and jump to instruction.
offsetinteger The position of the next instruction to execute, relative to the current pc.
accept one or more characters. Run the machine as long as we have token to process.
tokens
continue execution until the machine stops.
Call this function when you now there will no more tokens to append using the accept() call.
Restart the parser at the current token
XXX Is this private?
Skip n tokens from the input
XXX Is this private?
n
Return the top-most object on the stack if the machine has stopped. Return undefined otherwise
Return a generator for all the tokens parts matching the parser's grammar, possibly skipping an arbitrary number of input tokens betwenn matches.