-module(handles@internal@engine). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]). -export([run/3]). -spec run( list(handles@internal@parser:ast()), handles@ctx:value(), gleam@string_builder:string_builder() ) -> {ok, binary()} | {error, handles@error:runtime_error()}. run(Ast, Ctx, Builder) -> case Ast of [] -> _pipe = Builder, _pipe@1 = gleam@string_builder:to_string(_pipe), {ok, _pipe@1}; [Node | Rest] -> _pipe@6 = case Node of {constant, _, Value} -> {ok, Value}; {property, Index, Path} -> handles@internal@ctx_utils:get_property(Index, Path, Ctx); {if_block, Index@1, Path@1, Children} -> _pipe@2 = handles@internal@ctx_utils:get_bool( Index@1, Path@1, Ctx ), gleam@result:'try'( _pipe@2, fun(_capture) -> run_if(_capture, Children, Ctx) end ); {unless_block, Index@2, Path@2, Children@1} -> _pipe@3 = handles@internal@ctx_utils:get_bool( Index@2, Path@2, Ctx ), _pipe@4 = gleam@result:map(_pipe@3, fun gleam@bool:negate/1), gleam@result:'try'( _pipe@4, fun(_capture@1) -> run_if(_capture@1, Children@1, Ctx) end ); {each_block, Index@3, Path@3, Children@2} -> _pipe@5 = handles@internal@ctx_utils:get_list( Index@3, Path@3, Ctx ), gleam@result:'try'( _pipe@5, fun(_capture@2) -> run_each( _capture@2, Children@2, gleam@string_builder:new() ) end ) end, gleam@result:'try'( _pipe@6, fun(It) -> run( Rest, Ctx, begin _pipe@7 = Builder, gleam@string_builder:append(_pipe@7, It) end ) end ) end. -spec run_if( boolean(), list(handles@internal@parser:ast()), handles@ctx:value() ) -> {ok, binary()} | {error, handles@error:runtime_error()}. run_if(Bool, Children, Ctx) -> case Bool of false -> {ok, <<""/utf8>>}; true -> run(Children, Ctx, gleam@string_builder:new()) end. -spec run_each( list(handles@ctx:value()), list(handles@internal@parser:ast()), gleam@string_builder:string_builder() ) -> {ok, binary()} | {error, handles@error:runtime_error()}. run_each(Ctxs, Ast, Builder) -> case Ctxs of [] -> _pipe = Builder, _pipe@1 = gleam@string_builder:to_string(_pipe), {ok, _pipe@1}; [Ctx | Rest] -> _pipe@2 = run(Ast, Ctx, gleam@string_builder:new()), gleam@result:'try'( _pipe@2, fun(It) -> run_each( Rest, Ast, begin _pipe@3 = Builder, gleam@string_builder:append(_pipe@3, It) end ) end ) end.