Package lepl :: Package core :: Module parser
[hide private]
[frames] | no frames]

Module parser

source code

Create and evaluate parsers.

Once a consistent set of matchers is constructed (that describes a grammar) they must be evaluated against some input. The code here supports that evaluation (via trampoline()) and allows the graph of matchers to be rewritten beforehand.

Classes [hide private]
  GeneratorWrapper
Associate basic info about call that created the generator with the generator itself.
Functions [hide private]
list
imap(function, sequence, sequence=..., ...)
Return a list of the results of applying the function to the items of the argument sequence(s).
 
tagged(method)
Decorator for generators to add extra attributes.
source code
 
tagged_function(matcher, function)
Decorator for generators to add extra attributes.
source code
 
trampoline(main, m_stack=None, m_value=None)
The main parser loop.
source code
 
make_raw_parser(matcher, stream_factory, config)
Make a parser.
source code
 
make_multiple(raw)
Convert a raw parser to return a generator of results.
source code
 
make_single(raw)
Convert a raw parser to return a single result or None.
source code
Function Details [hide private]

imap(function, sequence, sequence=..., ...)

 
Return a list of the results of applying the function to the items of the argument sequence(s). If more than one sequence is given, the function is called with an argument list consisting of the corresponding item of each sequence, substituting None for missing values when not all sequences have the same length. If the function is None, return a list of the items of the sequence (or a list of tuples if more than one sequence).
Returns: list

trampoline(main, m_stack=None, m_value=None)

source code 

The main parser loop. Evaluates matchers as coroutines.

A dedicated version for when monitor not present increased the speed of the nat_lang performance test by only around 1% (close to noise).

Replacing stack append/pop with a manually allocated non-decreasing array and index made no significant difference (at around 1% level)

make_raw_parser(matcher, stream_factory, config)

source code 
Make a parser. Rewrite the matcher and prepare the input for a parser. This constructs a function that returns a generator that provides a sequence of matches (ie (results, stream) pairs).