Error handling
textX will raise an error if a syntax or semantic error is detected during meta-model or model parsing/construction.
For a syntax error TextXSyntaxError is raised. For a semantic error
TextXSemanticError is raised. Both exceptions inherit from TextXError. These
exceptions are located in textx.exceptions module.
All exceptions have message attribute with the error message, and line,
col and nchar attributes which represent line, column and substring length
where the error was found.
Errors during meta-model construction
Section titled “Errors during meta-model construction”Besides syntax errors in the grammar, TextXSemanticError is also raised when
the grammar is semantically invalid, even though it is syntactically well
formed. The most notable case is a non-consuming
repetition: a repetition (*, +, *=,
+=) whose body can match the empty string. Such grammars would hang the
parser in an infinite loop and are rejected at meta-model construction time,
with the line/col pointing to the offending repetition in the grammar:
Model: (A)*;A: 'x'?;
<file>:2:8: Non-consuming match inside repetition in rule "Model". Bodyexpression may succeed without consuming input, which would cause aninfinite loop.