AshBaml.BamlParser (ash_baml v0.2.0)

View Source

Parses BAML schemas and extracts type information for code generation.

This module wraps the baml_elixir parsing functionality to provide a clean interface for extracting classes, enums, and functions.

Summary

Functions

Extracts class definitions from parsed BAML schema.

Extracts enum definitions from parsed BAML schema.

Gets the BAML source path from a client module's configuration.

Extracts all type definitions from BAML files in the given path.

Functions

extract_classes(map)

Extracts class definitions from parsed BAML schema.

Returns a map where keys are class names and values contain field definitions.

extract_enums(map)

Extracts enum definitions from parsed BAML schema.

Returns a map where keys are enum names and values are lists of variants.

get_baml_path(client_module)

Gets the BAML source path from a client module's configuration.

Parameters

  • client_module - Module that uses BamlElixir.Client

Returns

  • {:ok, path} if configuration found
  • {:error, reason} if not found

Implementation Notes

The __baml_src_path__/0 callback is automatically generated by both:

  • use BamlElixir.Client macro (for explicit client modules)
  • DefineClientModules transformer (for config-driven clients)

At compile time, if the module is not yet loaded, this will attempt to extract the path from the module's source file as a fallback.

parse_schema(baml_src_path)

Extracts all type definitions from BAML files in the given path.

Parameters

  • baml_src_path - Path to directory containing .baml files

Returns

  • {:ok, %{classes: map, enums: map, functions: map}} on success
  • {:error, reason} on failure