MattCheely/boon/1.0.0

NOTE: the latest version is 2.0.1

Boon

Parsing and evaulation of Boon strings.

Terminology

In the boon expression:

this OR that

OR is an operator, and this and that are identifiers.

Parse

A parsed Boon expression. Can be evaluated many times

parse : String -> Result String Expression

Try to parse a string as a Boon expression, failing on invalid input.

Evaluate

evalFromDict : Dict String Bool -> Expression -> Bool

Evaluate an expression by looking up identifiers in a Dict String Bool. If a key is absent, it will evaluate to False

values =
    Dict.fromList
        [ ( "foo", True )
        , ( "bar", False )
        ]


(parse "foo OR bar"
    |> evalFromDict values) == True


(parse "baz OR bar"
    |> evalFromDict values) == False
evalFromSet : Set String -> Expression -> Bool

Evalute an expression by looking up identifiers in a Set String. Identifiers present in the set are True, any others are False.

values = Set.fromList ["foo", "bar"]


(parse "foo AND bar"
    |> evalFromSet values) == True


(parse "bar AND baz"
    |> evalFromSet values) == False
eval : (String -> Bool) -> Expression -> Bool

Evaluate an expression based on a user-provided lookup function that maps identifiers to boolean values.