have a server that like does stuff now

This commit is contained in:
2025-10-11 02:07:20 -06:00
parent fa16da8178
commit 6c45f30919
8 changed files with 107 additions and 24 deletions
+15 -5
View File
@@ -7,15 +7,17 @@
-export([
new/0,
default/0,
default_snowflakes/0,
define/3,
resolve_pattern/2
resolve_pattern/2,
resolve_snowflake/2
]).
-type sentence() :: wfc_sentence:sentence().
-record(ctx,
{snowflakes :: #{binary() := fun()},
patterns :: #{binary() := sentence()}}).
{snowflakes = #{} :: #{binary() := fun(([sentence()]) -> {ok, sentence()} | {error, string()})},
patterns = #{} :: #{binary() := sentence()}}).
-opaque context() :: #ctx{}.
@@ -25,10 +27,12 @@ new() ->
patterns = #{}}.
%% FIXME
default() ->
new().
#ctx{snowflakes = default_snowflakes()}.
default_snowflakes() ->
#{<<"and">> => fun wfc:mul/1,
<<"xor">> => fun wfc:add/1}.
define(Pat, Sentence, Ctx = #ctx{patterns = OldPatterns}) ->
NewPatterns = maps:put(Pat, Sentence, OldPatterns),
@@ -39,3 +43,9 @@ resolve_pattern(Pat, Ctx = #ctx{patterns = Patterns}) ->
error -> {error, wfc_utils:str("wfc_eval_context:resolve_pattern: not found: ~w; context: ~w", [Pat, Ctx])};
Result -> Result
end.
resolve_snowflake(SF, Ctx = #ctx{snowflakes = Snowflakes}) ->
case maps:find(SF, Snowflakes) of
error -> {error, wfc_utils:str("wfc_eval_context:resolve_snowflake: not found: ~w; context: ~w", [SF, Ctx])};
Result -> Result
end.