pyfcstm.dsl.parse
Grammar parsing module for processing and interpreting grammar-based input text.
This module provides functions to parse input text according to grammar rules defined in the GrammarParser. It uses ANTLR4 for lexical analysis and parsing, and provides specialized functions for parsing different grammar elements like conditions, preambles, and operations.
parse_with_grammar_entry
- pyfcstm.dsl.parse.parse_with_grammar_entry(input_text: str, entry_name: str, force_finished: bool = True)[source]
Parse input text using a specified grammar entry point.
This function allows parsing with any entry point in the grammar by name.
- Parameters:
input_text (str) – The text to parse
entry_name (str) – The name of the grammar rule to use as entry point
force_finished (bool) – Whether to check if parsing consumed all input
- Returns:
The parsed node representation of the input
- Return type:
object
- Raises:
Various parsing errors if the input doesn’t match the grammar
Example:
>>> result = parse_with_grammar_entry("x > 5", "condition")
parse_condition
- pyfcstm.dsl.parse.parse_condition(input_text: str)[source]
Parse input text as a condition expression.
This function specifically parses conditional expressions according to the grammar’s condition rule.
- Parameters:
input_text (str) – The condition text to parse
- Returns:
The parsed condition node
- Return type:
object
- Raises:
Various parsing errors if the input doesn’t match the condition grammar
Example:
>>> condition_node = parse_condition("x > 5 && y < 10")
parse_preamble
- pyfcstm.dsl.parse.parse_preamble(input_text: str)[source]
Parse input text as a preamble program.
This function specifically parses preamble programs according to the grammar’s preamble_program rule.
- Parameters:
input_text (str) – The preamble program text to parse
- Returns:
The parsed preamble program node
- Return type:
object
- Raises:
Various parsing errors if the input doesn’t match the preamble grammar
Example:
>>> preamble_node = parse_preamble("x = 10;")
parse_operation
- pyfcstm.dsl.parse.parse_operation(input_text: str)[source]
Parse input text as an operation program.
This function specifically parses operation programs according to the grammar’s operation_program rule.
- Parameters:
input_text (str) – The operation program text to parse
- Returns:
The parsed operation program node
- Return type:
object
- Raises:
Various parsing errors if the input doesn’t match the operation grammar
Example:
>>> operation_node = parse_operation("x := 10;")