predicator v0.7.2 Predicator

Documentation for Predicator.

Lexer and Parser currently only compatible with 0.4.0 predicate syntax

Link to this section Summary

Functions

eval/3 takes a predicate set, a context struct and options

Currently only compatible with 0.4.0 predicate syntax leex_and_parse/1 takes a string or charlist and does all lexing and parsing then returns the predicate

Currently only compatible with 0.4.0 predicate syntax leex_string/1 takes string or charlist and returns a lexed tuple for parsing

Currently only compatible with 0.4.0 predicate syntax parse_lexed/1 takes a leexed token(list or tup) and returns a predicate. It also can take optional atom for type of token keys to return. options are :string_key_inst & :atom_key_inst

Link to this section Types

Link to this type token_key_t()
token_key_t() :: :atom_key_inst | :string_key_inst

Link to this section Functions

Link to this function eval(inst, context_struct \\ %{}, opts \\ [map_type: :atom])

eval/3 takes a predicate set, a context struct and options

Link to this function leex_and_parse(str, token_type \\ :string_key_inst)

Currently only compatible with 0.4.0 predicate syntax leex_and_parse/1 takes a string or charlist and does all lexing and parsing then returns the predicate.

iex> leex_and_parse(“13 > 12”) [[“lit”, 13], [“lit”, 12], [“comparator”, “GT”]]

iex> leex_and_parse(‘532 == 532’, :atom_key_inst) [[:lit, 532], [:lit, 532], [:comparator, :EQ]]

Link to this function leex_string(str)
leex_string(String.t()) :: {:ok | :error, list() | tuple(), non_neg_integer()}

Currently only compatible with 0.4.0 predicate syntax leex_string/1 takes string or charlist and returns a lexed tuple for parsing.

iex> leex_string(‘10 > 5’) {:ok, [{:lit, 1, 10}, {:comparator, 1, :GT}, {:lit, 1, 5}], 1}

iex> leex_string(“apple > 5532”) {:ok, [{:load, 1, :apple}, {:comparator, 1, :GT}, {:lit, 1, 5532}], 1}

Link to this function parse_lexed(token, opt \\ :string_key_inst)
parse_lexed(list(), token_key_t()) :: {:ok | :error, list() | tuple()}

Currently only compatible with 0.4.0 predicate syntax parse_lexed/1 takes a leexed token(list or tup) and returns a predicate. It also can take optional atom for type of token keys to return. options are :string_key_inst & :atom_key_inst

iex> parse_lexed({:ok, [{:load, 1, :apple}, {:comparator, 1, :GT}, {:lit, 1, 5532}], 1})

iex> parse_lexed({:ok, [{:load, 1, :apple}, {:comparator, 1, :GT}, {:lit, 1, 5532}], 1}, :string_key_inst)

iex> parse_lexed([{:load, 1, :apple}, {:comparator, 1, :GT}, {:lit, 1, 5532}], :atom_key_inst)