-module(parser_gleam@char). -compile(no_auto_import). -export([char/1, not_char/1, one_of/1, not_one_of/1, many/1, many1/1, digit/0, space/0, alphanum/0, letter/0, unicode_letter/0, upper/0, lower/0, not_digit/0, not_space/0, not_alphanum/0, not_letter/0, not_upper/0, not_lower/0]). -spec maybe() -> fun((fun((parser_gleam@stream:stream(GJP)) -> {ok, parser_gleam@parse_result:parse_success(GJP, binary())} | {error, parser_gleam@parse_result:parse_error(GJP)})) -> fun((parser_gleam@stream:stream(GJP)) -> {ok, parser_gleam@parse_result:parse_success(GJP, binary())} | {error, parser_gleam@parse_result:parse_error(GJP)})). maybe() -> parser_gleam@parser:maybe(fp_gl@fstring:monoid()). -spec char(binary()) -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). char(C) -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun(S) -> S =:= C end), gleam@string:concat([<<"\""/utf8>>, C, <<"\""/utf8>>]) ). -spec not_char(binary()) -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_char(C) -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun(S) -> S /= C end), gleam@string:concat([<<"anything but \""/utf8>>, C, <<"\""/utf8>>]) ). -spec is_one_of(binary(), binary()) -> boolean(). is_one_of(S, C) -> _pipe = S, gleam@string:contains(_pipe, C). -spec one_of(binary()) -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). one_of(S) -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun(C) -> is_one_of(S, C) end), gleam@string:concat([<<"One of \""/utf8>>, S, <<"\""/utf8>>]) ). -spec not_one_of(binary()) -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_one_of(S) -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun(C) -> not is_one_of(S, C) end), gleam@string:concat([<<"Not one of \""/utf8>>, S, <<"\""/utf8>>]) ). -spec many( fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}) ) -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). many(Parser) -> (maybe())(many1(Parser)). -spec many1( fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}) ) -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). many1(Parser) -> _pipe = parser_gleam@parser:many1(Parser), parser_gleam@parser:map( _pipe, fun(Nea) -> _pipe@1 = Nea, _pipe@2 = fp_gl@non_empty_list:to_list(_pipe@1), gleam@string:join(_pipe@2, <<""/utf8>>) end ). -spec is_digit(binary()) -> boolean(). is_digit(C) -> _pipe = <<"0123456789"/utf8>>, gleam@string:contains(_pipe, C). -spec digit() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). digit() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun is_digit/1), <<"a digit"/utf8>> ). -spec is_space(binary()) -> boolean(). is_space(C) -> {ok, Re@1} = case gleam@regex:from_string(<<"^\\s$"/utf8>>) of {ok, Re} -> {ok, Re}; _try -> erlang:error(#{gleam_error => assert, message => <<"Assertion pattern match failed"/utf8>>, value => _try, module => <<"parser_gleam/char"/utf8>>, function => <<"is_space"/utf8>>, line => 91}) end, gleam@regex:check(Re@1, C). -spec space() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). space() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun is_space/1), <<"a whitespace"/utf8>> ). -spec is_underscore(binary()) -> boolean(). is_underscore(C) -> C =:= <<"_"/utf8>>. -spec is_letter(binary()) -> boolean(). is_letter(C) -> {ok, Re@1} = case gleam@regex:from_string(<<"[a-z]"/utf8>>) of {ok, Re} -> {ok, Re}; _try -> erlang:error(#{gleam_error => assert, message => <<"Assertion pattern match failed"/utf8>>, value => _try, module => <<"parser_gleam/char"/utf8>>, function => <<"is_letter"/utf8>>, line => 105}) end, gleam@regex:check( Re@1, begin _pipe = C, gleam@string:lowercase(_pipe) end ). -spec is_alphanum(binary()) -> boolean(). is_alphanum(C) -> (is_letter(C) orelse is_digit(C)) orelse is_underscore(C). -spec alphanum() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). alphanum() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun is_alphanum/1), <<"a word character"/utf8>> ). -spec letter() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). letter() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun is_letter/1), <<"a letter"/utf8>> ). -spec is_unicode_letter(binary()) -> boolean(). is_unicode_letter(C) -> gleam@string:lowercase(C) /= gleam@string:uppercase(C). -spec unicode_letter() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). unicode_letter() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun is_unicode_letter/1), <<"an unicode letter"/utf8>> ). -spec is_upper(binary()) -> boolean(). is_upper(C) -> is_letter(C) andalso (C =:= gleam@string:uppercase(C)). -spec upper() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). upper() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun is_upper/1), <<"an upper case letter"/utf8>> ). -spec is_lower(binary()) -> boolean(). is_lower(C) -> is_letter(C) andalso (C =:= gleam@string:lowercase(C)). -spec lower() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). lower() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fun is_lower/1), <<"a lower case letter"/utf8>> ). -spec not_digit() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_digit() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fp_gl@predicate:'not'(fun is_digit/1)), <<"a non-digit"/utf8>> ). -spec not_space() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_space() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fp_gl@predicate:'not'(fun is_space/1)), <<"a non-whitespace character"/utf8>> ). -spec not_alphanum() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_alphanum() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fp_gl@predicate:'not'(fun is_alphanum/1)), <<"a non-word character"/utf8>> ). -spec not_letter() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_letter() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fp_gl@predicate:'not'(fun is_letter/1)), <<"a non-letter character"/utf8>> ). -spec not_upper() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_upper() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fp_gl@predicate:'not'(fun is_upper/1)), <<"anything but an upper case letter"/utf8>> ). -spec not_lower() -> fun((parser_gleam@stream:stream(binary())) -> {ok, parser_gleam@parse_result:parse_success(binary(), binary())} | {error, parser_gleam@parse_result:parse_error(binary())}). not_lower() -> parser_gleam@parser:expected( parser_gleam@parser:sat(fp_gl@predicate:'not'(fun is_lower/1)), <<"anything but a lower case letter"/utf8>> ).