Current section
Files
Jump to
Current section
Files
src/cog.erl
-module(cog).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-export([run/1, main/0]).
-file("/Users/danielle/Repositories/Projects/cog/src/cog.gleam", 52).
-spec do_perform_actions(list(glexer@token:token()), list(glexer@token:token())) -> {ok,
list(glexer@token:token())} |
{error, simplifile:file_error()}.
do_perform_actions(Tokens, Generated) ->
case Tokens of
[] ->
{ok, Generated};
[{comment_normal, <<"cog:embed "/utf8, Path/binary>>} = T1,
{space, _} = T2,
const = T3,
{space, _} = T4,
{name, _} = T5,
{space, _} = T6,
equal = T7,
{space, _} = T8,
{string, _} |
Tokens@1] ->
gleam@result:'try'(
simplifile:read(Path),
fun(Data) ->
Codepoints = begin
_pipe = Data,
_pipe@1 = gleam@string:to_utf_codepoints(_pipe),
_pipe@2 = gleam@list:map(
_pipe@1,
fun(Codepoint) ->
<<<<"\\u{"/utf8,
(gleam@int:to_base16(
gleam_stdlib:identity(Codepoint)
))/binary>>/binary,
"}"/utf8>>
end
),
gleam@string:join(_pipe@2, <<""/utf8>>)
end,
New = begin
_pipe@3 = [T1,
T2,
T3,
T4,
T5,
T6,
T7,
T8,
{string, Codepoints}],
lists:reverse(_pipe@3)
end,
do_perform_actions(Tokens@1, lists:append(New, Generated))
end
);
[Token | Tokens@2] ->
do_perform_actions(Tokens@2, [Token | Generated])
end.
-file("/Users/danielle/Repositories/Projects/cog/src/cog.gleam", 45).
-spec perform_actions(list(glexer@token:token())) -> {ok,
list(glexer@token:token())} |
{error, simplifile:file_error()}.
perform_actions(Tokens) ->
_pipe = do_perform_actions(Tokens, []),
gleam@result:map(_pipe, fun lists:reverse/1).
-file("/Users/danielle/Repositories/Projects/cog/src/cog.gleam", 35).
-spec run(binary()) -> {ok, binary()} | {error, simplifile:file_error()}.
run(Content) ->
Tokens = begin
_pipe = glexer:new(Content),
glexer:lex(_pipe)
end,
Tokens@1 = gleam@list:map(
Tokens,
fun(Token) -> erlang:element(1, Token) end
),
gleam@result:'try'(
perform_actions(Tokens@1),
fun(Tokens@2) -> {ok, cog@glexer_printer:print(Tokens@2)} end
).
-file("/Users/danielle/Repositories/Projects/cog/src/cog.gleam", 10).
-spec main() -> {ok, nil} | {error, simplifile:file_error()}.
main() ->
gleam@result:'try'(
simplifile:get_files(<<"./src"/utf8>>),
fun(Source_files) ->
gleam@result:'try'(
simplifile:get_files(<<"./test"/utf8>>),
fun(Test_files) ->
Files = lists:append(Source_files, Test_files),
Gleam_files = gleam@list:filter(
Files,
fun(_capture) ->
gleam_stdlib:string_ends_with(
_capture,
<<".gleam"/utf8>>
)
end
),
gleam@result:'try'(
begin
_pipe = Gleam_files,
_pipe@1 = gleam@list:map(
_pipe,
fun(File) ->
gleam@result:'try'(
simplifile:read(File),
fun(Content) ->
gleam@result:'try'(
run(Content),
fun(Source) ->
simplifile:write(
File,
Source
)
end
)
end
)
end
),
gleam@result:all(_pipe@1)
end,
fun(_) -> {ok, nil} end
)
end
)
end
).