Object-oriented parser generator system supporting BNF and EBNF grammar representations and tokenizer, LL(1), and naive LR(1) parser generation.
Classes
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 _markerstring to identify position across a re-throw.
_conditionboolean <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, andsubclassmethods andclassNameproperty for a new class.Parameters:
Name Type Description _constructorfunction new class' constructor function.
_classNamestring new class' name.
- Source:
- See:
Example
page.baseclass(page.BNF, 'page.BNF');
-
<static> error(arguments)
-
Prefixes message with
error:and delegates to page.message. Incrementsthis.errorsif it exists. Template method, could be overwritten in any baseclass.Parameters:
Name Type Description argumentsstring 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 _sstring string to escape.
Returns:
single-quoted, escaped string.
- Type
- string
-
<static> merge(_a, _b)
-
Adds one map to another.
Parameters:
Name Type Description _aMap to add to.
_bMap to add.
Returns:
trueif 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 argumentsstring 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 _aMap to check.
_bMap to check.
Returns:
trueif there are common property keys.- Type
- boolean
-
<static> subclass(_constructor, _className, _superclass)
-
Connects subclass to superclass. Arranges for inheritance,
className, andinstanceof. Template method, could be overwritten in any baseclass. Taken from here.Note that there can't be a method similar to
superin Java becausesuperis implemented with a lexical search above the current class — it can't be applied tothis.Parameters:
Name Type Description _constructorfunction subclass' constructor function.
_classNamestring new subclass' name.
_superclassfunction superclass' constructor function.
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
erroraction, ornull. The function is serially reusable; when first accessed it will print a line to label the output columns.Parameters:
Name Type Argument Description _observeObserver <optional>
next observer function to delegate to, if any.
_matchRegExp <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 _sstring string to unescape.
Returns:
unquoted, unescaped string.
- Type
- string
-
<static> uneval(_o [, _indent])
-
Rescursively displays a recursive
Arrayorobjectaggregate containing boolean, number, or string values as leaves. This is similar toJSON.stringifybut perhaps prettier.Parameters:
Name Type Argument Description _oobject object to display.
_indentstring <optional>
indentation prefix.
Returns:
- Type
- string
Example
// the operation can be reversed eval('obj = '+page.uneval(obj))
page