RuleParser v0.1.0 RuleParser View Source

Documentation for Parser.

Link to this section Summary

Functions

Parse an expression

Parse to an atom. For testing purpose. Please use parse/2 instead

Parse a sub expr. For testing purpose. Please use parse/2 instead

Parse to a string. For testing purpose. Please use parse/2 instead

Parse a value. For testing purpose. Please use parse/2 instead

Link to this section Functions

Parse an expression.

iex> RuleParser.parse("a==1 and b == 2") {:ok, [expr: [:a, :==, {:v, 1}, :and, :b, :==, {:v, 2}]], "", %{}, {1, 0}, 15}

iex> RuleParser.parse("a==1 and b in [\"abc\", :abc, 123]") {:ok, [expr: [:a, :==, {:v, 1}, :and, :b, :in, {:v, ["abc", :abc, 123]}]], "", %{}, {1, 0}, 32}

iex> RuleParser.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}, 50}

Parse to an atom. For testing purpose. Please use parse/2 instead.

iex> RuleParser.parse_atom(":h") {:ok, [:h], "", %{}, {1, 0}, 2}

iex> RuleParser.parse_atom(":hello_world") {:ok, [:hello_world], "", %{}, {1, 0}, 12}

iex> RuleParser.parse_atom(":he2llo_world1") {:ok, [:he], "2llo_world1", %{}, {1, 0}, 3}

Parse a sub expr. For testing purpose. Please use parse/2 instead.

iex> RuleParser.parse_expr("a != 1") {:ok, [:a, :!=, {:v, 1}], "", %{}, {1, 0}, 6}

iex> RuleParser.parse_expr(~S(a in ["hello", :world, 2])) {:ok, [:a, :in, {:v, ["hello", :world, 2]}], "", %{}, {1, 0}, 25}

Parse to a string. For testing purpose. Please use parse/2 instead.

iex> RuleParser.parse_quoted_string(~S("hello world")) {:ok, ["hello world"], "", %{}, {1, 0}, 13}

iex> RuleParser.parse_quoted_string(~S(hello world)) {:error, "expected byte equal to ?\"", "hello world", %{}, {1, 0}, 0}

iex> RuleParser.parse_quoted_string(~S("hello \"world\"")) {:ok, ["hello \"world\""], "", %{}, {1, 0}, 17}

Parse a value. For testing purpose. Please use parse/2 instead.

iex> RuleParser.parse_value("10") {:ok, [v: 10], "", %{}, {1, 0}, 2}

iex> RuleParser.parse_value(~S(["a", :a, 1])) {:ok, [v: ["a", :a, 1]], "", %{}, {1, 0}, 12}