CommonParser v0.2.0 CommonParser.Expr View Source
Documentation for Parser.
Link to this section Summary
Link to this section Functions
parse(binary, opts \\ [])
View Source
parse(binary(), keyword()) ::
{:ok, [term()], rest, context, line, byte_offset}
| {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
byte_offset: pos_integer(),
rest: binary(),
reason: String.t(),
context: map()
parse(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parse an expression.
iex> CommonParser.Expr.parse("a=1 and b = 2") {:ok, [expr: [:a, :==, {:v, 1}, :and, :b, :==, {:v, 2}]], "", %{}, {1, 0}, 13}
iex> CommonParser.Expr.parse("a=1 and b in [\"abc\", :abc, 123]") {:ok, [expr: [:a, :==, {:v, 1}, :and, :b, :in, {:v, ["abc", :abc, 123]}]], "", %{}, {1, 0}, 31}
iex> CommonParser.Expr.parse("a=1 and (b in [\"abc\", :abc, 123] or c != [1,2,3])") {:ok, [expr: [:a, :==, {:v, 1}, :and, {:expr, [:b, :in, {:v, ["abc", :abc, 123]}, :or, :c, :!=, {:v, [1, 2, 3]}]}]], "", %{}, {1, 0}, 49}
parse_atom(binary, opts \\ [])
View Source
parse_atom(binary(), keyword()) ::
{:ok, [term()], rest, context, line, byte_offset}
| {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
byte_offset: pos_integer(),
rest: binary(),
reason: String.t(),
context: map()
parse_atom(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parse to an atom. For testing purpose. Please use parse/2
instead.
iex> CommonParser.Expr.parse_atom(":h") {:ok, [:h], "", %{}, {1, 0}, 2}
iex> CommonParser.Expr.parse_atom(":hello_world") {:ok, [:hello_world], "", %{}, {1, 0}, 12}
iex> CommonParser.Expr.parse_atom(":he2llo_world1") {:ok, [:he], "2llo_world1", %{}, {1, 0}, 3}
parse_expr(binary, opts \\ [])
View Source
parse_expr(binary(), keyword()) ::
{:ok, [term()], rest, context, line, byte_offset}
| {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
byte_offset: pos_integer(),
rest: binary(),
reason: String.t(),
context: map()
parse_expr(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parse a sub expr. For testing purpose. Please use parse/2
instead.
iex> CommonParser.Expr.parse_expr("a != 1") {:ok, [:a, :!=, {:v, 1}], "", %{}, {1, 0}, 6}
iex> CommonParser.Expr.parse_expr(~S(a in ["hello", :world, 2])) {:ok, [:a, :in, {:v, ["hello", :world, 2]}], "", %{}, {1, 0}, 25}
parse_quoted_string(binary, opts \\ [])
View Source
parse_quoted_string(binary(), keyword()) ::
{:ok, [term()], rest, context, line, byte_offset}
| {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
byte_offset: pos_integer(),
rest: binary(),
reason: String.t(),
context: map()
parse_quoted_string(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parse to a string. For testing purpose. Please use parse/2
instead.
iex> CommonParser.Expr.parse_quoted_string(~S("hello world")) {:ok, ["hello world"], "", %{}, {1, 0}, 13}
iex> CommonParser.Expr.parse_quoted_string(~S(hello world)) {:error, "expected byte equal to ?\"", "hello world", %{}, {1, 0}, 0}
iex> CommonParser.Expr.parse_quoted_string(~S("hello \"world\"")) {:ok, ["hello \"world\""], "", %{}, {1, 0}, 17}
parse_value(binary, opts \\ [])
View Source
parse_value(binary(), keyword()) ::
{:ok, [term()], rest, context, line, byte_offset}
| {:error, reason, rest, context, line, byte_offset}
when line: {pos_integer(), byte_offset},
byte_offset: pos_integer(),
rest: binary(),
reason: String.t(),
context: map()
parse_value(binary(), keyword()) :: {:ok, [term()], rest, context, line, byte_offset} | {:error, reason, rest, context, line, byte_offset} when line: {pos_integer(), byte_offset}, byte_offset: pos_integer(), rest: binary(), reason: String.t(), context: map()
Parse a value. For testing purpose. Please use parse/2
instead.
iex> CommonParser.Expr.parse_value("10") {:ok, [v: 10], "", %{}, {1, 0}, 2}
iex> CommonParser.Expr.parse_value(~S(["a", :a, 1])) {:ok, [v: ["a", :a, 1]], "", %{}, {1, 0}, 12}