-module(handles@internal@parser). -compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]). -define(FILEPATH, "src/handles/internal/parser.gleam"). -export([run/1]). -export_type([a_s_t/0, parse_result/0]). -if(?OTP_RELEASE >= 27). -define(MODULEDOC(Str), -moduledoc(Str)). -define(DOC(Str), -doc(Str)). -else. -define(MODULEDOC(Str), -compile([])). -define(DOC(Str), -compile([])). -endif. ?MODULEDOC(false). -type a_s_t() :: {constant, integer(), binary()} | {property, integer(), list(binary())} | {partial, integer(), binary(), list(binary())} | {block, integer(), integer(), handles@internal@block:kind(), list(binary()), list(a_s_t())}. -type parse_result() :: {e_o_f, list(a_s_t())} | {block_end, integer(), handles@internal@block:kind(), list(a_s_t()), list(handles@internal@tokenizer:token())}. -file("src/handles/internal/parser.gleam", 30). ?DOC(false). -spec parse(list(a_s_t()), list(handles@internal@tokenizer:token())) -> {ok, parse_result()} | {error, handles@error:tokenizer_error()}. parse(Ast, Tokens) -> case Tokens of [] -> {ok, {e_o_f, lists:reverse(Ast)}}; [{block_end, Index, Kind} | Tail] -> {ok, {block_end, Index, Kind, lists:reverse(Ast), Tail}}; [{constant, Index@1, Value} | Tail@1] -> _pipe = [{constant, Index@1, Value} | Ast], parse(_pipe, Tail@1); [{property, Index@2, Path} | Tail@2] -> _pipe@1 = [{property, Index@2, Path} | Ast], parse(_pipe@1, Tail@2); [{partial, Index@3, Id, Value@1} | Tail@3] -> _pipe@2 = [{partial, Index@3, Id, Value@1} | Ast], parse(_pipe@2, Tail@3); [{block_start, Start_index, Start_kind, Path@1} | Tail@4] -> case parse([], Tail@4) of {error, Err} -> {error, Err}; {ok, {e_o_f, _}} -> _pipe@3 = Start_index, _pipe@4 = {unbalanced_block, _pipe@3}, {error, _pipe@4}; {ok, {block_end, End_index, End_kind, Children, Rest}} when End_kind =:= Start_kind -> _pipe@5 = [{block, Start_index, End_index, Start_kind, Path@1, Children} | Ast], parse(_pipe@5, Rest); {ok, {block_end, Index@4, _, _, _}} -> _pipe@6 = Index@4, _pipe@7 = {unexpected_block_end, _pipe@6}, {error, _pipe@7} end end. -file("src/handles/internal/parser.gleam", 69). ?DOC(false). -spec run(list(handles@internal@tokenizer:token())) -> {ok, list(a_s_t())} | {error, handles@error:tokenizer_error()}. run(Tokens) -> _pipe = parse([], Tokens), gleam@result:'try'(_pipe, fun(It) -> case It of {e_o_f, Ast} -> {ok, Ast}; {block_end, Index, _, _, _} -> _pipe@1 = Index, _pipe@2 = {unexpected_block_end, _pipe@1}, {error, _pipe@2} end end).