NimbleParsec-based parser for the Ecto query language.
Parses data types into an AST representation:
- Strings:
"foo"→{:string, "foo"} - Integers:
42→{:integer, 42} - Floats:
3.14→{:float, 3.14} - Booleans:
true/TRUE→{:boolean, true} - Identifiers:
column_1→{:identifier, "column_1"} - Lists:
[1, 2]→{:list, [{:integer, 1}, {:integer, 2}]} - Functions:
TO_UPPER(col)→{:function, "to_upper", [{:identifier, "col"}]} - Operators:
col == 1→{:op, :==, {:identifier, "col"}, {:integer, 1}} - AND/OR:
a == 1 AND b == 2→{:and, [op1, op2]} - Grouping:
(a == 1 OR b == 2) AND c == 3→{:and, [{:or, [...]}, ...]}
Summary
Functions
Parses an input string into an AST node.
Returns {:ok, ast_node} on success or {:error, reason} on failure.
@spec parse_raw(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: non_neg_integer(), rest: binary(), reason: String.t(), context: map()
Parses the given binary as parse_raw.
Returns {:ok, [token], rest, context, position, byte_offset} or
{:error, reason, rest, context, line, byte_offset} where position
describes the location of the parse_raw (start position) as {line, offset_to_start_of_line}.
To column where the error occurred can be inferred from byte_offset - offset_to_start_of_line.
Options
:byte_offset- the byte offset for the whole binary, defaults to 0:line- the line and the byte offset into that line, defaults to{1, byte_offset}:context- the initial context value. It will be converted to a map