parselglossy.grammars.lexer module

Top-level functions for parselglossy.

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

Run grammar of choice on input string.

Parameters
  • in_str (Union[str, Path]) – 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.

Returns

Return type

The contents of the input string as a dictionary.

Raises

ParselglossyError

parselglossy.grammars.lexer.parse_string_to_dict(lexer, s: Union[str, pathlib.Path]) → 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 (JSONDict) – Nested dictionary

  • s (Union[str, Path]) – String to parse

Returns

tokes_dict – Dictionary of tokens

Return type

JSONDict

Raises

ParselglossyError