gcode_reader.emulate.parsers ============================ .. py:module:: gcode_reader.emulate.parsers Classes ------- .. autoapisummary:: gcode_reader.emulate.parsers.GcodeParser Module Contents --------------- .. py:class:: GcodeParser(syntax_name='default') Parses G-code text into a list of high-level Command objects. This class acts as a bridge between the low-level dictionary representation of a G-code line (from the `read` module) and the structured `Command` objects used for analysis and machine simulation. It uses a series of helper methods to identify the specific type of command for each line. .. attribute:: syntax The syntax definition for the chosen G-code flavor. :type: dict .. attribute:: helpers An ordered list of handler methods used to parse a dictionary of G-code words into a specific Command object. :type: list Initializes the GcodeParser with a specific syntax flavor. :param syntax_name: The name of the syntax flavor to use, which corresponds to a definition in `gcode_reader.syntax.flavors`. Defaults to "default". :type syntax_name: str, optional .. py:method:: dataframe_to_commands(df: pandas.DataFrame) Reads a gcode dataframe and converts it to a list of Command objects. Ignores nan data in the input dataframe. :param df: The dataframe of gcode information to read. :type df: DataFrame :returns: A list of parsed Command Objects, one for each row of the dataframe. :rtype: List[Command] .. py:method:: gcode_file_to_commands(filepath: str) -> List[gcode_reader.emulate.commands.Command] Reads a G-code file and converts it into a list of Command objects. This is a high-level method that handles opening, reading, and parsing an entire G-code file from start to finish. :param filepath: The path to the G-code file. :type filepath: str :returns: A list of parsed Command objects, one for each line in the file. :rtype: List[Command] .. py:method:: gcode_line_to_command(line: str, **named_parameters) Reads a single G-code line string and converts it to a Command object. :param line: The G-code line to parse. :type line: str :param \*\*named_parameters: Additional parameters to inject into the parsed words, used for context not present in the line itself. :returns: A parsed Command object. :rtype: Command .. py:method:: gcode_words_to_command(**words) -> gcode_reader.emulate.commands.Command Translates a dictionary of G-code words into a specific Command object. This method orchestrates the parsing process. It takes a dictionary of words from a single G-code line and passes it sequentially to each function in the `self.helpers` list. The first helper that successfully identifies the command pattern and returns a `Command` object wins. If no helper can identify the command, it logs a warning and returns a generic `Command` object containing the original data. :param \*\*words: A dictionary where keys are G-code words (e.g., 'G', 'X') and values are their numeric or string values. :returns: The specific `Command` subclass instance that best matches the G-code words. :rtype: Command .. py:property:: arc_move_codes .. py:property:: code_map .. py:property:: dwell_code .. py:attribute:: helpers .. py:property:: linear_move_codes .. py:property:: syntax .. py:property:: word_map