Current section
Files
Jump to
Current section
Files
src/chomp@lexer.erl
-module(chomp@lexer).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([simple/1, advanced/1, keep/1, drop/1, custom/1, map/2, then/2, into/2, ignore/1, token/2, symbol/3, keyword/3, string/2, identifier/4, try_identifier/4, variable/2, spaces_/1, spaces/1, whitespace/1, comment/2, run/2, run_advanced/3, float_with_separator/2, float/1, int_with_separator/2, int/1, number_with_separator/3, number/2]).
-export_type([matcher/2, match/2, token/1, error/0, lexer/2, state/1]).
-opaque matcher(FEA, FEB) :: {matcher,
fun((FEB, binary(), binary()) -> match(FEA, FEB))}.
-type match(FEC, FED) :: {keep, FEC, FED} | {skip, FED} | {drop, FED} | no_match.
-type token(FEE) :: {token, chomp@span:span(), binary(), FEE}.
-type error() :: {no_match_found, integer(), integer(), binary()}.
-opaque lexer(FEF, FEG) :: {lexer, fun((FEG) -> list(matcher(FEF, FEG)))}.
-type state(FEH) :: {state,
list(binary()),
list(token(FEH)),
{integer(), integer(), binary()},
integer(),
integer()}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 101).
-spec simple(list(matcher(FEI, nil))) -> lexer(FEI, nil).
simple(Matchers) ->
{lexer, fun(_) -> Matchers end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 109).
-spec advanced(fun((FEO) -> list(matcher(FEP, FEO)))) -> lexer(FEP, FEO).
advanced(Matchers) ->
{lexer, fun(Mode) -> Matchers(Mode) end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 123).
-spec keep(fun((binary(), binary()) -> {ok, FEV} | {error, nil})) -> matcher(FEV, any()).
keep(F) ->
{matcher, fun(Mode, Lexeme, Lookahead) -> _pipe = F(Lexeme, Lookahead),
_pipe@1 = gleam@result:map(
_pipe,
fun(_capture) -> {keep, _capture, Mode} end
),
gleam@result:unwrap(_pipe@1, no_match) end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 139).
-spec drop(fun((binary(), binary()) -> boolean())) -> matcher(any(), any()).
drop(F) ->
{matcher, fun(Mode, Lexeme, Lookahead) -> case F(Lexeme, Lookahead) of
true ->
{drop, Mode};
false ->
no_match
end end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 154).
-spec custom(fun((FFF, binary(), binary()) -> match(FFG, FFF))) -> matcher(FFG, FFF).
custom(F) ->
{matcher, F}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 161).
-spec map(matcher(FFL, FFM), fun((FFL) -> FFP)) -> matcher(FFP, FFM).
map(Matcher, F) ->
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case (erlang:element(2, Matcher))(Mode, Lexeme, Lookahead) of
{keep, Value, Mode@1} ->
{keep, F(Value), Mode@1};
{skip, Mode@2} ->
{skip, Mode@2};
{drop, Mode@3} ->
{drop, Mode@3};
no_match ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 177).
-spec then(matcher(FFS, FFT), fun((FFS) -> match(FFW, FFT))) -> matcher(FFW, FFT).
then(Matcher, F) ->
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case (erlang:element(2, Matcher))(Mode, Lexeme, Lookahead) of
{keep, Value, _} ->
F(Value);
{skip, Mode@1} ->
{skip, Mode@1};
{drop, Mode@2} ->
{drop, Mode@2};
no_match ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 195).
-spec into(matcher(FGB, FGC), fun((FGC) -> FGC)) -> matcher(FGB, FGC).
into(Matcher, F) ->
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case (erlang:element(2, Matcher))(Mode, Lexeme, Lookahead) of
{keep, Value, Mode@1} ->
{keep, Value, F(Mode@1)};
{skip, Mode@2} ->
{skip, Mode@2};
{drop, Mode@3} ->
{drop, F(Mode@3)};
no_match ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 210).
-spec ignore(matcher(any(), FGI)) -> matcher(any(), FGI).
ignore(Matcher) ->
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case (erlang:element(2, Matcher))(Mode, Lexeme, Lookahead) of
{keep, _, Mode@1} ->
{drop, Mode@1};
{skip, Mode@2} ->
{skip, Mode@2};
{drop, Mode@3} ->
{drop, Mode@3};
no_match ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 225).
-spec token(binary(), FGO) -> matcher(FGO, any()).
token(Str, Value) ->
{matcher, fun(Mode, Lexeme, _) -> case Lexeme =:= Str of
true ->
{keep, Value, Mode};
false ->
no_match
end end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 238).
-spec symbol(binary(), binary(), FGS) -> matcher(FGS, any()).
symbol(Str, Breaker, Value) ->
_assert_subject = gleam@regexp:from_string(Breaker),
{ok, Break} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"symbol"/utf8>>,
line => 239})
end,
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case (Lexeme =:= Str) andalso ((Lookahead =:= <<""/utf8>>) orelse gleam@regexp:check(
Break,
Lookahead
)) of
true ->
{keep, Value, Mode};
false ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 254).
-spec keyword(binary(), binary(), FGW) -> matcher(FGW, any()).
keyword(Str, Breaker, Value) ->
_assert_subject = gleam@regexp:from_string(Breaker),
{ok, Break} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"keyword"/utf8>>,
line => 255})
end,
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case (Lexeme =:= Str) andalso ((Lookahead =:= <<""/utf8>>) orelse gleam@regexp:check(
Break,
Lookahead
)) of
true ->
{keep, Value, Mode};
false ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 381).
-spec string(binary(), fun((binary()) -> FHY)) -> matcher(FHY, any()).
string(Char, To_value) ->
_assert_subject = gleam@regexp:from_string(
<<<<<<<<<<<<"^"/utf8, Char/binary>>/binary, "([^"/utf8>>/binary,
Char/binary>>/binary,
"\\\\]|\\\\[\\s\\S])*"/utf8>>/binary,
Char/binary>>/binary,
"$"/utf8>>
),
{ok, Is_string} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"string"/utf8>>,
line => 382})
end,
{matcher,
fun(Mode, Lexeme, _) -> case gleam@regexp:check(Is_string, Lexeme) of
true ->
_pipe = Lexeme,
_pipe@1 = gleam@string:drop_start(_pipe, 1),
_pipe@2 = gleam@string:drop_end(_pipe@1, 1),
_pipe@3 = To_value(_pipe@2),
{keep, _pipe@3, Mode};
false ->
no_match
end end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 401).
-spec identifier(
binary(),
binary(),
gleam@set:set(binary()),
fun((binary()) -> FID)
) -> matcher(FID, any()).
identifier(Start, Inner, Reserved, To_value) ->
_assert_subject = gleam@regexp:from_string(
<<<<<<"^"/utf8, Start/binary>>/binary, Inner/binary>>/binary,
"*$"/utf8>>
),
{ok, Ident} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"identifier"/utf8>>,
line => 407})
end,
_assert_subject@1 = gleam@regexp:from_string(Inner),
{ok, Inner@1} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@1,
module => <<"chomp/lexer"/utf8>>,
function => <<"identifier"/utf8>>,
line => 408})
end,
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case {gleam@regexp:check(Inner@1, Lookahead),
gleam@regexp:check(Ident, Lexeme)} of
{true, true} ->
{skip, Mode};
{false, true} ->
case gleam@set:contains(Reserved, Lexeme) of
true ->
no_match;
false ->
{keep, To_value(Lexeme), Mode}
end;
{_, _} ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 425).
-spec try_identifier(
binary(),
binary(),
gleam@set:set(binary()),
fun((binary()) -> FII)
) -> {ok, matcher(FII, any())} | {error, gleam@regexp:compile_error()}.
try_identifier(Start, Inner, Reserved, To_value) ->
gleam@result:then(
gleam@regexp:from_string(
<<<<<<"^"/utf8, Start/binary>>/binary, Inner/binary>>/binary,
"*$"/utf8>>
),
fun(Ident) ->
gleam@result:map(
gleam@regexp:from_string(Inner),
fun(Inner@1) ->
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case {gleam@regexp:check(Inner@1, Lookahead),
gleam@regexp:check(Ident, Lexeme)} of
{true, true} ->
{skip, Mode};
{false, true} ->
case gleam@set:contains(Reserved, Lexeme) of
true ->
no_match;
false ->
{keep, To_value(Lexeme), Mode}
end;
{_, _} ->
no_match
end
end}
end
)
end
).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 449).
-spec variable(gleam@set:set(binary()), fun((binary()) -> FIP)) -> matcher(FIP, any()).
variable(Reserved, To_value) ->
identifier(<<"[a-z]"/utf8>>, <<"[a-zA-Z0-9_]"/utf8>>, Reserved, To_value).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 464).
-spec spaces_(fun((binary()) -> FIX)) -> matcher(FIX, any()).
spaces_(To_value) ->
_assert_subject = gleam@regexp:from_string(<<"^[ \\t]+"/utf8>>),
{ok, Spaces} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"spaces_"/utf8>>,
line => 465})
end,
{matcher, fun(Mode, Lexeme, _) -> case gleam@regexp:check(Spaces, Lexeme) of
true ->
{keep, To_value(Lexeme), Mode};
false ->
no_match
end end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 458).
-spec spaces(FIT) -> matcher(FIT, any()).
spaces(Token) ->
spaces_(fun(_) -> Token end).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 477).
-spec whitespace(FJB) -> matcher(FJB, any()).
whitespace(Token) ->
_assert_subject = gleam@regexp:from_string(<<"^\\s+$"/utf8>>),
{ok, Whitespace} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"whitespace"/utf8>>,
line => 478})
end,
{matcher,
fun(Mode, Lexeme, _) -> case gleam@regexp:check(Whitespace, Lexeme) of
true ->
{keep, Token, Mode};
false ->
no_match
end end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 489).
-spec comment(binary(), fun((binary()) -> FJF)) -> matcher(FJF, any()).
comment(Start, To_value) ->
Drop_length = string:length(Start),
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case {gleam_stdlib:string_starts_with(Lexeme, Start), Lookahead} of
{true, <<"\n"/utf8>>} ->
_pipe = Lexeme,
_pipe@1 = gleam@string:drop_start(_pipe, Drop_length),
_pipe@2 = To_value(_pipe@1),
{keep, _pipe@2, Mode};
{true, <<""/utf8>>} ->
_pipe = Lexeme,
_pipe@1 = gleam@string:drop_start(_pipe, Drop_length),
_pipe@2 = To_value(_pipe@1),
{keep, _pipe@2, Mode};
{true, _} ->
{skip, Mode};
{false, _} ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 636).
-spec do_match(FKH, binary(), binary(), list(matcher(FKI, FKH))) -> match(FKI, FKH).
do_match(Mode, Str, Lookahead, Matchers) ->
gleam@list:fold_until(
Matchers,
no_match,
fun(_, Matcher) ->
case (erlang:element(2, Matcher))(Mode, Str, Lookahead) of
{keep, _, _} = Match ->
{stop, Match};
{skip, _} = Match@1 ->
{stop, Match@1};
{drop, _} = Match@2 ->
{stop, Match@2};
no_match ->
{continue, no_match}
end
end
).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 654).
-spec next_col(integer(), binary()) -> integer().
next_col(Col, Str) ->
case Str of
<<"\n"/utf8>> ->
1;
_ ->
Col + 1
end.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 661).
-spec next_row(integer(), binary()) -> integer().
next_row(Row, Str) ->
case Str of
<<"\n"/utf8>> ->
Row + 1;
_ ->
Row
end.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 527).
-spec do_run(lexer(FJY, FJZ), FJZ, state(FJY)) -> {ok, list(token(FJY))} |
{error, error()}.
do_run(Lexer, Mode, State) ->
Matchers = (erlang:element(2, Lexer))(Mode),
case {erlang:element(2, State), erlang:element(4, State)} of
{[], {_, _, <<""/utf8>>}} ->
{ok, lists:reverse(erlang:element(3, State))};
{[], {Start_row, Start_col, Lexeme}} ->
case do_match(Mode, Lexeme, <<""/utf8>>, Matchers) of
no_match ->
{error, {no_match_found, Start_row, Start_col, Lexeme}};
{skip, _} ->
{error, {no_match_found, Start_row, Start_col, Lexeme}};
{drop, _} ->
{ok, lists:reverse(erlang:element(3, State))};
{keep, Value, _} ->
Span = {span,
Start_row,
Start_col,
erlang:element(5, State),
erlang:element(6, State)},
Token = {token, Span, Lexeme, Value},
{ok, lists:reverse([Token | erlang:element(3, State)])}
end;
{[Lookahead | Rest], {Start_row@1, Start_col@1, Lexeme@1}} ->
Row = next_row(erlang:element(5, State), Lookahead),
Col = next_col(erlang:element(6, State), Lookahead),
case do_match(Mode, Lexeme@1, Lookahead, Matchers) of
{keep, Value@1, Mode@1} ->
Span@1 = {span,
Start_row@1,
Start_col@1,
erlang:element(5, State),
erlang:element(6, State)},
Token@1 = {token, Span@1, Lexeme@1, Value@1},
do_run(
Lexer,
Mode@1,
{state,
Rest,
[Token@1 | erlang:element(3, State)],
{erlang:element(5, State),
erlang:element(6, State),
Lookahead},
Row,
Col}
);
{skip, Mode@2} ->
do_run(
Lexer,
Mode@2,
{state,
Rest,
erlang:element(3, State),
{Start_row@1,
Start_col@1,
<<Lexeme@1/binary, Lookahead/binary>>},
Row,
Col}
);
{drop, Mode@3} ->
do_run(
Lexer,
Mode@3,
{state,
Rest,
erlang:element(3, State),
{erlang:element(5, State),
erlang:element(6, State),
Lookahead},
Row,
Col}
);
no_match ->
do_run(
Lexer,
Mode,
{state,
Rest,
erlang:element(3, State),
{Start_row@1,
Start_col@1,
<<Lexeme@1/binary, Lookahead/binary>>},
Row,
Col}
)
end
end.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 508).
-spec run(binary(), lexer(FJJ, nil)) -> {ok, list(token(FJJ))} |
{error, error()}.
run(Source, Lexer) ->
_pipe = gleam@string:to_graphemes(Source),
_pipe@1 = {state, _pipe, [], {1, 1, <<""/utf8>>}, 1, 1},
do_run(Lexer, nil, _pipe@1).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 519).
-spec run_advanced(binary(), FJQ, lexer(FJR, FJQ)) -> {ok, list(token(FJR))} |
{error, error()}.
run_advanced(Source, Mode, Lexer) ->
do_run(
Lexer,
Mode,
{state,
gleam@string:to_graphemes(Source),
[],
{1, 1, <<""/utf8>>},
1,
1}
).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 302).
-spec float_with_separator(binary(), fun((float()) -> FHM)) -> matcher(FHM, any()).
float_with_separator(Separator, To_value) ->
_assert_subject = gleam@regexp:from_string(
<<<<"[0-9"/utf8, Separator/binary>>/binary, "]"/utf8>>
),
{ok, Digit} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"float_with_separator"/utf8>>,
line => 306})
end,
_assert_subject@1 = gleam@regexp:from_string(
<<<<"^[0-9"/utf8, Separator/binary>>/binary, "]+$"/utf8>>
),
{ok, Integer} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@1,
module => <<"chomp/lexer"/utf8>>,
function => <<"float_with_separator"/utf8>>,
line => 307})
end,
_assert_subject@2 = gleam@regexp:from_string(
<<<<<<<<"^[0-9"/utf8, Separator/binary>>/binary, "]+\\.[0-9"/utf8>>/binary,
Separator/binary>>/binary,
"]+$"/utf8>>
),
{ok, Number} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@2,
module => <<"chomp/lexer"/utf8>>,
function => <<"float_with_separator"/utf8>>,
line => 308})
end,
{matcher,
fun(Mode, Lexeme, Lookahead) ->
Is_int = not gleam@regexp:check(Digit, Lookahead) andalso gleam@regexp:check(
Integer,
Lexeme
),
Is_float = not gleam@regexp:check(Digit, Lookahead) andalso gleam@regexp:check(
Number,
Lexeme
),
case Lexeme of
<<"."/utf8>> when Is_int ->
no_match;
_ when Is_float ->
_assert_subject@3 = begin
_pipe = Lexeme,
_pipe@1 = gleam@string:replace(
_pipe,
Separator,
<<""/utf8>>
),
gleam_stdlib:parse_float(_pipe@1)
end,
{ok, Num} = case _assert_subject@3 of
{ok, _} -> _assert_subject@3;
_assert_fail@3 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@3,
module => <<"chomp/lexer"/utf8>>,
function => <<"float_with_separator"/utf8>>,
line => 321})
end,
{keep, To_value(Num), Mode};
_ ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 296).
-spec float(fun((float()) -> FHI)) -> matcher(FHI, any()).
float(To_value) ->
float_with_separator(<<""/utf8>>, To_value).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 273).
-spec int_with_separator(binary(), fun((integer()) -> FHE)) -> matcher(FHE, any()).
int_with_separator(Separator, To_value) ->
_assert_subject = gleam@regexp:from_string(
<<<<"[0-9"/utf8, Separator/binary>>/binary, "]"/utf8>>
),
{ok, Digit} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"int_with_separator"/utf8>>,
line => 277})
end,
_assert_subject@1 = gleam@regexp:from_string(
<<<<"^[0-9"/utf8, Separator/binary>>/binary, "]+$"/utf8>>
),
{ok, Integer} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@1,
module => <<"chomp/lexer"/utf8>>,
function => <<"int_with_separator"/utf8>>,
line => 278})
end,
{matcher,
fun(Mode, Lexeme, Lookahead) ->
case not gleam@regexp:check(Digit, Lookahead) andalso gleam@regexp:check(
Integer,
Lexeme
) of
false ->
no_match;
true ->
_assert_subject@2 = begin
_pipe = Lexeme,
_pipe@1 = gleam@string:replace(
_pipe,
Separator,
<<""/utf8>>
),
gleam_stdlib:parse_int(_pipe@1)
end,
{ok, Num} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@2,
module => <<"chomp/lexer"/utf8>>,
function => <<"int_with_separator"/utf8>>,
line => 285})
end,
{keep, To_value(Num), Mode}
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 267).
-spec int(fun((integer()) -> FHA)) -> matcher(FHA, any()).
int(To_value) ->
int_with_separator(<<""/utf8>>, To_value).
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 339).
-spec number_with_separator(
binary(),
fun((integer()) -> FHU),
fun((float()) -> FHU)
) -> matcher(FHU, any()).
number_with_separator(Separator, From_int, From_float) ->
_assert_subject = gleam@regexp:from_string(
<<<<"[0-9"/utf8, Separator/binary>>/binary, "]"/utf8>>
),
{ok, Digit} = case _assert_subject of
{ok, _} -> _assert_subject;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail,
module => <<"chomp/lexer"/utf8>>,
function => <<"number_with_separator"/utf8>>,
line => 344})
end,
_assert_subject@1 = gleam@regexp:from_string(
<<<<"^[0-9"/utf8, Separator/binary>>/binary, "]+$"/utf8>>
),
{ok, Integer} = case _assert_subject@1 of
{ok, _} -> _assert_subject@1;
_assert_fail@1 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@1,
module => <<"chomp/lexer"/utf8>>,
function => <<"number_with_separator"/utf8>>,
line => 345})
end,
_assert_subject@2 = gleam@regexp:from_string(
<<<<<<<<"^[0-9"/utf8, Separator/binary>>/binary, "]+\\.[0-9"/utf8>>/binary,
Separator/binary>>/binary,
"]+$"/utf8>>
),
{ok, Number} = case _assert_subject@2 of
{ok, _} -> _assert_subject@2;
_assert_fail@2 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@2,
module => <<"chomp/lexer"/utf8>>,
function => <<"number_with_separator"/utf8>>,
line => 346})
end,
{matcher,
fun(Mode, Lexeme, Lookahead) ->
Is_int = not gleam@regexp:check(Digit, Lookahead) andalso gleam@regexp:check(
Integer,
Lexeme
),
Is_float = not gleam@regexp:check(Digit, Lookahead) andalso gleam@regexp:check(
Number,
Lexeme
),
case {Lexeme, Lookahead} of
{<<"."/utf8>>, _} when Is_int ->
no_match;
{_, <<"."/utf8>>} when Is_int ->
no_match;
{_, _} when Is_int ->
_assert_subject@3 = begin
_pipe = Lexeme,
_pipe@1 = gleam@string:replace(
_pipe,
Separator,
<<""/utf8>>
),
gleam_stdlib:parse_int(_pipe@1)
end,
{ok, Num} = case _assert_subject@3 of
{ok, _} -> _assert_subject@3;
_assert_fail@3 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@3,
module => <<"chomp/lexer"/utf8>>,
function => <<"number_with_separator"/utf8>>,
line => 360})
end,
{keep, From_int(Num), Mode};
{_, _} when Is_float ->
_assert_subject@4 = begin
_pipe@2 = Lexeme,
_pipe@3 = gleam@string:replace(
_pipe@2,
Separator,
<<""/utf8>>
),
gleam_stdlib:parse_float(_pipe@3)
end,
{ok, Num@1} = case _assert_subject@4 of
{ok, _} -> _assert_subject@4;
_assert_fail@4 ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
value => _assert_fail@4,
module => <<"chomp/lexer"/utf8>>,
function => <<"number_with_separator"/utf8>>,
line => 368})
end,
{keep, From_float(Num@1), Mode};
{_, _} ->
no_match
end
end}.
-file("/home/noah/Projects/gleam/chomp/src/chomp/lexer.gleam", 332).
-spec number(fun((integer()) -> FHQ), fun((float()) -> FHQ)) -> matcher(FHQ, any()).
number(From_int, From_float) ->
number_with_separator(<<""/utf8>>, From_int, From_float).