finesse.script.parser module
Kat parser to convert tokens to productions.
This is a recursive descent parser, providing unlimited lookahead capabilities to allow arbitrary context-free grammars to be parsed. The implementation of memoization makes it a packrat parser which runs in linear time at the expense of potentially unlimited memory use. In practice memory use is limited by the simplicity of typical kat scripts (e.g. expressions don’t tend to have many subexpressions).
This is inspired by Python’s PEG parser, used as of 3.9. Some introductory information can be found in this series of blog posts.
Sean Leavey <sean.leavey@ligo.org>
- class finesse.script.parser.KatParser[source]
Bases:
objectKat script parser.
This uses so-called packrat parsing to reduce, via productions, tokens yielded from a token stream generated from an input file or string to
KatScriptItemobjects containing the associatedtokens.- maybe_whitespace(multiline, whitespace)[source]
Expect zero or more whitespace if enabled, else return [].
- parse(string)[source]
Parse the contents of string.
Parameters
- string
str The string to parse kat script from.
Returns
KatScriptThe parsed kat script.
- string