Current section
Files
Jump to
Current section
Files
src/pathern@internal@parser.erl
-module(pathern@internal@parser).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([parse/2]).
-file("/home/ram/code/gleam/pathern/src/pathern/internal/parser.gleam", 58).
-spec parse_param(binary(), binary()) -> binary().
parse_param(Path, Accum) ->
case gleam@string:first(Path) of
{ok, Grapheme} ->
case Grapheme of
<<"/"/utf8>> ->
Accum;
_ ->
parse_param(
gleam@string:drop_start(Path, 1),
<<Accum/binary, Grapheme/binary>>
)
end;
{error, _} ->
Accum
end.
-file("/home/ram/code/gleam/pathern/src/pathern/internal/parser.gleam", 34).
-spec parse_token(
pathern@internal@lexer:token(),
binary(),
gleam@dict:dict(binary(), binary())
) -> {ok, {gleam@dict:dict(binary(), binary()), binary()}} | {error, nil}.
parse_token(Token, Path, Params) ->
case erlang:element(2, Token) of
slash ->
case gleam@string:slice(Path, 0, erlang:element(4, Token)) of
<<""/utf8>> ->
{error, nil};
Val ->
case Val =:= erlang:element(5, Token) of
true ->
{ok,
{Params,
gleam@string:drop_start(
Path,
erlang:element(4, Token)
)}};
false ->
{error, nil}
end
end;
literal ->
case gleam@string:slice(Path, 0, erlang:element(4, Token)) of
<<""/utf8>> ->
{error, nil};
Val ->
case Val =:= erlang:element(5, Token) of
true ->
{ok,
{Params,
gleam@string:drop_start(
Path,
erlang:element(4, Token)
)}};
false ->
{error, nil}
end
end;
param ->
Param = parse_param(Path, <<""/utf8>>),
Params@1 = gleam@dict:insert(
Params,
erlang:element(5, Token),
Param
),
{ok,
{Params@1, gleam@string:drop_start(Path, string:length(Param))}};
_ ->
{error, nil}
end.
-file("/home/ram/code/gleam/pathern/src/pathern/internal/parser.gleam", 13).
-spec parse_tokens(
list(pathern@internal@lexer:token()),
binary(),
gleam@dict:dict(binary(), binary())
) -> {ok, gleam@dict:dict(binary(), binary())} | {error, nil}.
parse_tokens(Tokens, Path, Params) ->
case Tokens of
[Head | Rest] ->
case parse_token(Head, Path, Params) of
{ok, {Params@1, New_path}} ->
parse_tokens(Rest, New_path, Params@1);
{error, _} ->
{error, nil}
end;
[] ->
case gleam@string:is_empty(Path) of
true ->
{ok, Params};
false ->
{error, nil}
end
end.
-file("/home/ram/code/gleam/pathern/src/pathern/internal/parser.gleam", 5).
-spec parse(binary(), list(pathern@internal@lexer:token())) -> {ok,
gleam@dict:dict(binary(), binary())} |
{error, nil}.
parse(Path, Tokens) ->
Params = maps:new(),
parse_tokens(Tokens, Path, Params).