parselglossy.grammars.lexer module#

Top-level functions for parselglossy.

parselglossy.grammars.lexer.dispatch_grammar(grammar: str) pp.ParserElement[source]#
parselglossy.grammars.lexer.lex_from_str(*, in_str: str, grammar: str = 'standard', ir_file: Optional[Union[str, Path]] = None) Dict[str, Any][source]#

Run grammar of choice on input string.

Parameters
  • in_str (str) – The string to be parsed.

  • grammar (str) – Grammar to be used. Defaults to “standard”.

  • ir_file (Optional[Union[str, Path]]) – File to write intermediate representation to (JSON format). None by default, which means file is not written out.

Return type

The contents of the input string as a dictionary.

Raises

ParselglossyError

parselglossy.grammars.lexer.parse_string_to_dict(lexer: pp.ParserElement, s: str) Dict[str, Any][source]#

Helper function around parseString(s).asDict() that checks whether some keywords or sections were accidentally repeated and shadowing earlier keywords/sections.

Parameters
  • lexer (pp.ParserElement) – Nested dictionary

  • s (str) – String to parse

Returns

tokes_dict – Dictionary of tokens

Return type

JSONDict

Raises

ParselglossyError