too fucking tired... going to bed
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
-module(wfc_eval_context).
|
||||
|
||||
-export_type([
|
||||
context/0
|
||||
]).
|
||||
|
||||
-export([
|
||||
new/0,
|
||||
default/0,
|
||||
define/3,
|
||||
resolve_pattern/2
|
||||
]).
|
||||
|
||||
-type sentence() :: wfc_sentence:sentence().
|
||||
|
||||
-record(ctx,
|
||||
{snowflakes :: #{binary() := fun()},
|
||||
patterns :: #{binary() := sentence()}}).
|
||||
|
||||
-opaque context() :: #ctx{}.
|
||||
|
||||
|
||||
new() ->
|
||||
#ctx{snowflakes = #{},
|
||||
patterns = #{}}.
|
||||
|
||||
|
||||
%% FIXME
|
||||
default() ->
|
||||
new().
|
||||
|
||||
|
||||
define(Pat, Sentence, Ctx = #ctx{patterns = OldPatterns}) ->
|
||||
NewPatterns = maps:put(Pat, Sentence, OldPatterns),
|
||||
{ok, Ctx#ctx{patterns = NewPatterns}}.
|
||||
|
||||
resolve_pattern(Pat, Ctx = #ctx{patterns = Patterns}) ->
|
||||
case maps:find(Pat, Patterns) of
|
||||
error -> {error, wfc_utils:str("wfc_eval_context:resolve_pattern: not found: ~w; context: ~w", [Pat, Ctx])};
|
||||
Result -> Result
|
||||
end.
|
||||
Reference in New Issue
Block a user