Class: Parser

Base~ Parser

Abstract base class for recognition based on a grammar. Should wrap a method parse() which recognizes input, builds a tree of nested lists, and creates and calls on an object with action methods, if any.


<abstract> new Parser(grammar)

Creates a parser; only used by subclass to set .grammar.

Parameters:
Name Type Description
grammar module:Base~Factory

represents grammar.

Properties:
Name Type Argument Description
grammar module:Base~Factory

represents the grammar, counts errors; concurrent recognition will trash error counting.

actions Object <nullable>

maps rule names to action methods during recognition.

Source:

Methods


act(name, result)

Calls an action method. Checks argument count unless grammar.config.noargs is set or the method expects no arguments, i.e., has a rest parameter.

Parameters:
Name Type Description
name string

rule name to match.

result Array

list of arguments.

Source:
Returns:

action method result or unchanged result.


call(target, method, args)

Checks if argument and parameter count of a method match unless the method expects no parameters, or has a rest parameter or grammar.config.noargs is true.

Parameters:
Name Type Argument Description
target object

to apply method to.

method function

to check.

args Object <repeatable>

arguments to pass.

Source:
Returns:

method result.

Type
Object
Example

super.method(arg1, .. argn)

this.parser.call(this, super.method, arg1, .. argn)

parse( [actions], arg)

Only used by subclass to set .actions; resets .errors for the grammar. Should recognize an input sentence.

Parameters:
Name Type Argument Description
actions function | Object <optional>

a function is assumed to be a class and a singleton is created with this as constructor argument. The object maps rule names to action methods.

arg Object <repeatable>

used as further constructor arguments.

Source: