Belp v0.1.0 Belp View Source

Belp is a simple Boolean Expression Lexer and Parser.

Link to this section Summary

Types

A type that describes which primitives can be used as expression.

Functions

Evaluates the given expression.

Evaluates the given expression. Raises when the expression is invalid or variables are undefined.

Checks whether the given expression is valid.

Gets a list of variable names that are present in the given expression.

Gets a list of variable names that are present in the given expression. Raises when the expression is invalid or variables are undefined.

Link to this section Types

A type that describes which primitives can be used as expression.

Link to this section Functions

Link to this function

eval(expr, vars \\ %{})

View Source
eval(
  expr(),
  Keyword.t(as_boolean(any()))
  | %{optional(atom() | String.t()) => as_boolean(any())}
) ::
  {:ok, boolean()}
  | {:error,
     Belp.InvalidCharError.t()
     | Belp.SyntaxError.t()
     | Belp.UndefinedVariableError.t()}

Evaluates the given expression.

Link to this function

eval!(expr, vars \\ %{})

View Source
eval!(
  expr(),
  Keyword.t(as_boolean(any()))
  | %{optional(atom() | String.t()) => as_boolean(any())}
) :: boolean() | no_return()

Evaluates the given expression. Raises when the expression is invalid or variables are undefined.

Link to this function

valid_expression?(expr)

View Source
valid_expression?(expr()) :: boolean()

Checks whether the given expression is valid.

Link to this function

variables(expr)

View Source
variables(expr()) ::
  {:ok, [String.t()]}
  | {:error, Belp.InvalidCharError.t() | Belp.SyntaxError.t()}

Gets a list of variable names that are present in the given expression.

Link to this function

variables!(expr)

View Source
variables!(expr()) :: [String.t()] | no_return()

Gets a list of variable names that are present in the given expression. Raises when the expression is invalid or variables are undefined.