Packages

JSX-like syntax for gleam

Current section

Files

Jump to
gleamx src gleamx.erl
Raw

src/gleamx.erl

-module(gleamx).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/gleamx.gleam").
-export([main/0]).
-file("src/gleamx.gleam", 32).
-spec compile(binary()) -> nil.
compile(Path) ->
_assert_subject = <<".gleamx"/utf8>>,
case gleam_stdlib:string_ends_with(Path, _assert_subject) of
true -> nil;
false -> erlang:error(#{gleam_error => assert,
message => <<"Assertion failed."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gleamx"/utf8>>,
function => <<"compile"/utf8>>,
line => 33,
kind => function_call,
arguments => [#{kind => expression,
value => Path,
start => 755,
'end' => 759
}, #{kind => literal,
value => _assert_subject,
start => 761,
'end' => 770
}],
start => 731,
'end' => 771,
expression_start => 738})
end,
Code@1 = case simplifile:read(Path) of
{ok, Code} -> Code;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"Pattern match failed, no pattern matched the value."/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gleamx"/utf8>>,
function => <<"compile"/utf8>>,
line => 34,
value => _assert_fail,
start => 774,
'end' => 806,
pattern_start => 785,
pattern_end => 793})
end,
case gleamx@parser:parse(Code@1) of
{error, Error} ->
gleam_stdlib:println(gleamx@parser:error_to_string(Error));
{ok, Chunks} ->
case gleamx@codegen:generate(Chunks) of
{error, Error@1} ->
gleam_stdlib:println(gleamx@parser:error_to_string(Error@1));
{ok, {Code@2, _}} ->
Out_path = gleam@string:drop_end(Path, 1),
_ = simplifile:write(Out_path, Code@2),
nil
end
end.
-file("src/gleamx.gleam", 18).
-spec compile_all() -> nil.
compile_all() ->
_pipe = fswalk:builder(),
_pipe@1 = fswalk:with_path(_pipe, <<"src"/utf8>>),
_pipe@2 = fswalk:walk(_pipe@1),
_pipe@3 = gleam@yielder:map(
_pipe@2,
fun(Res) ->
Entry@1 = case Res of
{ok, Entry} -> Entry;
_assert_fail ->
erlang:error(#{gleam_error => let_assert,
message => <<"failed to walk"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gleamx"/utf8>>,
function => <<"compile_all"/utf8>>,
line => 23,
value => _assert_fail,
start => 460,
'end' => 486,
pattern_start => 471,
pattern_end => 480})
end,
Entry@1
end
),
_pipe@4 = gleam@yielder:filter(
_pipe@3,
fun(Entry@2) ->
gleam_stdlib:string_ends_with(
erlang:element(2, Entry@2),
<<".gleamx"/utf8>>
)
andalso not erlang:element(2, erlang:element(3, Entry@2))
end
),
gleam@yielder:each(
_pipe@4,
fun(Entry@3) -> compile(erlang:element(2, Entry@3)) end
).
-file("src/gleamx.gleam", 10).
-spec main() -> nil.
main() ->
case erlang:element(4, argv:load()) of
[] ->
compile_all();
[<<"compile"/utf8>>, Path] ->
compile(Path);
_ ->
erlang:error(#{gleam_error => panic,
message => <<"invalid command"/utf8>>,
file => <<?FILEPATH/utf8>>,
module => <<"gleamx"/utf8>>,
function => <<"main"/utf8>>,
line => 14})
end.