Error struct for parse errors in Predicator expressions.
This error occurs when the input expression cannot be parsed due to syntax errors.
Fields
message- Human-readable error description. Never contains the location - that is always:positionposition-{line, column}of the syntax error, typedPredicator.Types.position/0so generic error-reporting code can read a position uniformly acrossParseError,EvaluationError,TypeMismatchError, andUndefinedVariableErrorspan- the source text the failing token or construct covers, when the failure carried a token extent (optional, defaultnil).positionis always the span's start when both are present.
Examples
A parse error from a compile entry point carries all three fields - the
span comes from the token stream, so it is present in every compile mode,
not only the _with_spans ones:
iex> {:error, error} = Predicator.compile("score > > 5")
iex> {error.position, error.span}
{{1, 9}, {{1, 9}, {1, 10}}}:span is nil only on an error a caller built through new/3:
iex> Predicator.Errors.ParseError.new("boom", 1, 10)
%Predicator.Errors.ParseError{message: "boom", position: {1, 10}, span: nil}
Summary
Types
@type t() :: %Predicator.Errors.ParseError{ message: binary(), position: Predicator.Types.position(), span: Predicator.Types.span() | nil }
Functions
@spec new(binary(), pos_integer(), pos_integer()) :: t()
Creates a parse error.
Takes the line and column separately because that is the shape
Predicator.Lexer.tokenize/1 and Predicator.Parser.parse/2 report failures
in; the struct stores them as a single :position tuple. :span is nil.
@spec new(binary(), pos_integer(), pos_integer(), Predicator.Types.span() | nil) :: t()
Creates a parse error with a source span.
Like new/3, but also records the token or construct extent the failure
covers. :position is set to the span's start.