Namespace: page

page

Object-oriented parser generator system supporting BNF and EBNF grammar representations and tokenizer, LL(1), and naive LR(1) parser generation.

Source:

Classes

BNF
BNFP
EBNF
EBNFP
LL1
SLR1
Tuple

Methods


<static> assert(_marker [, _condition])

Used for type-checking and other assertion checking. Template method, could be overwritten in any baseclass.

Parameters:
Name Type Argument Description
_marker string

to identify position across a re-throw.

_condition boolean <optional>

should be true.

Source:
See:
Throws:

if a condition is not present or not met.

Type
Error

<static> baseclass(_constructor, _className)

Provides assert, error, message, and subclass methods and className property for a new class.

Parameters:
Name Type Description
_constructor function

new class' constructor function.

_className string

new class' name.

Source:
See:
Example
page.baseclass(page.BNF, 'page.BNF');

<static> error(arguments)

Prefixes message with error: and delegates to page.message. Increments this.errors if it exists. Template method, could be overwritten in any baseclass.

Parameters:
Name Type Description
arguments string

message strings, will be joined with blanks.

Source:
See:
Example
aBNF.error('example', 'message')

<static> escape(_s)

Escapes non-ASCII and invisible characters using backslash.

Parameters:
Name Type Description
_s string

string to escape.

Source:
Returns:

single-quoted, escaped string.

Type
string

<static> merge(_a, _b)

Adds one map to another.

Parameters:
Name Type Description
_a Map

to add to.

_b Map

to add.

Source:
Returns:

true if one or more keys were added.

Type
boolean

<static> message(arguments)

Prints a message. Template method, could be overwritten in any baseclass.

Parameters:
Name Type Description
arguments string

message strings, will be joined with blanks.

Source:
See:

<static> overlap(_a, _b)

Compares two maps, i.e., checks if two objects contain properties with the same key.

Parameters:
Name Type Description
_a Map

to check.

_b Map

to check.

Source:
Returns:

true if there are common property keys.

Type
boolean

<static> subclass(_constructor, _className, _superclass)

Connects subclass to superclass. Arranges for inheritance, className, and instanceof. Template method, could be overwritten in any baseclass. Taken from here.

Note that there can't be a method similar to super in Java because super is implemented with a lexical search above the current class — it can't be applied to this.

Parameters:
Name Type Description
_constructor function

subclass' constructor function.

_className string

new subclass' name.

_superclass function

superclass' constructor function.

Source:
Example
page.subclass(page.BNF.Lit, 'page.BNF.Lit', page.BNF.T);

<static> trace( [_observe] [, _match])

Creates a function which can observe any parsing function and display the messages after it passes them through to another observer, if any. It will return the value from the observer, the information for an error action, or null. The function is serially reusable; when first accessed it will print a line to label the output columns.

Parameters:
Name Type Argument Description
_observe Observer <optional>

next observer function to delegate to, if any.

_match RegExp <optional>

if specified, selects the actions to be printed.

Source:
See:
Returns:

a function which can observe a parsing algorithm.

Type
Observer

<static> unescape(_s)

Unescapes the result of page.escape and removes leading and trailing delimiter character.

Parameters:
Name Type Description
_s string

string to unescape.

Source:
Returns:

unquoted, unescaped string.

Type
string

<static> uneval(_o [, _indent])

Rescursively displays a recursive Array or object aggregate containing boolean, number, or string values as leaves. This is similar to JSON.stringify but perhaps prettier.

Parameters:
Name Type Argument Description
_o object

object to display.

_indent string <optional>

indentation prefix.

Source:
Returns:
Type
string
Example
// the operation can be reversed
eval('obj = '+page.uneval(obj))