Packages
caffeine_lang
6.2.2
6.3.1
6.3.0
6.2.2
6.2.1
6.2.0
6.1.2
6.1.1
6.1.0
6.0.0
5.6.0
5.5.0
5.4.4
5.4.3
5.4.2
5.4.1
5.4.0
5.3.0
5.2.0
5.1.1
5.1.0
5.0.12
5.0.11
5.0.10
5.0.8
5.0.7
5.0.6
5.0.5
5.0.4
5.0.1
5.0.0
4.10.0
4.9.0
4.8.3
4.8.2
4.8.1
4.8.0
4.7.9
4.7.8
4.7.7
4.7.6
4.7.5
4.6.7
4.6.6
4.6.5
4.6.4
4.6.3
4.6.2
4.6.0
4.5.1
4.5.0
4.4.4
4.4.3
4.4.1
4.4.0
4.3.7
4.3.6
3.0.6
3.0.5
3.0.4
3.0.3
3.0.2
3.0.1
3.0.0
2.0.5
2.0.4
2.0.3
2.0.2
2.0.1
2.0.0
1.0.2
1.0.1
0.1.0
0.0.24
0.0.23
0.0.22
0.0.21
0.0.20
0.0.19
0.0.18
0.0.17
0.0.16
0.0.15
0.0.14
0.0.13
0.0.12
0.0.11
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.2
0.0.1
A compiler for generating reliability artifacts from service expectation definitions.
Current section
Files
Jump to
Current section
Files
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([promote_measurements_file/1, promote_expects_file/1, extendable_kind_to_string/1, build_type_alias_pairs/1, literal_to_string/1, value_to_string/1]).
-export_type([comment/0, parsed/0, validated/0, measurements_file/1, type_alias/0, expects_file/1, extendable/0, extendable_kind/0, measurement_item/0, expectation_type/0, expect_item/0, assumes/0, dependency/0, dependency_kind/0, guarantees/0, duration_literal/0, measured_by/0, struct/0, field/0, value/0, literal/0, match_clause/0, value_extraction/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()} |
{doc_comment, binary()}.
-type parsed() :: any().
-type validated() :: any().
-type measurements_file(HBM) :: {measurements_file,
list(type_alias()),
list(extendable()),
list(measurement_item()),
list(comment())} |
{gleam_phantom, HBM}.
-type type_alias() :: {type_alias,
binary(),
caffeine_lang@types:parsed_type(),
list(comment())}.
-type expects_file(HBN) :: {expects_file,
list(extendable()),
list(expect_item()),
list(comment())} |
{gleam_phantom, HBN}.
-type extendable() :: {extendable,
binary(),
extendable_kind(),
struct(),
list(comment())}.
-type extendable_kind() :: extendable_requires | extendable_provides.
-type measurement_item() :: {measurement_item,
binary(),
gleam@option:option(expectation_type()),
list(binary()),
struct(),
struct(),
list(comment())}.
-type expectation_type() :: success_rate_type | time_slice_type.
-type expect_item() :: {expect_item,
binary(),
list(binary()),
gleam@option:option(assumes()),
guarantees(),
list(comment())}.
-type assumes() :: {assumes, list(dependency()), list(comment())}.
-type dependency() :: {dependency, dependency_kind(), binary(), list(comment())}.
-type dependency_kind() :: hard_dep | soft_dep.
-type guarantees() :: {guarantees,
float(),
gleam@option:option(duration_literal()),
duration_literal(),
gleam@option:option(measured_by())}.
-type duration_literal() :: {duration_literal, float(), binary()}.
-type measured_by() :: {measured_by, binary(), struct()}.
-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_percentage, float()} |
{literal_duration, float(), binary()} |
literal_true |
literal_false |
{literal_list, list(literal())} |
{literal_struct, list(field()), list(comment())} |
{literal_external_indicator,
binary(),
list(match_clause()),
gleam@option:option(value_extraction())}.
-type match_clause() :: {match_clause, binary(), literal()}.
-type value_extraction() :: {value_extraction,
binary(),
caffeine_lang@types:parsed_type()}.
-file("src/caffeine_lang/frontend/ast.gleam", 65).
?DOC(false).
-spec promote_measurements_file(measurements_file(any())) -> measurements_file(any()).
promote_measurements_file(File) ->
{measurements_file,
erlang:element(2, File),
erlang:element(3, File),
erlang:element(4, File),
erlang:element(5, File)}.
-file("src/caffeine_lang/frontend/ast.gleam", 78).
?DOC(false).
-spec promote_expects_file(expects_file(any())) -> expects_file(any()).
promote_expects_file(File) ->
{expects_file,
erlang:element(2, File),
erlang:element(3, File),
erlang:element(4, File)}.
-file("src/caffeine_lang/frontend/ast.gleam", 110).
?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", 275).
?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", 292).
?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_percentage, F@1} ->
<<(gleam@string:inspect(F@1))/binary, "%"/utf8>>;
{literal_duration, Amount, Unit} ->
<<(gleam@string:inspect(Amount))/binary, Unit/binary>>;
literal_true ->
<<"true"/utf8>>;
literal_false ->
<<"false"/utf8>>;
{literal_list, _} ->
<<"[...]"/utf8>>;
{literal_struct, _, _} ->
<<"{...}"/utf8>>;
{literal_external_indicator, Source, _, _} ->
<<<<"from "/utf8, Source/binary>>/binary, " {...}"/utf8>>
end.
-file("src/caffeine_lang/frontend/ast.gleam", 283).
?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.