CondParser (CondParser v1.0.1) View Source

CondParser reads conditions like (':foo' or ("toto" == true AND (12 != 13 OR false))) and true and transform them either in an ast with parse/1, or in json with to_json/1.

Ast looks like this:

{:and_op,
  {:or_op, ":foo",
    {:and_op,
      {:eq_op, "toto", true},
      {:or_op,
        {:not_eq_op, 12, 13},
        false
      }
    }
  },
  true
}

Json looks like this:

{
  "left": {
    "left": ":foo",
    "op": "or",
    "right": {
      "left": {"left": "toto", "op": "eq", "right": true},
      "op": "and",
      "right": {
        "left": {"left": 12, "op": "not_eq", "right": 13},
        "op": "or",
        "right": false
      }
    }
  },
  "op": "and",
  "right": true
}

Link to this section Summary

Link to this section Types

Specs

ast() :: any()

Specs

json() :: map()

Link to this section Functions

Specs

is_valid?(binary()) :: boolean()

Specs

parse(binary()) :: {:ok, ast()} | {:error, any()}

Specs

parse!(binary()) :: ast()

Specs

to_json(binary()) :: {:error, any()} | {:ok, json()}

Specs

to_json!(binary()) :: json()