parselglossy.api module

Top-level functions for parselglossy.

parselglossy.api.document(template: Union[str, pathlib.Path], outfile: Union[str, pathlib.Path, None] = None, header: str = 'Input parameters') → str[source]

Generate documentation in reStructuredText format from validation template.

Parameters:
  • template (Union[str, Path]) – Which validation template to use.
  • output (Union[str, Path]) – Where to save the generated documentation. Defaults to None.
  • header (str) – Header for the documentation page. Defaults to Input parameters.
Returns:

Return type:

The documentation page as a string.

parselglossy.api.lex(infile: Union[str, pathlib.Path], grammar: str = 'standard', ir_file: Union[str, pathlib.Path, None] = None) → Dict[str, Any][source]

Run grammar of choice on input string.

Parameters:
  • in_str (IO[Any]) – The string to be parsed.
  • grammar (str) – Grammar to be used.
  • ir_file (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.

parselglossy.api.parse(infile: Union[str, pathlib.Path], template: Union[str, pathlib.Path], outfile: Union[str, pathlib.Path, None] = None, grammar: str = 'standard', dump_ir: bool = False) → Dict[str, Any][source]

Parse input file.

Parameters:
  • infile (Union[str, Path]) – The input file to be parsed.
  • template (Union[str, Path]) – Which validation template to use.
  • outfile (Optional[Union[str, Path]]) – The output file. Defaults to None, which means writing to <infile>_fr.json.
  • grammar (str) – Which grammar to use. Defaults to standard.
  • dump_ir (bool) – Whether to write out the intermediate representation to file (JSON format). False by default. If true the filename if <infile>_ir.json
Returns:

Return type:

The validated input as a dictionary.

parselglossy.api.validate(infile: Union[str, pathlib.Path], template: Union[str, pathlib.Path], fr_file: Union[str, pathlib.Path, None] = None) → Dict[str, Any][source]

Validate intermediate representation into final representation.

Parameters:
  • infile (Union[str, Path]) – The file with the intermediate representation (JSON format).
  • template (Union[str, Path]) – Which validation template to use.
  • fr_file (Union[str, Path]) – File to write final representation to (JSON format). None by default, which means file is not written out.
Returns:

Return type:

The validated input as a dictionary.