Current section
Files
Jump to
Current section
Files
src/sketch_css@module@exposings.erl
-module(sketch_css@module@exposings).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch]).
-define(FILEPATH, "src/sketch_css/module/exposings.gleam").
-export([rewrite/1]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
?MODULEDOC(false).
-file("src/sketch_css/module/exposings.gleam", 32).
?DOC(false).
-spec add_qualified_import(binary()) -> fun((list({binary(),
gleam@option:option({binary(), binary()})}), glance:unqualified_import()) -> list({binary(),
gleam@option:option({binary(), binary()})})).
add_qualified_import(Module) ->
fun(Env, Import_) -> _pipe = erlang:element(3, Import_),
_pipe@1 = gleam@option:unwrap(_pipe, erlang:element(2, Import_)),
_pipe@2 = gleam@pair:new(
_pipe@1,
{some, {Module, erlang:element(2, Import_)}}
),
gleam@list:prepend(Env, _pipe@2) end.
-file("src/sketch_css/module/exposings.gleam", 24).
?DOC(false).
-spec init_environment(list(glance:definition(glance:import()))) -> list({binary(),
gleam@option:option({binary(), binary()})}).
init_environment(Imports) ->
gleam@list:fold(
Imports,
[],
fun(Env, Import_) ->
Import_@1 = erlang:element(3, Import_),
{import, Module, _, Unqualified_types, Unqualified_values} = Import_@1,
_pipe = gleam@list:fold(
Unqualified_values,
Env,
add_qualified_import(Module)
),
gleam@list:fold(
Unqualified_types,
_pipe,
add_qualified_import(Module)
)
end
).
-file("src/sketch_css/module/exposings.gleam", 106).
?DOC(false).
-spec replace_module(
binary(),
list({binary(), gleam@option:option({binary(), binary()})})
) -> gleam@option:option(binary()).
replace_module(Name, Env) ->
_pipe = gleam@list:key_find(Env, Name),
_pipe@1 = gleam@result:unwrap(_pipe, none),
gleam@option:map(_pipe@1, fun gleam@pair:first/1).
-file("src/sketch_css/module/exposings.gleam", 114).
?DOC(false).
-spec replace_name(
binary(),
list({binary(), gleam@option:option({binary(), binary()})})
) -> binary().
replace_name(Name, Env) ->
_pipe = gleam@list:key_find(Env, Name),
_pipe@1 = gleam@result:unwrap(_pipe, none),
_pipe@2 = gleam@option:map(_pipe@1, fun gleam@pair:second/1),
gleam@option:unwrap(_pipe@2, Name).
-file("src/sketch_css/module/exposings.gleam", 130).
?DOC(false).
-spec rewrite_type(
glance:type(),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:type().
rewrite_type(Type_, Env) ->
case Type_ of
{tuple_type, _} ->
Elements = gleam@list:map(
erlang:element(2, Type_),
fun(_capture) -> rewrite_type(_capture, Env) end
),
{tuple_type, Elements};
{named_type, Name, none, _} ->
Module = replace_module(Name, Env),
Name@1 = replace_name(Name, Env),
Parameters = gleam@list:map(
erlang:element(4, Type_),
fun(_capture@1) -> rewrite_type(_capture@1, Env) end
),
{named_type, Name@1, Module, Parameters};
{function_type, _, _} ->
Parameters@1 = gleam@list:map(
erlang:element(2, Type_),
fun(_capture@2) -> rewrite_type(_capture@2, Env) end
),
Return = rewrite_type(erlang:element(3, Type_), Env),
{function_type, Parameters@1, Return};
_ ->
Type_
end.
-file("src/sketch_css/module/exposings.gleam", 74).
?DOC(false).
-spec rewrite_custom_type(
glance:definition(glance:custom_type()),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:definition(glance:custom_type()).
rewrite_custom_type(Custom_type, Env) ->
{definition, Attributes, Definition} = Custom_type,
{definition,
Attributes,
begin
_record = Definition,
{custom_type,
erlang:element(2, _record),
erlang:element(3, _record),
erlang:element(4, _record),
erlang:element(5, _record),
begin
gleam@list:map(
erlang:element(6, Definition),
fun(Variant) -> _record@1 = Variant,
{variant,
erlang:element(2, _record@1),
begin
gleam@list:map(
erlang:element(3, Variant),
fun(Field) ->
Item = rewrite_type(
erlang:element(2, Field),
Env
),
case Field of
{labelled_variant_field, _, _} ->
_record@2 = Field,
{labelled_variant_field,
Item,
erlang:element(
3,
_record@2
)};
{unlabelled_variant_field, _} ->
{unlabelled_variant_field,
Item}
end
end
)
end} end
)
end}
end}.
-file("src/sketch_css/module/exposings.gleam", 94).
?DOC(false).
-spec rewrite_type_alias(
glance:definition(glance:type_alias()),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:definition(glance:type_alias()).
rewrite_type_alias(Type_alias, Env) ->
{definition, Attributes, Definition} = Type_alias,
{definition,
Attributes,
begin
Aliased = rewrite_type(erlang:element(5, Definition), Env),
_record = Definition,
{type_alias,
erlang:element(2, _record),
erlang:element(3, _record),
erlang:element(4, _record),
Aliased}
end}.
-file("src/sketch_css/module/exposings.gleam", 121).
?DOC(false).
-spec rewrite_parameters(
glance:function_parameter(),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:function_parameter().
rewrite_parameters(Parameter, Env) ->
Rewrite_type = fun(_capture) -> rewrite_type(_capture, Env) end,
Type_ = gleam@option:map(erlang:element(4, Parameter), Rewrite_type),
_record = Parameter,
{function_parameter,
erlang:element(2, _record),
erlang:element(3, _record),
Type_}.
-file("src/sketch_css/module/exposings.gleam", 154).
?DOC(false).
-spec rewrite_statement(
{list(glance:statement()),
list({binary(), gleam@option:option({binary(), binary()})})},
glance:statement()
) -> {list(glance:statement()),
list({binary(), gleam@option:option({binary(), binary()})})}.
rewrite_statement(Acc, Stat) ->
{Stats, Env} = Acc,
case Stat of
{expression, Expr} ->
Expr@1 = rewrite_expr(Expr, Env),
Stat@1 = {expression, Expr@1},
{[Stat@1 | Stats], Env};
{use, _, _} ->
Function = rewrite_expr(erlang:element(3, Stat), Env),
Stat@2 = begin
_record = Stat,
{use, erlang:element(2, _record), Function}
end,
{[Stat@2 | Stats], Env};
{assignment, _, _, _, _} ->
{Pattern, Env@1} = rewrite_pattern(erlang:element(3, Stat), Env),
Annotation = gleam@option:map(
erlang:element(4, Stat),
fun(_capture) -> rewrite_type(_capture, Env@1) end
),
Value = rewrite_expr(erlang:element(5, Stat), Env@1),
Stat@3 = begin
_record@1 = Stat,
{assignment,
erlang:element(2, _record@1),
Pattern,
Annotation,
Value}
end,
{[Stat@3 | Stats], Env@1}
end.
-file("src/sketch_css/module/exposings.gleam", 307).
?DOC(false).
-spec rewrite_expr(
glance:expression(),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:expression().
rewrite_expr(Expr, Env) ->
case Expr of
{negate_int, Expr@1} ->
{negate_int, rewrite_expr(Expr@1, Env)};
{negate_bool, Expr@2} ->
{negate_bool, rewrite_expr(Expr@2, Env)};
{panic, Expr@3} ->
{panic,
gleam@option:map(
Expr@3,
fun(_capture) -> rewrite_expr(_capture, Env) end
)};
{todo, Expr@4} ->
{todo,
gleam@option:map(
Expr@4,
fun(_capture@1) -> rewrite_expr(_capture@1, Env) end
)};
{tuple, Exprs} ->
{tuple,
gleam@list:map(
Exprs,
fun(_capture@2) -> rewrite_expr(_capture@2, Env) end
)};
{tuple_index, _, _} ->
_record = Expr,
{tuple_index,
rewrite_expr(erlang:element(2, Expr), Env),
erlang:element(3, _record)};
{variable, Var} ->
_pipe = gleam@list:key_find(Env, Var),
_pipe@1 = gleam@result:unwrap(_pipe, none),
_pipe@2 = gleam@option:map(
_pipe@1,
fun(Found) ->
{Module, Label} = Found,
Container = {variable, Module},
{field_access, Container, Label}
end
),
gleam@option:unwrap(_pipe@2, {variable, Var});
{block, Stats} ->
_pipe@3 = gleam@list:fold(Stats, {[], Env}, fun rewrite_statement/2),
_pipe@4 = gleam@pair:first(_pipe@3),
_pipe@5 = lists:reverse(_pipe@4),
{block, _pipe@5};
{fn, Arguments, Return_annotation, Body} ->
Rewrite_type = fun(_capture@3) -> rewrite_type(_capture@3, Env) end,
Return_annotation@1 = gleam@option:map(
Return_annotation,
Rewrite_type
),
Body@1 = rewrite_function_body(Body, Env),
{fn,
begin
gleam@list:map(
Arguments,
fun(Argument) ->
Type_ = gleam@option:map(
erlang:element(3, Argument),
Rewrite_type
),
_record@1 = Argument,
{fn_parameter, erlang:element(2, _record@1), Type_}
end
)
end,
Return_annotation@1,
Body@1};
{list, _, _} ->
Elements = gleam@list:map(
erlang:element(2, Expr),
fun(_capture@4) -> rewrite_expr(_capture@4, Env) end
),
Rest = gleam@option:map(
erlang:element(3, Expr),
fun(_capture@5) -> rewrite_expr(_capture@5, Env) end
),
{list, Elements, Rest};
{record_update, _, _, _, _} ->
Record = rewrite_expr(erlang:element(4, Expr), Env),
Expr@5 = begin
_record@2 = Expr,
{record_update,
erlang:element(2, _record@2),
erlang:element(3, _record@2),
Record,
begin
gleam@list:map(
erlang:element(5, Expr),
fun(Field) ->
Item = gleam@option:map(
erlang:element(3, Field),
fun(_capture@6) ->
rewrite_expr(_capture@6, Env)
end
),
_record@3 = Field,
{record_update_field,
erlang:element(2, _record@3),
Item}
end
)
end}
end,
case erlang:element(2, Expr@5) of
{some, _} ->
Expr@5;
none ->
Constructor = replace_name(erlang:element(3, Expr@5), Env),
Module@1 = replace_module(erlang:element(3, Expr@5), Env),
_record@4 = Expr@5,
{record_update,
Module@1,
Constructor,
erlang:element(4, _record@4),
erlang:element(5, _record@4)}
end;
{field_access, _, _} ->
Container@1 = rewrite_expr(erlang:element(2, Expr), Env),
_record@5 = Expr,
{field_access, Container@1, erlang:element(3, _record@5)};
{call, _, _} ->
Rewrite_expr_field = fun(_capture@7) ->
rewrite_expr_field(_capture@7, Env)
end,
Function = rewrite_expr(erlang:element(2, Expr), Env),
Arguments@1 = gleam@list:map(
erlang:element(3, Expr),
Rewrite_expr_field
),
{call, Function, Arguments@1};
{fn_capture, _, Function@1, Arguments_before, Arguments_after} ->
Rewrite_expr_field@1 = fun(_capture@8) ->
rewrite_expr_field(_capture@8, Env)
end,
Function@2 = rewrite_expr(Function@1, Env),
Arguments_before@1 = gleam@list:map(
Arguments_before,
Rewrite_expr_field@1
),
Arguments_after@1 = gleam@list:map(
Arguments_after,
Rewrite_expr_field@1
),
_record@6 = Expr,
{fn_capture,
erlang:element(2, _record@6),
Function@2,
Arguments_before@1,
Arguments_after@1};
{bit_string, Segments} ->
Rewrite_expr = fun(_capture@9) -> rewrite_expr(_capture@9, Env) end,
{bit_string,
begin
gleam@list:map(
Segments,
fun(_use0) ->
{Expr@6, Segments@1} = _use0,
{Rewrite_expr(Expr@6),
begin
gleam@list:map(
Segments@1,
fun(Segment) -> case Segment of
{size_value_option, Expr@7} ->
{size_value_option,
Rewrite_expr(Expr@7)};
_ ->
Segment
end end
)
end}
end
)
end};
{'case', Subjects, Clauses} ->
Subjects@1 = gleam@list:map(
Subjects,
fun(_capture@10) -> rewrite_expr(_capture@10, Env) end
),
{'case',
Subjects@1,
begin
gleam@list:map(
Clauses,
fun(_use0@1) ->
{clause, Patterns, Guard, Body@2} = _use0@1,
{Patterns@1, Env@1} = rewrite_nested_patterns(
Patterns,
Env
),
Guard@1 = gleam@option:map(
Guard,
fun(_capture@11) ->
rewrite_expr(_capture@11, Env@1)
end
),
Body@3 = rewrite_expr(Body@2, Env@1),
{clause, Patterns@1, Guard@1, Body@3}
end
)
end};
{binary_operator, Name, Left, Right} ->
Left@1 = rewrite_expr(Left, Env),
Right@1 = rewrite_expr(Right, Env),
{binary_operator, Name, Left@1, Right@1};
_ ->
Expr
end.
-file("src/sketch_css/module/exposings.gleam", 55).
?DOC(false).
-spec rewrite_function_body(
list(glance:statement()),
list({binary(), gleam@option:option({binary(), binary()})})
) -> list(glance:statement()).
rewrite_function_body(Body, Env) ->
_pipe = gleam@list:fold(Body, {[], Env}, fun rewrite_statement/2),
_pipe@1 = gleam@pair:first(_pipe),
lists:reverse(_pipe@1).
-file("src/sketch_css/module/exposings.gleam", 41).
?DOC(false).
-spec rewrite_function(
glance:definition(glance:function_()),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:definition(glance:function_()).
rewrite_function(Function, Env) ->
{definition, Attributes, Definition} = Function,
{definition,
Attributes,
begin
{function, _, _, Parameters, Return, Body, _} = Definition,
Parameters@1 = gleam@list:map(
Parameters,
fun(_capture) -> rewrite_parameters(_capture, Env) end
),
Return@1 = gleam@option:map(
Return,
fun(_capture@1) -> rewrite_type(_capture@1, Env) end
),
Body@1 = rewrite_function_body(Body, Env),
_record = Definition,
{function,
erlang:element(2, _record),
erlang:element(3, _record),
Parameters@1,
Return@1,
Body@1,
erlang:element(7, _record)}
end}.
-file("src/sketch_css/module/exposings.gleam", 61).
?DOC(false).
-spec rewrite_constant(
glance:definition(glance:constant()),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:definition(glance:constant()).
rewrite_constant(Constant, Env) ->
{definition, Attributes, Definition} = Constant,
{definition,
Attributes,
begin
{constant, _, _, Annotation, Value} = Definition,
Annotation@1 = gleam@option:map(
Annotation,
fun(_capture) -> rewrite_type(_capture, Env) end
),
Value@1 = rewrite_expr(Value, Env),
_record = Definition,
{constant,
erlang:element(2, _record),
erlang:element(3, _record),
Annotation@1,
Value@1}
end}.
-file("src/sketch_css/module/exposings.gleam", 15).
?DOC(false).
-spec rewrite(glance:module_()) -> glance:module_().
rewrite(Mod) ->
Env = init_environment(erlang:element(2, Mod)),
Type_aliases = gleam@list:map(
erlang:element(4, Mod),
fun(_capture) -> rewrite_type_alias(_capture, Env) end
),
Custom_types = gleam@list:map(
erlang:element(3, Mod),
fun(_capture@1) -> rewrite_custom_type(_capture@1, Env) end
),
Constants = gleam@list:map(
erlang:element(5, Mod),
fun(_capture@2) -> rewrite_constant(_capture@2, Env) end
),
Functions = gleam@list:map(
erlang:element(6, Mod),
fun(_capture@3) -> rewrite_function(_capture@3, Env) end
),
_record = Mod,
{module,
erlang:element(2, _record),
Custom_types,
Type_aliases,
Constants,
Functions}.
-file("src/sketch_css/module/exposings.gleam", 293).
?DOC(false).
-spec rewrite_expr_field(
glance:field(glance:expression()),
list({binary(), gleam@option:option({binary(), binary()})})
) -> glance:field(glance:expression()).
rewrite_expr_field(Field, Env) ->
case Field of
{unlabelled_field, Item} ->
{unlabelled_field, rewrite_expr(Item, Env)};
{shorthand_field, Label} ->
{shorthand_field, Label};
{labelled_field, _, Item@1} ->
Item@2 = rewrite_expr(Item@1, Env),
_record = Field,
{labelled_field, erlang:element(2, _record), Item@2}
end.
-file("src/sketch_css/module/exposings.gleam", 237).
?DOC(false).
-spec rewrite_bitstring_segments_pattern(
list(glance:bit_string_segment_option(glance:pattern())),
list({binary(), gleam@option:option({binary(), binary()})})
) -> {list(glance:bit_string_segment_option(glance:pattern())),
list({binary(), gleam@option:option({binary(), binary()})})}.
rewrite_bitstring_segments_pattern(Segments, Env) ->
_pipe = gleam@list:fold(
Segments,
{[], Env},
fun(Acc, Segment) ->
{Segments@1, Env@1} = Acc,
case Segment of
{size_value_option, Type_} ->
{Type_@1, Env@2} = rewrite_pattern(Type_, Env@1),
Segment@1 = {size_value_option, Type_@1},
{[Segment@1 | Segments@1], Env@2};
_ ->
{[Segment | Segments@1], Env@1}
end
end
),
gleam@pair:map_first(_pipe, fun lists:reverse/1).
-file("src/sketch_css/module/exposings.gleam", 182).
?DOC(false).
-spec rewrite_pattern(
glance:pattern(),
list({binary(), gleam@option:option({binary(), binary()})})
) -> {glance:pattern(),
list({binary(), gleam@option:option({binary(), binary()})})}.
rewrite_pattern(Pattern, Env) ->
case Pattern of
{pattern_variable, Name} ->
_pipe = {Name, none},
_pipe@1 = gleam@list:prepend(Env, _pipe),
gleam@pair:new({pattern_variable, Name}, _pipe@1);
{pattern_tuple, Elems} ->
_pipe@2 = rewrite_patterns(Elems, Env),
gleam@pair:map_first(
_pipe@2,
fun(Field@0) -> {pattern_tuple, Field@0} end
);
{pattern_list, Elements, Tail} ->
{Elements@1, Env@1} = rewrite_patterns(Elements, Env),
{Tail@2, Env@2} = case Tail of
none ->
{none, Env@1};
{some, Tail@1} ->
_pipe@3 = rewrite_pattern(Tail@1, Env@1),
gleam@pair:map_first(
_pipe@3,
fun(Field@0) -> {some, Field@0} end
)
end,
{{pattern_list, Elements@1, Tail@2}, Env@2};
{pattern_bit_string, Segments} ->
_pipe@4 = gleam@list:fold(
Segments,
{[], Env},
fun(Acc, Segment) ->
{Exprs, Env@3} = Acc,
{Pattern@1, Segments@1} = Segment,
{Pattern@2, Env@4} = rewrite_pattern(Pattern@1, Env@3),
{Segments@2, Env@5} = rewrite_bitstring_segments_pattern(
Segments@1,
Env@4
),
{[{Pattern@2, Segments@2} | Exprs], Env@5}
end
),
_pipe@5 = gleam@pair:map_first(_pipe@4, fun lists:reverse/1),
gleam@pair:map_first(
_pipe@5,
fun(Field@0) -> {pattern_bit_string, Field@0} end
);
{pattern_concatenate, Left, {named, Name@1} = Right} ->
Env@6 = [{Name@1, none} | Env],
{{pattern_concatenate, Left, Right}, Env@6};
{pattern_constructor, _, Constructor, Arguments, _} ->
Module = replace_module(Constructor, Env),
Constructor@1 = replace_name(Constructor, Env),
{Arguments@1, Env@7} = rewrite_pattern_fields(Arguments, Env),
{begin
_record = Pattern,
{pattern_constructor,
Module,
Constructor@1,
Arguments@1,
erlang:element(5, _record)}
end,
Env@7};
_ ->
{Pattern, Env}
end.
-file("src/sketch_css/module/exposings.gleam", 255).
?DOC(false).
-spec rewrite_patterns(
list(glance:pattern()),
list({binary(), gleam@option:option({binary(), binary()})})
) -> {list(glance:pattern()),
list({binary(), gleam@option:option({binary(), binary()})})}.
rewrite_patterns(Elems, Env) ->
_pipe@1 = gleam@list:fold(
Elems,
{[], Env},
fun(Elems@1, Elem) ->
{Elems@2, Env@1} = Elems@1,
_pipe = rewrite_pattern(Elem, Env@1),
gleam@pair:map_first(
_pipe,
fun(_capture) -> gleam@list:prepend(Elems@2, _capture) end
)
end
),
gleam@pair:map_first(_pipe@1, fun lists:reverse/1).
-file("src/sketch_css/module/exposings.gleam", 264).
?DOC(false).
-spec rewrite_pattern_fields(
list(glance:field(glance:pattern())),
list({binary(), gleam@option:option({binary(), binary()})})
) -> {list(glance:field(glance:pattern())),
list({binary(), gleam@option:option({binary(), binary()})})}.
rewrite_pattern_fields(Arguments, Env) ->
_pipe@2 = gleam@list:fold(
Arguments,
{[], Env},
fun(Acc, Argument) ->
{Exprs, Env@1} = Acc,
case Argument of
{shorthand_field, Label} ->
_pipe = {Label, none},
_pipe@1 = gleam@list:prepend(Env@1, _pipe),
gleam@pair:new([Argument | Exprs], _pipe@1);
{unlabelled_field, Item} ->
{Item@1, Env@2} = rewrite_pattern(Item, Env@1),
Field = {unlabelled_field, Item@1},
{[Field | Exprs], Env@2};
{labelled_field, _, Item@2} ->
{Item@3, Env@3} = rewrite_pattern(Item@2, Env@1),
Field@1 = begin
_record = Argument,
{labelled_field, erlang:element(2, _record), Item@3}
end,
{[Field@1 | Exprs], Env@3}
end
end
),
gleam@pair:map_first(_pipe@2, fun lists:reverse/1).
-file("src/sketch_css/module/exposings.gleam", 425).
?DOC(false).
-spec rewrite_nested_patterns(
list(list(glance:pattern())),
list({binary(), gleam@option:option({binary(), binary()})})
) -> {list(list(glance:pattern())),
list({binary(), gleam@option:option({binary(), binary()})})}.
rewrite_nested_patterns(Patterns, Env) ->
_pipe@1 = gleam@list:fold(
Patterns,
{[], Env},
fun(Acc, Pattern) ->
{Patterns@1, Env@1} = Acc,
_pipe = rewrite_patterns(Pattern, Env@1),
gleam@pair:map_first(
_pipe,
fun(_capture) -> gleam@list:prepend(Patterns@1, _capture) end
)
end
),
gleam@pair:map_first(_pipe@1, fun lists:reverse/1).