thrift_generator_codec_ast (thrift_generator v0.7.0)

View Source

Raw erl_parse vocabulary shared by the specialized wire-codec emitters (thrift_generator_codec for the binary protocol and its compact/JSON siblings).

Patterns, binary segment options, guards and comprehension qualifiers have no convenient erl_syntax constructors, so the codec emitters build raw trees and let erl_pp render them; doc and spec attributes stay syntax trees like everywhere else in the emitter. Everything here is protocol-agnostic — the binary- and compact-specific shapes (fixed width headers, length prefixes) stay in their emitters.

Summary

Types

annotations()

-type annotations() :: #{binary() := true | binary()}.

ast()

-type ast() :: tuple().

ast_node()

-type ast_node() ::
          #thrift_generator_node{line :: non_neg_integer(),
                                 col :: non_neg_integer(),
                                 doc :: doc(),
                                 annotations :: erl_annotations(),
                                 payload :: term(),
                                 type_module :: module()}.

base_type()

-type base_type() :: bool | i8 | i16 | i32 | i64 | double | string | binary | uuid.

const_value()

-type const_value() ::
          {ref, Name :: binary()} |
          boolean() |
          integer() |
          float() |
          binary() |
          {list, [const_value()]} |
          {map, [{const_value(), const_value()}]}.

constant()

-type constant() ::
          #thrift_generator_constant{name :: constant_name(),
                                     type :: thrift_type(),
                                     value :: const_value()}.

constant_name()

-nominal constant_name() :: binary().

cpp_include()

-type cpp_include() :: #thrift_generator_cpp_include{path :: include_path()}.

doc()

-type doc() :: binary() | undefined.

document()

-type document() :: #thrift_generator_document{headers :: [ast_node()], definitions :: [ast_node()]}.

enum_()

-type enum_() :: #thrift_generator_enum{name :: enum_name(), values :: [enum_value()]}.

enum_name()

-nominal enum_name() :: binary().

enum_value()

-type enum_value() :: {Name :: binary(), Value :: integer() | undefined, annotations(), doc()}.

erl_annotations()

-type erl_annotations() :: #{atom() := true | binary()}.

exception_()

-type exception_() :: #thrift_generator_exception{name :: exception_name(), fields :: [ast_node()]}.

exception_name()

-nominal exception_name() :: binary().

field_()

-type field_() ::
          #thrift_generator_field{id :: integer() | undefined,
                                  required :: requiredness(),
                                  type :: thrift_type(),
                                  name :: field_name(),
                                  default :: const_value() | undefined}.

field_name()

-nominal field_name() :: binary().

function_()

-type function_() ::
          #thrift_generator_function{oneway :: boolean(),
                                     return_type :: thrift_type() | void,
                                     name :: function_name(),
                                     fields :: [ast_node()],
                                     throws :: [ast_node()]}.

function_name()

-nominal function_name() :: binary().

include_()

-type include_() :: #thrift_generator_include{path :: include_path()}.

include_path()

-nominal include_path() :: binary().

namespace_()

-type namespace_() :: #thrift_generator_namespace{scope :: namespace_scope(), name :: namespace_name()}.

namespace_name()

-nominal namespace_name() :: binary().

namespace_scope()

-nominal namespace_scope() :: binary().

node_payload()

-type node_payload() ::
          document() |
          include_() |
          cpp_include() |
          namespace_() |
          constant() |
          typedef() |
          enum_() |
          struct_() |
          union_def() |
          exception_() |
          service() |
          function_() |
          field_().

requiredness()

-type requiredness() :: required | optional | default.

service()

-type service() ::
          #thrift_generator_service{name :: service_name(),
                                    extends :: service_parent() | undefined,
                                    functions :: [ast_node()]}.

service_name()

-nominal service_name() :: binary().

service_parent()

-nominal service_parent() :: binary().

struct_()

-type struct_() :: #thrift_generator_struct{name :: struct_name(), fields :: [ast_node()]}.

struct_name()

-nominal struct_name() :: binary().

thrift_type()

-type thrift_type() ::
          {base, base_type(), annotations()} |
          type_ref() |
          {list, Element :: thrift_type(), annotations()} |
          {set, Element :: thrift_type(), annotations()} |
          {map, Key :: thrift_type(), Value :: thrift_type(), annotations()}.

type_ref()

-type type_ref() :: {ref, Name :: binary(), annotations()}.

typedef()

-type typedef() :: #thrift_generator_typedef{name :: typedef_name(), type :: thrift_type()}.

typedef_name()

-nominal typedef_name() :: binary().

union_def()

-type union_def() :: #thrift_generator_union{name :: union_name(), fields :: [ast_node()]}.

union_name()

-nominal union_name() :: binary().

Functions

nil()

-spec nil() -> ast().

at(A)

-spec at(atom()) -> ast().

atom_concat(Atom, Suffix)

-spec atom_concat(atom(), binary()) -> atom().

bin_lit(Bin)

-spec bin_lit(binary()) -> ast().

bin_pat(Segments)

-spec bin_pat([{ast(), ast() | default, [atom()] | default}]) -> ast().

bin_seg(Expr, Size, Types)

-spec bin_seg(ast(), ast() | default, [atom()] | default) -> ast().

call_local(F, Args)

-spec call_local(atom(), [ast()]) -> ast().

'case'(Expr, Clauses)

-spec 'case'(ast(), [ast()]) -> ast().

clause(Patterns, Guard, Body)

-spec clause([ast()], none | [ast()], [ast()]) -> ast().

cons(H, T)

-spec cons(ast(), ast()) -> ast().

encode_entry_clause(CheckBody)

-spec encode_entry_clause(ast()) -> ast().

encode_error_clause()

-spec encode_error_clause() -> ast().

err_decode(Reason)

-spec err_decode(ast()) -> ast().

err_encode(Reason)

-spec err_encode(ast()) -> ast().

error_clause()

-spec error_clause() -> ast().

fun_type(Args, Ret)

-spec fun_type([ast()], ast()) -> ast().

i(N)

-spec i(integer()) -> ast().

key_filter/3

-spec key_filter(ast(), ast(), boolean()) -> ast().

lc(Template, Qualifiers)

-spec lc(ast(), [ast()]) -> ast().

list_lit(Elements)

-spec list_lit([ast()]) -> ast().

literal/1

-spec literal(term()) -> ast().

map_empty()

-spec map_empty() -> ast().

map_exact(K, V)

-spec map_exact(ast(), ast()) -> ast().

map_put(Base, K, V)

-spec map_put(ast(), ast(), ast()) -> ast().

mismatch(Value)

-spec mismatch(ast()) -> ast().

mismatch_fn_tail()

-spec mismatch_fn_tail() -> ast().

mismatch_tail(V)

-spec mismatch_tail(ast()) -> ast().

more_tail()

-spec more_tail() -> ast().

name_lit(Bin)

-spec name_lit(binary()) -> ast().

ok3(Value, Rest)

-spec ok3(ast(), ast()) -> ast().

ok3_bind_clause(BindValue, BindRest, Body)

-spec ok3_bind_clause(ast(), ast(), ast()) -> ast().

ok_bind_clause(Bind, Body)

-spec ok_bind_clause(ast(), ast()) -> ast().

ok_t(Value)

-spec ok_t(ast()) -> ast().

other_clause(Name)

-spec other_clause(string()) -> ast().

other_tail()

-spec other_tail() -> ast().

remote(M, F, Args)

-spec remote(module(), atom(), [ast()]) -> ast().

required_check(Fields, Call)

-spec required_check([#tg_field{id :: integer(),
                                required :: requiredness(),
                                type :: thrift_type(),
                                name :: binary(),
                                default :: const_value() | undefined,
                                doc :: doc()}],
                     ast()) ->
                        ast().

spec_form(Name, Arity, Types)

-spec spec_form(atom(), arity(), [ast()]) -> {attribute, erl_anno:anno(), spec, term()}.

t_atom(Name)

-spec t_atom(atom()) -> ast().

t_atom_lit(A)

-spec t_atom_lit(atom()) -> ast().

t_error()

-spec t_error() -> ast().

t_fun(Args, Ret)

-spec t_fun([ast()], ast()) -> ast().

t_map_exact()

-spec t_map_exact() -> ast().

t_map_loose()

-spec t_map_loose() -> ast().

t_ok(Type)

-spec t_ok(ast()) -> ast().

t_union(Options)

-spec t_union([ast()]) -> ast().

tuple_pat(Elements)

-spec tuple_pat([ast()]) -> ast().

tuple_t(Elements)

-spec tuple_t([ast()]) -> ast().

tuple_t_type(Elements)

-spec tuple_t_type([ast()]) -> ast().

union_check(Fields, Call)

-spec union_check([#tg_field{id :: integer(),
                             required :: requiredness(),
                             type :: thrift_type(),
                             name :: binary(),
                             default :: const_value() | undefined,
                             doc :: doc()}],
                  ast()) ->
                     ast().

v(Name)

-spec v(string()) -> ast().