Class: Rule

EBNF~ Rule

Represents an EBNF rule.


new Rule(nt, seqs)

Creates an EBNF rule; see rule() factory method.

Parameters:
Name Type Description
nt module:EBNF~NT

left-hand side, non-terminal.

seqs Array.<module:EBNF~Seq>

the alternatives on the right-hand side.

Properties:
Name Type Argument Description
nt module:EBNF~NT

rule's non-terminal (left-hand side).

recursed number

counts nesting during shallow lookahead computation for all rules.

reached boolean

true if rule is reached during deep lookahead computation from the start rule; avoids multiple computations.

seqs Array.<module:EBNF~Seq>

the alternatives.

expect module:EBNF~Set

set of terminals which a node expects to see as parser.current.t, maps terminal names to true; expect is not empty.

follow module:EBNF~Set <nullable>

see node.follow().

Source:

Extends

Methods


check(error, name)

Check for ambiguity: descendants' expect must be disjoint.

Parameters:
Name Type Description
error function

should be bound to grammar.error().

name string

current rule.

Inherited From:
Overrides:
Source:
Returns:

error message, if any.

Type
undefined | string

deep()

Override getter: sets .reached, inherits: computes the set as sum over all descendants.

Overrides:
Source:
See:
  • {linkcode module:EBNF~Node#deep Node.deep(increment)}.
Returns:

the set, maps terminal names to true.

Type
module:EBNF~Set

follow( [increment])

Override setter: sets me and all descendants.

Parameters:
Name Type Argument Description
increment module:EBNF~Set <optional>
<nullable>

controls getter/setter behavior, setter adds.

Inherited From:
Overrides:
Source:
See:
  • {linkcode module:EBNF~Node#follow Node.fallow(increment)}.
Returns:

the set, maps terminal names to true.

Type
module:EBNF~Set

parse(parser)

Delegates to superclass to recognize the descendants and processes the result with the corresponding action if any. The rule name selects either a function-valued property or a method of the actions object.

Parameters:
Name Type Description
parser module:EBNF~Parser

context.

Overrides:
Source:
Throws:

if recognition fails or if the action throws.

Type
string
Returns:

the result produced by the selected descendant and modified by the action, if any, see parser.parse().


shallow( [increment])

Override getter: if left recursion returns empty set (which cannot happen...); otherwise inherits: computes the set as sum over all descendants.

Parameters:
Name Type Argument Description
increment module:EBNF~Set <optional>
<nullable>

controls getter/setter behavior, setter adds.

Overrides:
Source:
See:
  • {linkcode module:EBNF~Node#shallow Node.shallow(increment)}.
Returns:

the (incremented) set, maps terminal names to true.

Type
module:EBNF~Set

toString()

Displays a rule in EBNF notation.

Overrides:
Source:
Returns:
Type
string