Packages

A YAML 1.2 parser for Gleam, with an optional native fast_yaml C NIF backend.

Current section

Files

Jump to
taffy src taffy@parser@block.erl
Raw

src/taffy@parser@block.erl

-module(taffy@parser@block).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/taffy/parser/block.gleam").
-export([parse_mapping_key/1, parse_block_sequence_at/4, parse_block_sequence/3, parse_mapping_value/3, parse_block_mapping_from_key_col/5, parse_block_mapping_from_key/4]).
-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).
-file("src/taffy/parser/block.gleam", 393).
?DOC(false).
-spec is_anchor_on_mapping_key(taffy@parser@types:parser()) -> boolean().
is_anchor_on_mapping_key(Parser) ->
After_anchor = taffy@parser@helpers:advance(Parser),
case taffy@parser@helpers:current(After_anchor) of
{some, {plain, _}} ->
After_scalar = taffy@parser@helpers:advance(After_anchor),
case taffy@parser@helpers:current(After_scalar) of
{some, colon} ->
true;
_ ->
false
end;
{some, {single_quoted, _}} ->
After_scalar = taffy@parser@helpers:advance(After_anchor),
case taffy@parser@helpers:current(After_scalar) of
{some, colon} ->
true;
_ ->
false
end;
{some, {double_quoted, _}} ->
After_scalar = taffy@parser@helpers:advance(After_anchor),
case taffy@parser@helpers:current(After_scalar) of
{some, colon} ->
true;
_ ->
false
end;
_ ->
true
end.
-file("src/taffy/parser/block.gleam", 479).
?DOC(false).
-spec parse_and_register_anchor(
taffy@parser@types:parser(),
integer(),
binary(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_and_register_anchor(Parser, Min_indent, Anchor_name, Parse_value_fn) ->
gleam@result:'try'(
Parse_value_fn(Parser, Min_indent),
fun(_use0) ->
{Val, Parser@1} = _use0,
Parser@2 = taffy@parser@types:register_anchor(
Parser@1,
Anchor_name,
Val
),
{ok, {Val, Parser@2}}
end
).
-file("src/taffy/parser/block.gleam", 363).
?DOC(false).
-spec check_double_anchor_then_parse(
taffy@parser@types:parser(),
integer(),
binary(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
check_double_anchor_then_parse(Parser, Key_indent, Anchor_name, Parse_value_fn) ->
After_indent = taffy@parser@helpers:advance(Parser),
case taffy@parser@helpers:current(After_indent) of
{some, {anchor, _}} ->
case is_anchor_on_mapping_key(After_indent) of
true ->
parse_and_register_anchor(
Parser,
Key_indent + 1,
Anchor_name,
Parse_value_fn
);
false ->
{error,
{parse_error,
<<"A node can only have one anchor"/utf8>>,
erlang:element(4, After_indent)}}
end;
_ ->
parse_and_register_anchor(
Parser,
Key_indent + 1,
Anchor_name,
Parse_value_fn
)
end.
-file("src/taffy/parser/block.gleam", 490).
?DOC(false).
-spec wrap_with_anchor(
taffy@value:yaml_value(),
gleam@option:option(binary()),
taffy@parser@types:parser()
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
wrap_with_anchor(Val, Anchor, Parser) ->
case Anchor of
{some, Name} ->
Parser@1 = taffy@parser@types:register_anchor(Parser, Name, Val),
{ok, {Val, Parser@1}};
none ->
{ok, {Val, Parser}}
end.
-file("src/taffy/parser/block.gleam", 234).
?DOC(false).
-spec parse_value_with_anchor(
taffy@parser@types:parser(),
integer(),
gleam@option:option(binary()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_value_with_anchor(Parser, Min_indent, Anchor, Parse_value_fn) ->
gleam@result:'try'(
Parse_value_fn(Parser, Min_indent),
fun(_use0) ->
{Val, Parser@1} = _use0,
wrap_with_anchor(Val, Anchor, Parser@1)
end
).
-file("src/taffy/parser/block.gleam", 844).
?DOC(false).
-spec is_key_terminator(gleam@option:option(taffy@lexer:token())) -> boolean().
is_key_terminator(Token) ->
case Token of
{some, {plain, _}} ->
true;
{some, {single_quoted, _}} ->
true;
{some, {double_quoted, _}} ->
true;
{some, newline} ->
true;
{some, {indent, _}} ->
true;
{some, eof} ->
true;
{some, {comment, _}} ->
true;
{some, {anchor, _}} ->
true;
{some, {alias, _}} ->
true;
{some, {tag, _}} ->
true;
{some, dash} ->
true;
{some, question} ->
true;
{some, {literal, _}} ->
true;
{some, {folded, _}} ->
true;
{some, brace_open} ->
true;
{some, bracket_open} ->
true;
none ->
true;
_ ->
false
end.
-file("src/taffy/parser/block.gleam", 820).
?DOC(false).
-spec collect_block_key(taffy@parser@types:parser(), binary()) -> {ok,
{binary(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
collect_block_key(Parser, Acc) ->
case taffy@parser@helpers:current(Parser) of
{some, comma} ->
collect_block_key(
taffy@parser@helpers:advance(Parser),
<<Acc/binary, ","/utf8>>
);
{some, bracket_open} ->
collect_block_key(
taffy@parser@helpers:advance(Parser),
<<Acc/binary, "["/utf8>>
);
{some, bracket_close} ->
collect_block_key(
taffy@parser@helpers:advance(Parser),
<<Acc/binary, "]"/utf8>>
);
{some, brace_open} ->
collect_block_key(
taffy@parser@helpers:advance(Parser),
<<Acc/binary, "{"/utf8>>
);
{some, brace_close} ->
collect_block_key(
taffy@parser@helpers:advance(Parser),
<<Acc/binary, "}"/utf8>>
);
{some, {plain, S}} ->
collect_block_key(
taffy@parser@helpers:advance(Parser),
<<Acc/binary, S/binary>>
);
{some, colon} ->
After_colon = taffy@parser@helpers:advance(Parser),
case is_key_terminator(taffy@parser@helpers:current(After_colon)) of
true ->
{ok, {Acc, Parser}};
false ->
collect_block_key(After_colon, <<Acc/binary, ":"/utf8>>)
end;
_ ->
{ok, {Acc, Parser}}
end.
-file("src/taffy/parser/block.gleam", 786).
?DOC(false).
-spec parse_mapping_key(taffy@parser@types:parser()) -> {ok,
{binary(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_mapping_key(Parser) ->
case taffy@parser@helpers:current(Parser) of
{some, {plain, S}} ->
collect_block_key(taffy@parser@helpers:advance(Parser), S);
{some, {single_quoted, S@1}} ->
{ok, {S@1, taffy@parser@helpers:advance(Parser)}};
{some, {double_quoted, S@1}} ->
{ok, {S@1, taffy@parser@helpers:advance(Parser)}};
{some, {alias, Name}} ->
Parser@1 = taffy@parser@helpers:advance(Parser),
case taffy@parser@types:resolve_alias(Parser@1, Name) of
{ok, {Val, Parser@2}} ->
{ok,
{taffy@parser@scalar:value_to_key_string(Val), Parser@2}};
{error, <<"budget exceeded"/utf8>>} ->
{error,
{parse_error,
<<"Alias expansion budget exceeded (possible alias-bomb)"/utf8>>,
erlang:element(4, Parser@1)}};
{error, _} ->
{error,
{parse_error,
<<"Unknown anchor: "/utf8, Name/binary>>,
erlang:element(4, Parser@1)}}
end;
{some, {anchor, Name@1}} ->
gleam@result:'try'(
parse_mapping_key(taffy@parser@helpers:advance(Parser)),
fun(_use0) ->
{Key, Parser@3} = _use0,
Parser@4 = taffy@parser@types:register_anchor(
Parser@3,
Name@1,
{string, Key}
),
{ok, {Key, Parser@4}}
end
);
{some, {tag, _}} ->
parse_mapping_key(taffy@parser@helpers:advance(Parser));
_ ->
{error,
{parse_error,
<<"Expected mapping key"/utf8>>,
erlang:element(4, Parser)}}
end.
-file("src/taffy/parser/block.gleam", 1010).
?DOC(false).
-spec collect_explicit_key_value(taffy@parser@types:parser(), binary()) -> {binary(),
taffy@parser@types:parser()}.
collect_explicit_key_value(Parser, Acc) ->
case taffy@parser@helpers:current(Parser) of
{some, {plain, S}} ->
collect_explicit_key_value(
taffy@parser@helpers:advance(Parser),
<<<<Acc/binary, " "/utf8>>/binary, S/binary>>
);
{some, newline} ->
After_newline = taffy@parser@helpers:advance(Parser),
case taffy@parser@helpers:current(After_newline) of
{some, {indent, N}} when N > 0 ->
After_indent = taffy@parser@helpers:advance(After_newline),
case taffy@parser@helpers:current(After_indent) of
{some, colon} ->
{Acc, After_newline};
{some, {plain, S@1}} ->
collect_explicit_key_value(
taffy@parser@helpers:advance(After_indent),
<<<<Acc/binary, " "/utf8>>/binary, S@1/binary>>
);
_ ->
{Acc, After_newline}
end;
_ ->
{Acc, Parser}
end;
{some, {indent, N@1}} when N@1 > 0 ->
After_indent@1 = taffy@parser@helpers:advance(Parser),
case taffy@parser@helpers:current(After_indent@1) of
{some, colon} ->
{Acc, Parser};
{some, {plain, S@2}} ->
collect_explicit_key_value(
taffy@parser@helpers:advance(After_indent@1),
<<<<Acc/binary, " "/utf8>>/binary, S@2/binary>>
);
_ ->
{Acc, Parser}
end;
{some, colon} ->
{Acc, Parser};
{some, {comment, _}} ->
{Acc, Parser};
_ ->
{Acc, Parser}
end.
-file("src/taffy/parser/block.gleam", 639).
?DOC(false).
-spec add_key_value_pair_col(
binary(),
taffy@parser@types:parser(),
integer(),
integer(),
gleam@option:option(integer()),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
add_key_value_pair_col(
Key,
Parser,
Key_indent,
Mapping_indent,
Mapping_col,
Acc,
Parse_value_fn
) ->
gleam@result:'try'(
parse_mapping_value(Parser, Key_indent, Parse_value_fn),
fun(_use0) ->
{Val, Parser@1} = _use0,
Acc@1 = [{Key, Val} | Acc],
parse_block_mapping_pairs_col(
Parser@1,
Mapping_indent,
Mapping_col,
Acc@1,
Parse_value_fn
)
end
).
-file("src/taffy/parser/block.gleam", 504).
?DOC(false).
-spec parse_block_mapping_pairs_col(
taffy@parser@types:parser(),
integer(),
gleam@option:option(integer()),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_block_mapping_pairs_col(
Parser,
Min_indent,
Mapping_col,
Acc,
Parse_value_fn
) ->
Parser@1 = taffy@parser@helpers:skip_newlines_and_comments(Parser),
Done = {ok, {{mapping, lists:reverse(Acc)}, Parser@1}},
case taffy@parser@helpers:current(Parser@1) of
{some, {indent, N}} ->
Accepted = case Mapping_col of
{some, Col} ->
N =:= Col;
none ->
case Min_indent of
0 ->
false;
_ ->
N >= Min_indent
end
end,
case Accepted of
true ->
New_col = case Mapping_col of
{some, _} ->
Mapping_col;
none ->
{some, N}
end,
parse_indented_mapping_pair_col(
taffy@parser@helpers:advance(Parser@1),
Min_indent,
N,
New_col,
Acc,
Parser@1,
Parse_value_fn
);
false ->
Done
end;
{some, colon} when Min_indent =:= 0 ->
add_key_value_pair_col(
<<""/utf8>>,
taffy@parser@helpers:advance(Parser@1),
Min_indent,
Min_indent,
{some, 0},
Acc,
Parse_value_fn
);
{some, question} when Min_indent =:= 0 ->
parse_explicit_key_in_mapping(
Parser@1,
Min_indent,
0,
Acc,
Parse_value_fn
);
{some, {plain, S}} when Min_indent =:= 0 ->
try_scalar_as_mapping_key(
S,
Parser@1,
Min_indent,
Acc,
Done,
Parse_value_fn
);
{some, {single_quoted, S}} when Min_indent =:= 0 ->
try_scalar_as_mapping_key(
S,
Parser@1,
Min_indent,
Acc,
Done,
Parse_value_fn
);
{some, {double_quoted, S}} when Min_indent =:= 0 ->
try_scalar_as_mapping_key(
S,
Parser@1,
Min_indent,
Acc,
Done,
Parse_value_fn
);
{some, {alias, Name}} when Min_indent =:= 0 ->
parse_alias_key(
Name,
taffy@parser@helpers:advance(Parser@1),
Min_indent,
Acc,
Parse_value_fn
);
{some, {anchor, Name@1}} when Min_indent =:= 0 ->
parse_anchored_key(
Name@1,
taffy@parser@helpers:advance(Parser@1),
Min_indent,
Acc,
Parse_value_fn
);
{some, {tag, _}} when Min_indent =:= 0 ->
parse_tagged_key(
taffy@parser@helpers:advance(Parser@1),
Min_indent,
Acc,
Parse_value_fn
);
_ ->
Done
end.
-file("src/taffy/parser/block.gleam", 760).
?DOC(false).
-spec parse_tagged_key(
taffy@parser@types:parser(),
integer(),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_tagged_key(Parser, Min_indent, Acc, Parse_value_fn) ->
case parse_mapping_key(Parser) of
{ok, {Key, Parser@1}} ->
case taffy@parser@helpers:current(Parser@1) of
{some, colon} ->
add_key_value_pair_col(
Key,
taffy@parser@helpers:advance(Parser@1),
Min_indent,
Min_indent,
none,
Acc,
Parse_value_fn
);
_ ->
{ok, {{mapping, lists:reverse(Acc)}, Parser@1}}
end;
{error, _} ->
{ok, {{mapping, lists:reverse(Acc)}, Parser}}
end.
-file("src/taffy/parser/block.gleam", 663).
?DOC(false).
-spec try_scalar_as_mapping_key(
binary(),
taffy@parser@types:parser(),
integer(),
list({binary(), taffy@value:yaml_value()}),
{ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()},
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
try_scalar_as_mapping_key(Key, Parser, Min_indent, Acc, Done, Parse_value_fn) ->
After_key = taffy@parser@helpers:advance(Parser),
case taffy@parser@helpers:current(After_key) of
{some, colon} ->
add_key_value_pair_col(
Key,
taffy@parser@helpers:advance(After_key),
Min_indent,
Min_indent,
{some, 0},
Acc,
Parse_value_fn
);
_ ->
Done
end.
-file("src/taffy/parser/block.gleam", 687).
?DOC(false).
-spec parse_alias_key(
binary(),
taffy@parser@types:parser(),
integer(),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_alias_key(Name, Parser, Min_indent, Acc, Parse_value_fn) ->
case taffy@parser@types:resolve_alias(Parser, Name) of
{ok, {Key_val, Parser@1}} ->
Key = taffy@parser@scalar:value_to_key_string(Key_val),
case taffy@parser@helpers:current(Parser@1) of
{some, colon} ->
add_key_value_pair_col(
Key,
taffy@parser@helpers:advance(Parser@1),
Min_indent,
Min_indent,
none,
Acc,
Parse_value_fn
);
_ ->
{ok, {{mapping, lists:reverse(Acc)}, Parser@1}}
end;
{error, <<"budget exceeded"/utf8>>} ->
{error,
{parse_error,
<<"Alias expansion budget exceeded (possible alias-bomb)"/utf8>>,
erlang:element(4, Parser)}};
{error, _} ->
{error,
{parse_error,
<<"Unknown anchor: "/utf8, Name/binary>>,
erlang:element(4, Parser)}}
end.
-file("src/taffy/parser/block.gleam", 885).
?DOC(false).
-spec handle_explicit_key_value(
binary(),
taffy@parser@types:parser(),
integer(),
integer(),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
handle_explicit_key_value(
Key,
Parser,
Min_indent,
Key_indent,
Acc,
Parse_value_fn
) ->
case taffy@parser@helpers:current(Parser) of
{some, colon} ->
gleam@result:'try'(
Parse_value_fn(
taffy@parser@helpers:advance(Parser),
Key_indent + 1
),
fun(_use0) ->
{Val, Parser@1} = _use0,
parse_block_mapping_pairs_col(
Parser@1,
Min_indent,
none,
[{Key, Val} | Acc],
Parse_value_fn
)
end
);
{some, {indent, N}} ->
handle_indented_explicit_key_value(
Key,
taffy@parser@helpers:advance(Parser),
Min_indent,
N,
Acc,
Parse_value_fn
);
{some, question} ->
Acc@1 = [{Key, null} | Acc],
parse_explicit_key_in_mapping(
Parser,
Min_indent,
Key_indent,
Acc@1,
Parse_value_fn
);
_ ->
Acc@2 = [{Key, null} | Acc],
parse_block_mapping_pairs_col(
Parser,
Min_indent,
none,
Acc@2,
Parse_value_fn
)
end.
-file("src/taffy/parser/block.gleam", 942).
?DOC(false).
-spec handle_indented_explicit_key_value(
binary(),
taffy@parser@types:parser(),
integer(),
integer(),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
handle_indented_explicit_key_value(
Key,
Parser,
Min_indent,
Indent_level,
Acc,
Parse_value_fn
) ->
case taffy@parser@helpers:current(Parser) of
{some, colon} ->
gleam@result:'try'(
Parse_value_fn(
taffy@parser@helpers:advance(Parser),
Indent_level + 1
),
fun(_use0) ->
{Val, Parser@1} = _use0,
parse_block_mapping_pairs_col(
Parser@1,
Min_indent,
none,
[{Key, Val} | Acc],
Parse_value_fn
)
end
);
{some, question} ->
Acc@1 = [{Key, null} | Acc],
parse_explicit_key_in_mapping(
Parser,
Min_indent,
Indent_level,
Acc@1,
Parse_value_fn
);
{some, {plain, S}} ->
Acc@2 = [{Key, null} | Acc],
Parser@2 = taffy@parser@helpers:advance(Parser),
case taffy@parser@helpers:current(Parser@2) of
{some, colon} ->
gleam@result:'try'(
Parse_value_fn(
taffy@parser@helpers:advance(Parser@2),
Indent_level + 1
),
fun(_use0@1) ->
{Val@1, Parser@3} = _use0@1,
parse_block_mapping_pairs_col(
Parser@3,
Min_indent,
none,
[{S, Val@1} | Acc@2],
Parse_value_fn
)
end
);
_ ->
{ok, {{mapping, lists:reverse(Acc@2)}, Parser@2}}
end;
_ ->
Acc@3 = [{Key, null} | Acc],
parse_block_mapping_pairs_col(
Parser,
Min_indent,
none,
Acc@3,
Parse_value_fn
)
end.
-file("src/taffy/parser/block.gleam", 864).
?DOC(false).
-spec parse_explicit_key_in_mapping(
taffy@parser@types:parser(),
integer(),
integer(),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_explicit_key_in_mapping(
Parser,
Min_indent,
Key_indent,
Acc,
Parse_value_fn
) ->
Parser@1 = taffy@parser@helpers:advance(Parser),
gleam@result:'try'(
parse_explicit_key(Parser@1, Parse_value_fn),
fun(_use0) ->
{Key, Parser@2} = _use0,
Parser@3 = taffy@parser@helpers:skip_newlines_and_comments(Parser@2),
handle_explicit_key_value(
Key,
Parser@3,
Min_indent,
Key_indent,
Acc,
Parse_value_fn
)
end
).
-file("src/taffy/parser/block.gleam", 585).
?DOC(false).
-spec parse_indented_mapping_pair_col(
taffy@parser@types:parser(),
integer(),
integer(),
gleam@option:option(integer()),
list({binary(), taffy@value:yaml_value()}),
taffy@parser@types:parser(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_indented_mapping_pair_col(
Parser,
Min_indent,
Indent_level,
Mapping_col,
Acc,
Pre_indent_parser,
Parse_value_fn
) ->
Backtrack = {ok, {{mapping, lists:reverse(Acc)}, Pre_indent_parser}},
case taffy@parser@helpers:current(Parser) of
{some, colon} ->
add_key_value_pair_col(
<<""/utf8>>,
taffy@parser@helpers:advance(Parser),
Indent_level,
Min_indent,
Mapping_col,
Acc,
Parse_value_fn
);
{some, question} ->
parse_explicit_key_in_mapping(
Parser,
Min_indent,
Indent_level,
Acc,
Parse_value_fn
);
_ ->
case parse_mapping_key(Parser) of
{ok, {Key, Parser@1}} ->
case taffy@parser@helpers:current(Parser@1) of
{some, colon} ->
add_key_value_pair_col(
Key,
taffy@parser@helpers:advance(Parser@1),
Indent_level,
Min_indent,
Mapping_col,
Acc,
Parse_value_fn
);
_ ->
Backtrack
end;
{error, _} ->
Backtrack
end
end.
-file("src/taffy/parser/block.gleam", 102).
?DOC(false).
-spec parse_sequence_item_col(
taffy@parser@types:parser(),
integer(),
integer(),
gleam@option:option(integer()),
list(taffy@value:yaml_value()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_sequence_item_col(
Parser,
Min_indent,
Item_indent,
Seq_col,
Acc,
Parse_value_fn
) ->
Parser@1 = taffy@parser@helpers:advance(Parser),
Saved_sei = erlang:element(6, Parser@1),
gleam@result:'try'(
Parse_value_fn(Parser@1, Item_indent),
fun(_use0) ->
{Val, Parser@2} = _use0,
Parser@3 = {parser,
erlang:element(2, Parser@2),
erlang:element(3, Parser@2),
erlang:element(4, Parser@2),
erlang:element(5, Parser@2),
Saved_sei,
erlang:element(7, Parser@2),
erlang:element(8, Parser@2),
erlang:element(9, Parser@2),
erlang:element(10, Parser@2),
erlang:element(11, Parser@2),
erlang:element(12, Parser@2),
erlang:element(13, Parser@2)},
parse_block_sequence_items_col(
Parser@3,
Min_indent,
Seq_col,
[Val | Acc],
Parse_value_fn
)
end
).
-file("src/taffy/parser/block.gleam", 49).
?DOC(false).
-spec parse_block_sequence_items_col(
taffy@parser@types:parser(),
integer(),
gleam@option:option(integer()),
list(taffy@value:yaml_value()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_block_sequence_items_col(Parser, Min_indent, Seq_col, Acc, Parse_value_fn) ->
Parser@1 = taffy@parser@helpers:skip_newlines_and_comments(Parser),
Is_first_item = gleam@list:is_empty(Acc),
case taffy@parser@helpers:current(Parser@1) of
{some, dash} when Is_first_item orelse (Min_indent =:= 0) ->
parse_sequence_item_col(
Parser@1,
Min_indent,
Min_indent + 1,
Seq_col,
Acc,
Parse_value_fn
);
{some, {indent, N}} ->
Accepted = case Seq_col of
{some, Col} ->
N =:= Col;
none ->
N >= Min_indent
end,
case Accepted of
true ->
New_col = case Seq_col of
{some, _} ->
Seq_col;
none ->
{some, N}
end,
Parser@2 = taffy@parser@helpers:advance(Parser@1),
case taffy@parser@helpers:current(Parser@2) of
{some, dash} ->
parse_sequence_item_col(
Parser@2,
Min_indent,
N + 1,
New_col,
Acc,
Parse_value_fn
);
_ ->
{ok, {{sequence, lists:reverse(Acc)}, Parser@2}}
end;
false ->
{ok, {{sequence, lists:reverse(Acc)}, Parser@1}}
end;
_ ->
{ok, {{sequence, lists:reverse(Acc)}, Parser@1}}
end.
-file("src/taffy/parser/block.gleam", 29).
?DOC(false).
-spec parse_block_sequence_at(
taffy@parser@types:parser(),
integer(),
gleam@option:option(integer()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_block_sequence_at(Parser, Min_indent, Dash_col, Parse_value_fn) ->
Entry_indent = case Min_indent of
0 ->
{some, 0};
_ ->
none
end,
Parser@1 = {parser,
erlang:element(2, Parser),
erlang:element(3, Parser),
erlang:element(4, Parser),
erlang:element(5, Parser),
Entry_indent,
erlang:element(7, Parser),
erlang:element(8, Parser),
erlang:element(9, Parser),
erlang:element(10, Parser),
erlang:element(11, Parser),
erlang:element(12, Parser),
erlang:element(13, Parser)},
parse_block_sequence_items_col(
Parser@1,
Min_indent,
Dash_col,
[],
Parse_value_fn
).
-file("src/taffy/parser/block.gleam", 15).
?DOC(false).
-spec parse_block_sequence(
taffy@parser@types:parser(),
integer(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_block_sequence(Parser, Min_indent, Parse_value_fn) ->
parse_block_sequence_at(Parser, Min_indent, none, Parse_value_fn).
-file("src/taffy/parser/block.gleam", 442).
?DOC(false).
-spec parse_anchored_indented_value(
taffy@parser@types:parser(),
integer(),
integer(),
binary(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_anchored_indented_value(
Parser,
Key_indent,
Indent_level,
Anchor_name,
Parse_value_fn
) ->
case taffy@parser@helpers:current(Parser) of
{some, {anchor, _}} ->
{error,
{parse_error,
<<"A node can only have one anchor"/utf8>>,
erlang:element(4, Parser)}};
{some, dash} when Indent_level >= Key_indent ->
Parser@1 = taffy@parser@helpers:backtrack(Parser),
gleam@result:'try'(
parse_block_sequence(Parser@1, Indent_level, Parse_value_fn),
fun(_use0) ->
{Val, Parser@2} = _use0,
Parser@3 = taffy@parser@types:register_anchor(
Parser@2,
Anchor_name,
Val
),
{ok, {Val, Parser@3}}
end
);
_ when Indent_level > Key_indent ->
Parser@4 = taffy@parser@helpers:backtrack(Parser),
parse_and_register_anchor(
Parser@4,
Key_indent + 1,
Anchor_name,
Parse_value_fn
);
_ ->
Parser@5 = taffy@parser@helpers:backtrack(Parser),
Parser@6 = taffy@parser@types:register_anchor(
Parser@5,
Anchor_name,
null
),
{ok, {null, Parser@6}}
end.
-file("src/taffy/parser/block.gleam", 409).
?DOC(false).
-spec parse_anchored_value_after_newline(
taffy@parser@types:parser(),
integer(),
binary(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_anchored_value_after_newline(
Parser,
Key_indent,
Anchor_name,
Parse_value_fn
) ->
case taffy@parser@helpers:current(Parser) of
{some, dash} when Key_indent =:= 0 ->
gleam@result:'try'(
parse_block_sequence(Parser, 0, Parse_value_fn),
fun(_use0) ->
{Val, Parser@1} = _use0,
Parser@2 = taffy@parser@types:register_anchor(
Parser@1,
Anchor_name,
Val
),
{ok, {Val, Parser@2}}
end
);
{some, {indent, N}} ->
parse_anchored_indented_value(
taffy@parser@helpers:advance(Parser),
Key_indent,
N,
Anchor_name,
Parse_value_fn
);
_ ->
Parser@3 = taffy@parser@types:register_anchor(
Parser,
Anchor_name,
null
),
{ok, {null, Parser@3}}
end.
-file("src/taffy/parser/block.gleam", 328).
?DOC(false).
-spec parse_mapping_value_after_anchor(
taffy@parser@types:parser(),
integer(),
binary(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_mapping_value_after_anchor(
Parser,
Key_indent,
Anchor_name,
Parse_value_fn
) ->
case taffy@parser@helpers:current(Parser) of
{some, {alias, _}} ->
{error,
{parse_error,
<<"Cannot place an anchor on an alias"/utf8>>,
erlang:element(4, Parser)}};
{some, {anchor, _}} ->
{error,
{parse_error,
<<"A node can only have one anchor"/utf8>>,
erlang:element(4, Parser)}};
{some, newline} ->
parse_anchored_value_after_newline(
taffy@parser@helpers:advance(Parser),
Key_indent,
Anchor_name,
Parse_value_fn
);
{some, {indent, N}} when N > Key_indent ->
check_double_anchor_then_parse(
Parser,
Key_indent,
Anchor_name,
Parse_value_fn
);
_ ->
parse_and_register_anchor(
Parser,
Key_indent + 1,
Anchor_name,
Parse_value_fn
)
end.
-file("src/taffy/parser/block.gleam", 244).
?DOC(false).
-spec parse_indented_mapping_value(
taffy@parser@types:parser(),
integer(),
integer(),
gleam@option:option(binary()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_indented_mapping_value(
Parser,
Key_indent,
Indent_level,
Anchor,
Parse_value_fn
) ->
case taffy@parser@helpers:current(Parser) of
{some, dash} when Indent_level >= Key_indent ->
Parser@1 = taffy@parser@helpers:backtrack(Parser),
gleam@result:'try'(
parse_block_sequence(Parser@1, Indent_level, Parse_value_fn),
fun(_use0) ->
{Val, Parser@2} = _use0,
wrap_with_anchor(Val, Anchor, Parser@2)
end
);
{some, {anchor, Name}} ->
parse_mapping_value_after_anchor(
taffy@parser@helpers:advance(Parser),
Key_indent,
Name,
Parse_value_fn
);
_ ->
Parser@3 = taffy@parser@helpers:backtrack(Parser),
parse_value_with_anchor(
Parser@3,
Key_indent + 1,
Anchor,
Parse_value_fn
)
end.
-file("src/taffy/parser/block.gleam", 275).
?DOC(false).
-spec parse_mapping_value_after_newline(
taffy@parser@types:parser(),
integer(),
gleam@option:option(binary()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_mapping_value_after_newline(Parser, Key_indent, Anchor, Parse_value_fn) ->
case taffy@parser@helpers:current(Parser) of
{some, {indent, N}} ->
parse_indented_mapping_value(
taffy@parser@helpers:advance(Parser),
Key_indent,
N,
Anchor,
Parse_value_fn
);
{some, dash} when Key_indent =:= 0 ->
gleam@result:'try'(
parse_block_sequence(Parser, 0, Parse_value_fn),
fun(_use0) ->
{Val, Parser@1} = _use0,
wrap_with_anchor(Val, Anchor, Parser@1)
end
);
{some, {anchor, Name}} when Key_indent > 0 ->
parse_mapping_value_after_anchor(
taffy@parser@helpers:advance(Parser),
Key_indent,
Name,
Parse_value_fn
);
{some, {comment, _}} ->
parse_mapping_value_after_newline(
taffy@parser@helpers:advance(Parser),
Key_indent,
Anchor,
Parse_value_fn
);
{some, newline} ->
parse_mapping_value_after_newline(
taffy@parser@helpers:advance(Parser),
Key_indent,
Anchor,
Parse_value_fn
);
_ ->
{ok, {null, Parser}}
end.
-file("src/taffy/parser/block.gleam", 173).
?DOC(false).
-spec parse_mapping_value_with_anchor(
taffy@parser@types:parser(),
integer(),
gleam@option:option(binary()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_mapping_value_with_anchor(Parser, Key_indent, Anchor, Parse_value_fn) ->
case taffy@parser@helpers:current(Parser) of
{some, newline} ->
parse_mapping_value_after_newline(
taffy@parser@helpers:advance(Parser),
Key_indent,
Anchor,
Parse_value_fn
);
{some, {comment, _}} ->
parse_mapping_value_with_anchor(
taffy@parser@helpers:advance(Parser),
Key_indent,
Anchor,
Parse_value_fn
);
{some, {tag, _}} ->
parse_mapping_value_with_anchor(
taffy@parser@helpers:advance(Parser),
Key_indent,
Anchor,
Parse_value_fn
);
{some, {anchor, Name}} ->
parse_mapping_value_after_anchor(
taffy@parser@helpers:advance(Parser),
Key_indent,
Name,
Parse_value_fn
);
{some, {indent, N}} ->
parse_indented_mapping_value(
taffy@parser@helpers:advance(Parser),
Key_indent,
N,
Anchor,
Parse_value_fn
);
{some, dash} ->
{error,
{parse_error,
<<"Block sequence not allowed on same line as mapping key"/utf8>>,
erlang:element(4, Parser)}};
_ ->
Parser@1 = {parser,
erlang:element(2, Parser),
erlang:element(3, Parser),
erlang:element(4, Parser),
erlang:element(5, Parser),
erlang:element(6, Parser),
true,
erlang:element(8, Parser),
erlang:element(9, Parser),
erlang:element(10, Parser),
erlang:element(11, Parser),
erlang:element(12, Parser),
erlang:element(13, Parser)},
parse_value_with_anchor(
Parser@1,
Key_indent + 1,
Anchor,
Parse_value_fn
)
end.
-file("src/taffy/parser/block.gleam", 160).
?DOC(false).
-spec parse_mapping_value(
taffy@parser@types:parser(),
integer(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_mapping_value(Parser, Key_indent, Parse_value_fn) ->
case parse_mapping_value_with_anchor(
Parser,
Key_indent,
none,
Parse_value_fn
) of
{ok, {Val, Parser@1}} ->
{ok,
{Val,
{parser,
erlang:element(2, Parser@1),
erlang:element(3, Parser@1),
erlang:element(4, Parser@1),
erlang:element(5, Parser@1),
erlang:element(6, Parser@1),
false,
erlang:element(8, Parser@1),
erlang:element(9, Parser@1),
erlang:element(10, Parser@1),
erlang:element(11, Parser@1),
erlang:element(12, Parser@1),
erlang:element(13, Parser@1)}}};
Err ->
Err
end.
-file("src/taffy/parser/block.gleam", 138).
?DOC(false).
-spec parse_block_mapping_from_key_col(
binary(),
taffy@parser@types:parser(),
integer(),
gleam@option:option(integer()),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_block_mapping_from_key_col(
First_key,
Parser,
Min_indent,
First_key_col,
Parse_value_fn
) ->
gleam@result:'try'(
parse_mapping_value(Parser, Min_indent, Parse_value_fn),
fun(_use0) ->
{First_val, Parser@1} = _use0,
Initial = [{First_key, First_val}],
parse_block_mapping_pairs_col(
Parser@1,
Min_indent,
First_key_col,
Initial,
Parse_value_fn
)
end
).
-file("src/taffy/parser/block.gleam", 123).
?DOC(false).
-spec parse_block_mapping_from_key(
binary(),
taffy@parser@types:parser(),
integer(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_block_mapping_from_key(First_key, Parser, Min_indent, Parse_value_fn) ->
parse_block_mapping_from_key_col(
First_key,
Parser,
Min_indent,
none,
Parse_value_fn
).
-file("src/taffy/parser/block.gleam", 720).
?DOC(false).
-spec parse_anchored_key(
binary(),
taffy@parser@types:parser(),
integer(),
list({binary(), taffy@value:yaml_value()}),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_anchored_key(Anchor_name, Parser, Min_indent, Acc, Parse_value_fn) ->
case taffy@parser@helpers:current(Parser) of
{some, {alias, _}} ->
{error,
{parse_error,
<<"Cannot place an anchor on an alias"/utf8>>,
erlang:element(4, Parser)}};
_ ->
case parse_mapping_key(Parser) of
{ok, {Key, Parser@1}} ->
case taffy@parser@helpers:current(Parser@1) of
{some, colon} ->
Parser@2 = taffy@parser@helpers:advance(Parser@1),
gleam@result:'try'(
parse_mapping_value(
Parser@2,
Min_indent,
Parse_value_fn
),
fun(_use0) ->
{Val, Parser@3} = _use0,
Parser@4 = taffy@parser@types:register_anchor(
Parser@3,
Anchor_name,
{string, Key}
),
Acc@1 = [{Key, Val} | Acc],
parse_block_mapping_pairs_col(
Parser@4,
Min_indent,
none,
Acc@1,
Parse_value_fn
)
end
);
_ ->
{ok, {{mapping, lists:reverse(Acc)}, Parser@1}}
end;
{error, _} ->
{ok, {{mapping, lists:reverse(Acc)}, Parser}}
end
end.
-file("src/taffy/parser/block.gleam", 1143).
?DOC(false).
-spec parse_sequence_as_explicit_key(
taffy@parser@types:parser(),
integer(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {binary(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_sequence_as_explicit_key(Parser, Min_indent, Parse_value_fn) ->
gleam@result:'try'(
parse_block_sequence(Parser, Min_indent, Parse_value_fn),
fun(_use0) ->
{Seq_val, Parser@1} = _use0,
{ok, {taffy@parser@scalar:value_to_key_string(Seq_val), Parser@1}}
end
).
-file("src/taffy/parser/block.gleam", 1111).
?DOC(false).
-spec parse_explicit_key_after_newline_indent(
taffy@parser@types:parser(),
integer(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {binary(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_explicit_key_after_newline_indent(Indent_parser, N, Parse_value_fn) ->
After_indent = taffy@parser@helpers:advance(Indent_parser),
case taffy@parser@helpers:current(After_indent) of
{some, dash} ->
Parser = taffy@parser@helpers:backtrack(After_indent),
parse_sequence_as_explicit_key(Parser, N, Parse_value_fn);
{some, colon} ->
{ok, {<<""/utf8>>, Indent_parser}};
_ ->
{ok, {<<""/utf8>>, Indent_parser}}
end.
-file("src/taffy/parser/block.gleam", 1096).
?DOC(false).
-spec parse_explicit_key_after_newline(
taffy@parser@types:parser(),
taffy@parser@types:parser(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {binary(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_explicit_key_after_newline(After_newline, Original_parser, Parse_value_fn) ->
case taffy@parser@helpers:current(After_newline) of
{some, dash} ->
parse_sequence_as_explicit_key(After_newline, 0, Parse_value_fn);
{some, {indent, N}} ->
parse_explicit_key_after_newline_indent(
After_newline,
N,
Parse_value_fn
);
{some, colon} ->
{ok, {<<""/utf8>>, After_newline}};
_ ->
{ok, {<<""/utf8>>, Original_parser}}
end.
-file("src/taffy/parser/block.gleam", 1127).
?DOC(false).
-spec parse_explicit_key_after_indent(
taffy@parser@types:parser(),
integer(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {binary(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_explicit_key_after_indent(Parser, N, Parse_value_fn) ->
After_indent = taffy@parser@helpers:advance(Parser),
case taffy@parser@helpers:current(After_indent) of
{some, dash} ->
Backtracked = taffy@parser@helpers:backtrack(After_indent),
parse_sequence_as_explicit_key(Backtracked, N, Parse_value_fn);
{some, colon} ->
{ok, {<<""/utf8>>, Parser}};
_ ->
{ok, {<<""/utf8>>, Parser}}
end.
-file("src/taffy/parser/block.gleam", 1044).
?DOC(false).
-spec parse_explicit_key(
taffy@parser@types:parser(),
fun((taffy@parser@types:parser(), integer()) -> {ok,
{taffy@value:yaml_value(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()})
) -> {ok, {binary(), taffy@parser@types:parser()}} |
{error, taffy@parser@types:parse_error()}.
parse_explicit_key(Parser, Parse_value_fn) ->
case taffy@parser@helpers:current(Parser) of
{some, {plain, S}} ->
{Full_key, Parser@1} = collect_explicit_key_value(
taffy@parser@helpers:advance(Parser),
S
),
{ok, {Full_key, Parser@1}};
{some, {single_quoted, S@1}} ->
{ok, {S@1, taffy@parser@helpers:advance(Parser)}};
{some, {double_quoted, S@2}} ->
{ok, {S@2, taffy@parser@helpers:advance(Parser)}};
{some, {literal, S@3}} ->
{ok, {S@3, taffy@parser@helpers:advance(Parser)}};
{some, {folded, S@4}} ->
{ok, {S@4, taffy@parser@helpers:advance(Parser)}};
{some, {alias, Name}} ->
Parser@2 = taffy@parser@helpers:advance(Parser),
case taffy@parser@types:resolve_alias(Parser@2, Name) of
{ok, {Val, Parser@3}} ->
{ok,
{taffy@parser@scalar:value_to_key_string(Val), Parser@3}};
{error, <<"budget exceeded"/utf8>>} ->
{error,
{parse_error,
<<"Alias expansion budget exceeded (possible alias-bomb)"/utf8>>,
erlang:element(4, Parser@2)}};
{error, _} ->
{error,
{parse_error,
<<"Unknown anchor: "/utf8, Name/binary>>,
erlang:element(4, Parser@2)}}
end;
{some, {anchor, Name@1}} ->
Parser@4 = taffy@parser@helpers:advance(Parser),
gleam@result:'try'(
parse_explicit_key(Parser@4, Parse_value_fn),
fun(_use0) ->
{Key, Parser@5} = _use0,
Parser@6 = taffy@parser@types:register_anchor(
Parser@5,
Name@1,
{string, Key}
),
{ok, {Key, Parser@6}}
end
);
{some, {tag, _}} ->
Parser@7 = taffy@parser@helpers:advance(Parser),
parse_explicit_key(Parser@7, Parse_value_fn);
{some, newline} ->
parse_explicit_key_after_newline(
taffy@parser@helpers:advance(Parser),
Parser,
Parse_value_fn
);
{some, {indent, N}} ->
parse_explicit_key_after_indent(Parser, N, Parse_value_fn);
{some, colon} ->
{ok, {<<""/utf8>>, Parser}};
none ->
{ok, {<<""/utf8>>, Parser}};
{some, eof} ->
{ok, {<<""/utf8>>, Parser}};
{some, {comment, _}} ->
Parser@8 = taffy@parser@helpers:advance(Parser),
parse_explicit_key(Parser@8, Parse_value_fn);
_ ->
{ok, {<<""/utf8>>, Parser}}
end.