pyfcstm.dsl.error
ANTLR Error Collection and Handling Module
This module provides functionality for collecting and handling errors during ANTLR parsing processes. It implements a custom error listener that accumulates errors instead of throwing them immediately, allowing for comprehensive error reporting after the parsing is complete.
GrammarItemError
SyntaxFailError
- class pyfcstm.dsl.error.SyntaxFailError(line, column, offending_symbol_text, msg)[source]
Error raised when a syntax error is encountered during parsing.
- Parameters:
line (int) – The line number where the error occurred
column (int) – The column number where the error occurred
offending_symbol_text (str) – The text of the problematic symbol
msg (str) – The error message
AmbiguityError
- class pyfcstm.dsl.error.AmbiguityError(input_range, start_index, stop_index)[source]
Error raised when grammar ambiguity is detected.
- Parameters:
input_range (str) – The range of input text where ambiguity was detected
start_index (int) – The starting index of the ambiguous section
stop_index (int) – The ending index of the ambiguous section
FullContextAttemptError
- class pyfcstm.dsl.error.FullContextAttemptError(input_range, start_index, stop_index)[source]
Error raised when the parser attempts full context interpretation.
- Parameters:
input_range (str) – The range of input text where full context attempt occurred
start_index (int) – The starting index of the affected section
stop_index (int) – The ending index of the affected section
ContextSensitivityError
- class pyfcstm.dsl.error.ContextSensitivityError(input_range, start_index, stop_index)[source]
Error raised when context sensitivity is detected.
- Parameters:
input_range (str) – The range of input text where context sensitivity was detected
start_index (int) – The starting index of the sensitive section
stop_index (int) – The ending index of the sensitive section
UnfinishedParsingError
GrammarParseError
- class pyfcstm.dsl.error.GrammarParseError(errors: List[GrammarItemError])[source]
Exception raised when one or more grammar parsing errors are encountered.
- Parameters:
errors (List[GrammarItemError]) – List of grammar-related errors that occurred during parsing
CollectingErrorListener
- class pyfcstm.dsl.error.CollectingErrorListener[source]
A custom ANTLR error listener that collects errors during parsing.
This class extends ANTLR’s ErrorListener to provide comprehensive error collection and reporting functionality. Instead of immediately throwing exceptions, it accumulates errors and can report them collectively.
- Variables:
errors – List storing all encountered error messages
- check_errors()[source]
Check for collected errors and raise an exception if any exist.
This method should be called after parsing is complete to verify if any errors were encountered during the process.
- Raises:
GrammarParseError – If any errors were collected during parsing, with detailed error messages
- reportAmbiguity(recognizer, dfa, startIndex, stopIndex, exact, ambigAlts, configs)[source]
Handle and collect grammar ambiguity issues.
- Parameters:
recognizer – The parser that encountered the ambiguity
dfa – The DFA being processed
startIndex – Starting index of the ambiguous input
stopIndex – Ending index of the ambiguous input
exact – Whether the ambiguity is exact
ambigAlts – The ambiguous alternatives
configs – The ATN configurations
- reportAttemptingFullContext(recognizer, dfa, startIndex, stopIndex, conflictingAlts, configs)[source]
Handle and collect full context parsing attempts.
- Parameters:
recognizer – The parser attempting full context
dfa – The DFA being processed
startIndex – Starting index of the affected input
stopIndex – Ending index of the affected input
conflictingAlts – The conflicting alternatives
configs – The ATN configurations
- reportContextSensitivity(recognizer, dfa, startIndex, stopIndex, prediction, configs)[source]
Handle and collect context sensitivity issues.
- Parameters:
recognizer – The parser that encountered the sensitivity
dfa – The DFA being processed
startIndex – Starting index of the sensitive input
stopIndex – Ending index of the sensitive input
prediction – The predicted alternative
configs – The ATN configurations
- syntaxError(recognizer, offendingSymbol, line, column, msg, e)[source]
Handle and collect syntax errors encountered during parsing.
- Parameters:
recognizer – The parser that encountered the error
offendingSymbol – The problematic input symbol
line – Line number where the error occurred
column – Column number where the error occurred
msg – The error message
e – The exception that was raised