-module(cel@interpreter@type_). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([kind/1, references/1, variables/1, functions/1]). -export_type([type/0, reference_/0, reference_map/0]). -type type() :: dynamic_t | {list_t, type()} | {map_t, type(), type()} | {function_t, type(), list(type())} | int_t | u_int_t | float_t | string_t | bytes_t | bool_t | null_t. -type reference_() :: {constant, cel@interpreter@value:value()} | {variable, list(binary())} | {call, binary()}. -type reference_map() :: {reference_map, gleam@dict:dict(integer(), reference_())}. -file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/type_.gleam", 24). -spec kind(cel@interpreter@value:value()) -> type(). kind(Value) -> case Value of {bool, _} -> bool_t; {int, _} -> int_t; {u_int, _} -> u_int_t; {float, _} -> float_t; {string, _} -> string_t; {bytes, _} -> bytes_t; {function, _, _} -> {function_t, dynamic_t, []}; {list, _} -> {list_t, dynamic_t}; {map, _} -> {map_t, dynamic_t, dynamic_t}; null -> null_t end. -file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/type_.gleam", 57). -spec member_path(cel@parser:expression_data()) -> list(binary()). member_path(Expr) -> case cel@parser:expr(Expr) of {member, Parent, {attribute, Name}} -> case cel@parser:expr(Parent) of {ident, Parent@1} -> [Name, Parent@1]; _ -> [Name | member_path(Parent)] end; _ -> [] end. -file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/type_.gleam", 70). -spec collect_id_references( cel@parser:expression_data(), gleam@dict:dict(integer(), reference_()) ) -> gleam@dict:dict(integer(), reference_()). collect_id_references(Expr, Acc) -> Id = begin _pipe = Expr, cel@parser:id(_pipe) end, case begin _pipe@1 = Expr, cel@parser:expr(_pipe@1) end of {atom, Atom} -> gleam@dict:insert( Acc, Id, {constant, cel@interpreter@value:from_atom(Atom)} ); {binary_operation, Lhs, _, Rhs} -> Enumerated_lhs = collect_id_references(Lhs, Acc), collect_id_references(Rhs, Enumerated_lhs); {function_call, Name, This, Args} -> Expressions = case This of {some, E} -> [E | Args]; none -> Args end, Enumerated = begin _pipe@2 = Expressions, gleam@list:fold( _pipe@2, Acc, fun(Acc@1, Expr@1) -> collect_id_references(Expr@1, Acc@1) end ) end, gleam@dict:insert(Enumerated, Id, {call, Name}); {ident, Name@1} -> gleam@dict:insert(Acc, Id, {variable, [Name@1]}); {list, Expressions@1} -> _pipe@3 = Expressions@1, gleam@list:fold( _pipe@3, Acc, fun(Acc@2, Expr@2) -> collect_id_references(Expr@2, Acc@2) end ); {map, Map} -> _pipe@4 = Map, gleam@list:fold( _pipe@4, Acc, fun(Acc@3, Key_value) -> {Key, Value} = Key_value, Enumerated@1 = collect_id_references(Key, Acc@3), collect_id_references(Value, Enumerated@1) end ); {member, _, {attribute, _}} -> Path = member_path(Expr), gleam@dict:insert(Acc, Id, {variable, lists:reverse(Path)}); {member, Parent, {index, Inner}} -> Acc@4 = collect_id_references(Parent, Acc), collect_id_references(Inner, Acc@4); {ternary, Cond, Then, Otherwise} -> _pipe@5 = [Cond, Then, Otherwise], gleam@list:fold( _pipe@5, Acc, fun(Acc@5, Expr@3) -> collect_id_references(Expr@3, Acc@5) end ); {unary, _, Expr@4} -> collect_id_references(Expr@4, Acc) end. -file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/type_.gleam", 124). -spec references(cel@parser:expression_data()) -> reference_map(). references(Expr) -> Refs = collect_id_references(Expr, maps:new()), {reference_map, Refs}. -file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/type_.gleam", 130). -spec variables(reference_map()) -> list(list(binary())). variables(Map) -> {reference_map, Refs} = Map, _pipe = maps:to_list(Refs), _pipe@1 = gleam@list:filter_map(_pipe, fun(Pair) -> case Pair of {_, {variable, Path}} -> {ok, Path}; {_, _} -> {error, nil} end end), gleam@list:unique(_pipe@1). -file("/Users/jonas/src/personal/cel-gleam/src/cel/interpreter/type_.gleam", 144). -spec functions(reference_map()) -> list(binary()). functions(Map) -> {reference_map, Refs} = Map, _pipe = maps:to_list(Refs), _pipe@1 = gleam@list:filter_map(_pipe, fun(Pair) -> case Pair of {_, {call, Name}} -> {ok, Name}; {_, _} -> {error, nil} end end), gleam@list:unique(_pipe@1).