Exceptions
Parse failures, and the helpers that attach suggestions to them.
ParseError is re-exported at the top level as
formulate.ParseError, which is how it should normally be caught. Note that
it covers syntax errors only: an expression that parses but uses a construct
the target language has no equivalent for raises ValueError when it is
rendered, not when it is parsed.
Parse failures, and the hints attached to them.
The parsers report a syntax error as a ParseError whose message shows
where parsing stopped and, where a common mistake is recognisable, how to fix
it. The hints are heuristics over the source text, so they can suggest
something that is not the actual problem; the underlying lark error is always
included as well, and kept on the exception as
ParseError.lark_error.
- exception formulate.exceptions.ParseError(message: str, lark_error: LarkError)
Bases:
ExceptionRaised when an expression cannot be parsed.
- Parameters:
message – the human-readable report: where parsing stopped, any suggestions, and the underlying lark message.
lark_error – the error raised by lark, kept for programmatic access to details such as the line and column.
- formulate.exceptions.debug_numexpr(exp: str, error: LarkError) ParseError
Turn a lark failure on a NumExpr expression into a
ParseError.Suggests the NumExpr spelling of the logical operators when the expression contains the ROOT or Python one, and points out chained comparisons, which NumExpr does not support.
- Parameters:
exp – the expression that failed to parse.
error – the error lark raised for it.
- formulate.exceptions.debug_root(exp: str, error: LarkError) ParseError
Turn a lark failure on a ROOT expression into a
ParseError.Suggests the ROOT spelling of the logical operators when the expression contains the NumExpr one.
- Parameters:
exp – the expression that failed to parse.
error – the error lark raised for it.