Choreo.Lab.DSL.Compiler (Choreo v0.12.0)

Copy Markdown View Source

Shared helper functions for Choreo Lab DSL compilers.

This module encapsulates AST parsing and utility operations used during macro expansion of the experimental diagram DSLs.

Summary

Functions

Recursively compiles all statements in a block using a provided processor function.

Extracts a do block from a constructor statement (assigned or inline). Returns {block, stripped_statement} or {nil, nil}.

Extracts line metadata from an AST node.

Formats a line number suffix for error messages.

Pops a do block from an argument list.

Pops trailing options (a keyword list) from an argument list.

Derives a snake_case atom from a string or atom label.

Unwraps a block or single statement into a list of statements.

Unwraps a pipeline of modifications.

Functions

compile_block_statements(block, env, process_statement_fn)

@spec compile_block_statements(Macro.t(), any(), (Macro.t(), any() -> {any(), any()})) ::
  {any(), any()}

Recursively compiles all statements in a block using a provided processor function.

extract_do_block(call)

@spec extract_do_block(Macro.t()) :: {Macro.t() | nil, Macro.t() | nil}

Extracts a do block from a constructor statement (assigned or inline). Returns {block, stripped_statement} or {nil, nil}.

line_meta(arg1)

@spec line_meta(Macro.t()) :: keyword()

Extracts line metadata from an AST node.

line_suffix(meta)

@spec line_suffix(keyword()) :: String.t()

Formats a line number suffix for error messages.

pop_do_block(args)

@spec pop_do_block([any()]) :: {Macro.t() | nil, [any()]}

Pops a do block from an argument list.

pop_trailing_opts(args)

@spec pop_trailing_opts([any()]) :: {keyword(), [any()]}

Pops trailing options (a keyword list) from an argument list.

slug_atom(label)

@spec slug_atom(String.t() | atom()) :: atom()

Derives a snake_case atom from a string or atom label.

statements(single)

@spec statements(Macro.t()) :: [Macro.t()]

Unwraps a block or single statement into a list of statements.

unwrap_pipe(base, acc)

@spec unwrap_pipe(Macro.t(), [Macro.t()]) :: {Macro.t(), [Macro.t()]}

Unwraps a pipeline of modifications.