AB.TypeParser (AB v0.2.1)
View SourceFunctions for parsing and extracting type specifications from modules.
Summary
Functions
Creates a struct generator based on the module's @type definition rather than @spec.
Extracts struct fields from field types.
Extracts the typespec for a given function. Returns {:ok, {input_types, output_type}} or {:error, reason}.
Gets a function spec with all user and remote types fully resolved.
Parses a spec AST into input and output types.
Resolves all user and remote types in a type specification recursively. Returns the fully resolved type with all type aliases expanded.
Compares two type specifications for equivalence, ignoring metadata like line numbers.
Functions
Creates a struct generator based on the module's @type definition rather than @spec.
Extracts struct fields from field types.
Extracts the typespec for a given function. Returns {:ok, {input_types, output_type}} or {:error, reason}.
@spec get_resolved_function_spec(module(), atom()) :: {:ok, {[any()], any()}} | {:error, String.t()}
Gets a function spec with all user and remote types fully resolved.
Examples
iex> get_resolved_function_spec(MyModule, :my_function)
{:ok, {[resolved_input_types], resolved_output_type}}
@spec parse_spec(any()) :: {:ok, {[any()], any()}} | {:error, String.t()}
@spec parse_spec(any()) :: {:ok, {[any()], any()}} | {:error, String.t()}
@spec parse_spec(any()) :: {:ok, {[any()], any()}} | {:error, String.t()}
Parses a spec AST into input and output types.
Resolves all user and remote types in a type specification recursively. Returns the fully resolved type with all type aliases expanded.
Examples
iex> resolve_all_types({:user_type, 0, :opts, []}, MyModule)
{:type, 0, :list, [...]}
iex> resolve_all_types({:remote_type, 0, [{:atom, 0, String}, {:atom, 0, :t}, []]}, MyModule)
{:type, 0, :binary, []}
@spec types_equivalent?(any(), any()) :: boolean()
@spec types_equivalent?(any(), any()) :: boolean()
@spec types_equivalent?(any(), any()) :: boolean()
@spec types_equivalent?(any(), any()) :: boolean()
@spec types_equivalent?(any(), any()) :: boolean()
@spec types_equivalent?(any(), any()) :: boolean()
@spec types_equivalent?(any(), any()) :: boolean()
@spec types_equivalent?(any(), any()) :: boolean()
Compares two type specifications for equivalence, ignoring metadata like line numbers.