Current section
Files
Jump to
Current section
Files
src/pearl@token.erl
-module(pearl@token).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/pearl/token.gleam").
-export([sigil_delimiters/1, to_source/1]).
-export_type([token/0, sigil_delimiter/0]).
-type token() :: {whitespace, binary()} |
{comment, binary()} |
{doc_comment, binary()} |
{module_comment, binary()} |
end_of_file |
{character, binary()} |
{integer, binary()} |
{float, binary()} |
{atom, binary(), boolean()} |
{string, binary()} |
{triple_quoted_string,
gleam@option:option(binary()),
integer(),
binary(),
list(binary()),
binary()} |
{sigil, binary(), sigil_delimiter(), binary()} |
{variable, binary()} |
'after' |
'begin' |
'case' |
'catch' |
'cond' |
'else' |
'end' |
'fun' |
'if' |
'let' |
'maybe' |
'of' |
'receive' |
'try' |
'when' |
left_paren |
right_paren |
left_brace |
right_brace |
left_square |
right_square |
comma |
semicolon |
colon |
dot |
minus_greater |
double_less |
double_greater |
hash |
double_colon |
double_dot |
triple_dot |
double_pipe |
equal_greater |
colon_equal |
less_minus |
less_equal |
pipe |
double_equal |
slash_equal |
equal_less |
less |
greater_equal |
greater |
equal_colon_equal |
equal_slash_equal |
plus |
minus |
star |
slash |
'bnot' |
'div' |
'rem' |
'band' |
'bor' |
'bxor' |
'bsl' |
'bsr' |
'not' |
'and' |
'or' |
'xor' |
'andalso' |
'orelse' |
double_plus |
double_minus |
question_equal |
question |
bang |
equal |
{unknown, binary()} |
{unterminated_string, binary()} |
{unterminated_sigil, binary(), sigil_delimiter(), binary()} |
{unterminated_atom, binary()} |
{invalid_triple_quoted_string, binary()}.
-type sigil_delimiter() :: sigil_none |
sigil_paren |
sigil_square |
sigil_brace |
sigil_angle |
sigil_slash |
sigil_pipe |
sigil_single_quote |
sigil_double_quote |
sigil_backtick |
sigil_hash.
-file("src/pearl/token.gleam", 259).
-spec sigil_delimiters(sigil_delimiter()) -> {binary(), binary()}.
sigil_delimiters(Delimiter) ->
case Delimiter of
sigil_none ->
{<<""/utf8>>, <<""/utf8>>};
sigil_angle ->
{<<"<"/utf8>>, <<">"/utf8>>};
sigil_backtick ->
{<<"`"/utf8>>, <<"`"/utf8>>};
sigil_brace ->
{<<"{"/utf8>>, <<"}"/utf8>>};
sigil_double_quote ->
{<<"\""/utf8>>, <<"\""/utf8>>};
sigil_hash ->
{<<"#"/utf8>>, <<"#"/utf8>>};
sigil_paren ->
{<<"("/utf8>>, <<")"/utf8>>};
sigil_pipe ->
{<<"|"/utf8>>, <<"|"/utf8>>};
sigil_single_quote ->
{<<"'"/utf8>>, <<"'"/utf8>>};
sigil_slash ->
{<<"/"/utf8>>, <<"/"/utf8>>};
sigil_square ->
{<<"["/utf8>>, <<"]"/utf8>>}
end.
-file("src/pearl/token.gleam", 114).
-spec to_source(token()) -> binary().
to_source(Token) ->
case Token of
{whitespace, Space} ->
Space;
{comment, Contents} ->
<<"%"/utf8, Contents/binary>>;
{doc_comment, Contents@1} ->
<<"%%"/utf8, Contents@1/binary>>;
{module_comment, Contents@2} ->
<<"%%%"/utf8, Contents@2/binary>>;
end_of_file ->
<<""/utf8>>;
{character, Char} ->
<<"$"/utf8, Char/binary>>;
{integer, Int} ->
Int;
{float, Float} ->
Float;
{atom, Name, true} ->
<<<<"'"/utf8, Name/binary>>/binary, "'"/utf8>>;
{atom, Name@1, false} ->
Name@1;
{string, Contents@3} ->
<<<<"\""/utf8, Contents@3/binary>>/binary, "\""/utf8>>;
{triple_quoted_string,
Sigil,
Number_of_quotes,
Beginning_whitespace,
Lines,
End_indentation} ->
<<<<<<<<<<<<(case Sigil of
none ->
<<""/utf8>>;
{some, Sigil@1} ->
<<"~"/utf8, Sigil@1/binary>>
end)/binary, (gleam@string:repeat(
<<"\""/utf8>>,
Number_of_quotes
))/binary>>/binary, Beginning_whitespace/binary>>/binary, (gleam@string:join(
gleam@list:map(
Lines,
fun(Line) ->
<<End_indentation/binary, Line/binary>>
end
),
<<"\n"/utf8>>
))/binary>>/binary, "\n"/utf8>>/binary, End_indentation/binary>>/binary, (gleam@string:repeat(
<<"\""/utf8>>,
Number_of_quotes
))/binary>>;
{sigil, Sigil@2, Delimiter, Contents@4} ->
{Opening, Closing} = sigil_delimiters(Delimiter),
<<<<<<<<"~"/utf8, Sigil@2/binary>>/binary, Opening/binary>>/binary,
Contents@4/binary>>/binary,
Closing/binary>>;
{variable, Name@2} ->
Name@2;
'after' ->
<<"after"/utf8>>;
'begin' ->
<<"begin"/utf8>>;
'case' ->
<<"case"/utf8>>;
'catch' ->
<<"catch"/utf8>>;
'cond' ->
<<"cond"/utf8>>;
'else' ->
<<"else"/utf8>>;
'end' ->
<<"end"/utf8>>;
'fun' ->
<<"fun"/utf8>>;
'if' ->
<<"if"/utf8>>;
'let' ->
<<"let"/utf8>>;
'maybe' ->
<<"maybe"/utf8>>;
'of' ->
<<"of"/utf8>>;
'receive' ->
<<"receive"/utf8>>;
'try' ->
<<"try"/utf8>>;
'when' ->
<<"when"/utf8>>;
left_paren ->
<<"("/utf8>>;
right_paren ->
<<")"/utf8>>;
left_brace ->
<<"{"/utf8>>;
right_brace ->
<<"}"/utf8>>;
left_square ->
<<"["/utf8>>;
right_square ->
<<"]"/utf8>>;
comma ->
<<","/utf8>>;
semicolon ->
<<";"/utf8>>;
colon ->
<<":"/utf8>>;
dot ->
<<"."/utf8>>;
minus_greater ->
<<"->"/utf8>>;
double_less ->
<<"<<"/utf8>>;
double_greater ->
<<">>"/utf8>>;
hash ->
<<"#"/utf8>>;
double_colon ->
<<"::"/utf8>>;
double_dot ->
<<".."/utf8>>;
triple_dot ->
<<"..."/utf8>>;
double_pipe ->
<<"||"/utf8>>;
equal_greater ->
<<"=>"/utf8>>;
colon_equal ->
<<":="/utf8>>;
less_minus ->
<<"<-"/utf8>>;
less_equal ->
<<"<="/utf8>>;
pipe ->
<<"|"/utf8>>;
double_equal ->
<<"=="/utf8>>;
slash_equal ->
<<"/="/utf8>>;
equal_less ->
<<"=<"/utf8>>;
less ->
<<"<"/utf8>>;
greater_equal ->
<<">="/utf8>>;
greater ->
<<">"/utf8>>;
equal_colon_equal ->
<<"=:="/utf8>>;
equal_slash_equal ->
<<"=/="/utf8>>;
plus ->
<<"+"/utf8>>;
minus ->
<<"-"/utf8>>;
star ->
<<"*"/utf8>>;
slash ->
<<"/"/utf8>>;
'bnot' ->
<<"bnot"/utf8>>;
'div' ->
<<"div"/utf8>>;
'rem' ->
<<"rem"/utf8>>;
'band' ->
<<"band"/utf8>>;
'bor' ->
<<"bor"/utf8>>;
'bxor' ->
<<"bxor"/utf8>>;
'bsl' ->
<<"bsl"/utf8>>;
'bsr' ->
<<"bsr"/utf8>>;
'not' ->
<<"not"/utf8>>;
'and' ->
<<"and"/utf8>>;
'or' ->
<<"or"/utf8>>;
'xor' ->
<<"xor"/utf8>>;
'andalso' ->
<<"andalso"/utf8>>;
'orelse' ->
<<"orelse"/utf8>>;
double_plus ->
<<"++"/utf8>>;
double_minus ->
<<"--"/utf8>>;
question_equal ->
<<"?="/utf8>>;
question ->
<<"?"/utf8>>;
bang ->
<<"!"/utf8>>;
equal ->
<<"="/utf8>>;
{unknown, Char@1} ->
Char@1;
{unterminated_string, Contents@5} ->
<<"\""/utf8, Contents@5/binary>>;
{unterminated_sigil, Sigil@3, Delimiter@1, Contents@6} ->
{Opening@1, _} = sigil_delimiters(Delimiter@1),
<<<<<<"~"/utf8, Sigil@3/binary>>/binary, Opening@1/binary>>/binary,
Contents@6/binary>>;
{unterminated_atom, Contents@7} ->
<<"'"/utf8, Contents@7/binary>>;
{invalid_triple_quoted_string, Contents@8} ->
<<<<"\"\"\""/utf8, Contents@8/binary>>/binary, "\"\"\""/utf8>>
end.