knitout_interpreter.knitout_language.Knitout_Parser module

Parser code for accessing Parglare language support

class Knitout_Parser(debug_grammar=False, debug_parser=False, debug_parser_layout=False)[source]

Bases: object

Parser for reading knitout using the parglare library.

__init__(debug_grammar=False, debug_parser=False, debug_parser_layout=False)[source]

Initialize the Knitout parser with optional debugging features.

Parameters:
  • debug_grammar (bool, optional) – Enable grammar debugging. Defaults to False.

  • debug_parser (bool, optional) – Enable parser debugging. Defaults to False.

  • debug_parser_layout (bool, optional) – Enable parser layout debugging. Defaults to False.

Raises:

FileNotFoundError – If the <knitout.pg> grammar file cannot be located in the package.

parse_knitout_to_instructions(pattern, pattern_is_file=False)[source]

Parse knitout pattern into a knitout program.

Parameters:
  • pattern (str) – Either a file path or the knitout string to be parsed.

  • pattern_is_file (bool, optional) – If True, treat pattern as a file path. Defaults to True.

Returns:

The program ordered by the parsed lines of knitout code.

Return type:

Knitout_Line

Raises:
parse_knitout(pattern, pattern_is_file=False)[source]

Execute the parsing code for the parglare parser.

This is a convenience function that creates a Knitout_Parser instance and parses the given pattern.

Parameters:
  • pattern (str) – Either a file path or the knitout string to be parsed.

  • pattern_is_file (bool, optional) – If True, treat pattern as a file path. Defaults to True.

Returns:

List of knitout lines created by parsing the given pattern.

Return type:

list[Knitout_Line]