Clarify initializer documentation

Make it clear that there is only one initializer in the whole grammar.
The previous formulation could have been understood to mean that there
can be an initializer for every rule in the grammar.

Fixes #82.
redux
David Majda 10 years ago
parent 39084496ca
commit 5a02bca34d

@ -182,14 +182,14 @@ written as a JavaScript string between the name and separating equality sign.
Rules need to be separated only by whitespace (their beginning is easily Rules need to be separated only by whitespace (their beginning is easily
recognizable), but a semicolon (“;”) after the parsing expression is allowed. recognizable), but a semicolon (“;”) after the parsing expression is allowed.
Rules can be preceded by an *initializer* — a piece of JavaScript code in curly The first rule can be preceded by an *initializer* — a piece of JavaScript code
braces (“{” and “}”). This code is executed before the generated parser starts in curly braces (“{” and “}”). This code is executed before the generated parser
parsing. All variables and functions defined in the initializer are accessible starts parsing. All variables and functions defined in the initializer are
in rule actions and semantic predicates. The code inside the initializer can accessible in rule actions and semantic predicates. The code inside the
access the parser object using the `parser` variable and options passed to the initializer can access the parser object using the `parser` variable and options
parser using the `options` variable. Curly braces in the initializer code must passed to the parser using the `options` variable. Curly braces in the
be balanced. Let's look at the example grammar from above using a simple initializer code must be balanced. Let's look at the example grammar from above
initializer. using a simple initializer.
{ {
function makeInteger(o) { function makeInteger(o) {

Loading…
Cancel
Save