Packages

A CEL (Common Expression Language) parser and interpreter in pure Gleam

Current section

Files

Jump to
cel src cel@interpreter@value.erl
Raw

src/cel@interpreter@value.erl

-module(cel@interpreter@value).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([key_from_value/1, to_type/1]).
-export_type([key/0, value/0, type/0]).
-type key() :: {key_int, integer()} |
{key_u_int, integer()} |
{key_bool, boolean()} |
{key_string, binary()}.
-type value() :: {list, list(value())} |
{map, gleam@dict:dict(key(), value())} |
{function, binary(), gleam@option:option(value())} |
{int, integer()} |
{u_int, integer()} |
{float, float()} |
{string, binary()} |
{bytes, bitstring()} |
{bool, boolean()} |
null.
-type type() :: list_t |
map_t |
function_t |
int_t |
u_int_t |
float_t |
string_t |
bytes_t |
bool_t |
null_t.
-file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/value.gleam", 11).
-spec key_from_value(value()) -> {ok, key()} | {error, nil}.
key_from_value(Value) ->
case Value of
{bool, K} ->
{ok, {key_bool, K}};
{int, K@1} ->
{ok, {key_int, K@1}};
{u_int, K@2} ->
{ok, {key_u_int, K@2}};
{string, K@3} ->
{ok, {key_string, K@3}};
_ ->
{error, nil}
end.
-file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/value.gleam", 34).
-spec to_type(value()) -> type().
to_type(Value) ->
case Value of
{bool, _} ->
bool_t;
{bytes, _} ->
bytes_t;
{float, _} ->
float_t;
{function, _, _} ->
function_t;
{int, _} ->
int_t;
{list, _} ->
list_t;
{map, _} ->
map_t;
null ->
null_t;
{string, _} ->
string_t;
{u_int, _} ->
u_int_t
end.