Current section

Files

Jump to
caffeine_lang src caffeine_lang@frontend@ast.erl
Raw

src/caffeine_lang@frontend@ast.erl

-module(caffeine_lang@frontend@ast).
-compile([no_auto_import, nowarn_unused_vars, nowarn_unused_function, nowarn_nomatch, inline]).
-define(FILEPATH, "src/caffeine_lang/frontend/ast.gleam").
-export([extendable_kind_to_string/1, parsed_artifact_ref_to_string/1, build_type_alias_pairs/1, literal_to_string/1, value_to_string/1]).
-export_type([comment/0, blueprints_file/0, type_alias/0, expects_file/0, extendable/0, extendable_kind/0, parsed_artifact_ref/0, blueprints_block/0, blueprint_item/0, expects_block/0, expect_item/0, struct/0, field/0, value/0, literal/0]).
-if(?OTP_RELEASE >= 27).
-define(MODULEDOC(Str), -moduledoc(Str)).
-define(DOC(Str), -doc(Str)).
-else.
-define(MODULEDOC(Str), -compile([])).
-define(DOC(Str), -compile([])).
-endif.
-type comment() :: {line_comment, binary()} | {section_comment, binary()}.
-type blueprints_file() :: {blueprints_file,
list(type_alias()),
list(extendable()),
list(blueprints_block()),
list(comment())}.
-type type_alias() :: {type_alias,
binary(),
caffeine_lang@types:parsed_type(),
list(comment())}.
-type expects_file() :: {expects_file,
list(extendable()),
list(expects_block()),
list(comment())}.
-type extendable() :: {extendable,
binary(),
extendable_kind(),
struct(),
list(comment())}.
-type extendable_kind() :: extendable_requires | extendable_provides.
-type parsed_artifact_ref() :: parsed_s_l_o | parsed_dependency_relations.
-type blueprints_block() :: {blueprints_block,
list(parsed_artifact_ref()),
list(blueprint_item()),
list(comment())}.
-type blueprint_item() :: {blueprint_item,
binary(),
list(binary()),
struct(),
struct(),
list(comment())}.
-type expects_block() :: {expects_block,
binary(),
list(expect_item()),
list(comment())}.
-type expect_item() :: {expect_item,
binary(),
list(binary()),
struct(),
list(comment())}.
-type struct() :: {struct, list(field()), list(comment())}.
-type field() :: {field, binary(), value(), list(comment())}.
-type value() :: {type_value, caffeine_lang@types:parsed_type()} |
{literal_value, literal()}.
-type literal() :: {literal_string, binary()} |
{literal_integer, integer()} |
{literal_float, float()} |
literal_true |
literal_false |
{literal_list, list(literal())} |
{literal_struct, list(field()), list(comment())}.
-file("src/caffeine_lang/frontend/ast.gleam", 72).
?DOC(false).
-spec extendable_kind_to_string(extendable_kind()) -> binary().
extendable_kind_to_string(Kind) ->
case Kind of
extendable_requires ->
<<"Requires"/utf8>>;
extendable_provides ->
<<"Provides"/utf8>>
end.
-file("src/caffeine_lang/frontend/ast.gleam", 91).
?DOC(false).
-spec parsed_artifact_ref_to_string(parsed_artifact_ref()) -> binary().
parsed_artifact_ref_to_string(Ref) ->
case Ref of
parsed_s_l_o ->
<<"SLO"/utf8>>;
parsed_dependency_relations ->
<<"DependencyRelations"/utf8>>
end.
-file("src/caffeine_lang/frontend/ast.gleam", 183).
?DOC(false).
-spec build_type_alias_pairs(list(type_alias())) -> list({binary(),
caffeine_lang@types:parsed_type()}).
build_type_alias_pairs(Type_aliases) ->
gleam@list:map(
Type_aliases,
fun(Ta) -> {erlang:element(2, Ta), erlang:element(3, Ta)} end
).
-file("src/caffeine_lang/frontend/ast.gleam", 200).
?DOC(false).
-spec literal_to_string(literal()) -> binary().
literal_to_string(Lit) ->
case Lit of
{literal_string, S} ->
<<<<"\""/utf8, S/binary>>/binary, "\""/utf8>>;
{literal_integer, N} ->
gleam@string:inspect(N);
{literal_float, F} ->
gleam@string:inspect(F);
literal_true ->
<<"true"/utf8>>;
literal_false ->
<<"false"/utf8>>;
{literal_list, _} ->
<<"[...]"/utf8>>;
{literal_struct, _, _} ->
<<"{...}"/utf8>>
end.
-file("src/caffeine_lang/frontend/ast.gleam", 191).
?DOC(false).
-spec value_to_string(value()) -> binary().
value_to_string(Value) ->
case Value of
{type_value, T} ->
caffeine_lang@types:parsed_type_to_string(T);
{literal_value, Lit} ->
literal_to_string(Lit)
end.