Std.CodeGen (Cure Standard Library v0.38.0)

View Source

First-class Cure code generator built on Std.Syntax and Cure.Compiler.Printer.

Every gen_* constructor returns a Std.Syntax.Syntax tree, so generated code can either be rendered to formatted, parse-verified .cure source via render/1, render_formatted/1, and render_verified/1, or spliced directly into compile-time macros.

Examples

use Std.CodeGen

let body = gen_binop("+", gen_var("x"), gen_int(1))
let inc  = gen_fn("inc", [gen_param("x", gen_type_ref("Int"))], gen_type_ref("Int"), body)
let m    = gen_mod("Demo.Math", [gen_comment("Auto-generated"), inc])
render_verified(m)

Summary

Types

Errors produced when lowering, printing, or parse-verifying generated syntax.

A named, typed field specification for gen_rec/2.

A planned generated source file pairing an output path with its Syntax tree.

A rendered and parse-verified source file pairing an output path with its source text.

Callbacks

Lift a Cure runtime value into a Std.Syntax.Syntax literal expression.

Functions

Append a declaration decl to a module, proof, interface, implementation, or block container.

Append multiple declarations decls to a module, proof, interface, implementation, or block container.

Append a use <module_name> import to container.

Mark a function definition fn_node as private (local fn).

Construct an unguarded match arm <pattern> -> <body>.

Construct an atom literal syntax node.

Construct a standard generated-file banner comment attributing generator_name.

Construct a binary operator expression <left> <op> <right> (e.g. "+", "==", "*", "and").

Construct a sequential expression block.

Construct a boolean literal syntax node.

Construct a function call <name>(<args>).

Construct a character literal syntax node.

Construct a standalone # <text> line comment node (multi-line strings emit one # per line).

Construct a cons list expression [<head> | <tail>].

Construct a decorator @<name>(<args>) (or bare @<name> when args is empty).

Construct a standalone ## <text> doc comment node (multi-line strings emit one ## per line).

Attach @extern(<mod_name>, <fun_name>, <arity>) to a function signature sig.

Construct a FieldSpec pairing field name with type kind.

Construct a field access expression <target>.<field>.

Construct a float literal syntax node.

Construct a public function definition fn <name>(<params>) -> <ret> = <body>.

Construct a single clause | <patterns> -> <body> for a multi-clause function.

Construct a multi-clause function definition fn <name>(<params>) -> <ret> with clauses.

Construct a bodyless function signature fn <name>(<params>) -> <ret> (for interfaces and @extern).

Construct a function type (<domains>) -> <ret>.

Construct a guarded match arm <pattern> when <guard> -> <body>.

Construct a guarded clause | <patterns> when <guard> -> <body> for a multi-clause function.

Construct an if <cond> then <then_br> else <else_br> conditional expression.

Construct an implementation block impl <interface_name> for <target_type> with methods fns.

Construct an integer literal syntax node.

Construct a protocol/interface declaration proto <name>(<type_params>) with method signatures sigs.

Construct an anonymous function fn(<param_names>) -> <body>.

Construct a let <name> = <value> binding.

Construct a list literal [<items>].

Construct a private function definition local fn <name>(<params>) -> <ret> = <body>.

Construct a map literal %{<pairs>}.

Construct a match <scrutinee> expression with arms.

Construct a mod <name> container with body declarations decls.

Construct a key-value pair <key>: <value> for maps and record literals.

Construct a typed function parameter name: kind.

Construct a pickup conditional block with clauses.

Construct a pickup guard clause <guard> -> <body>.

Construct a pickup terminator clause else -> <body>.

Thread initial through a list of call expressions steps using the |> pipe operator.

Construct a single pipe step <lhs> |> <fn_name>(<extra_args>).

Construct a top-level program block containing items separated by canonical blank lines.

Construct a proof <name> container with proof declarations decls.

Construct a module-qualified function call <mod_name>.<fn_name>(<args>).

Construct a rec <name> record declaration with fields.

Construct a parameterized rec <name>(<type_params>) record declaration with fields.

Construct a record construction literal <name>{<field_pairs>}.

Construct an idiomatic section divider comment # -- <title> ---... padded to 76 columns.

Construct a string literal syntax node.

Construct a tuple literal (<items>).

Construct a tuple type Tuple(<items>).

Construct a sum type declaration type <name> = <variants>.

Construct a parameterized type application <name>(<args>) (e.g. List(Int)).

Construct a parameterized sum type declaration type <name>(<type_params>) = <variants>.

Construct a bare type reference <name> (e.g. Int, String).

Construct a typealias <name> = <rhs> declaration.

Construct a typed let <name>: <kind> = <value> binding.

Construct the unit value literal ().

Construct a unary operator expression <op> <operand> (e.g. "-", "not").

Construct a use <module_name> import declaration.

Construct an aliased use <module_name> as <alias_name> import declaration.

Construct a selective use <module_name>.{<items>} import declaration.

Construct a variable reference syntax node.

Construct a nullary enum variant name.

Construct an enum variant name(payload_types...) carrying typed payloads.

Construct a GeneratedFile entry pairing path with its Syntax tree content.

Return true when name is a Cure reserved keyword.

Lift a List(t) into a list literal [...] using elem_fn for each element.

Lift an Option(t) into Some(<val>) or None() using elem_fn.

Parse a single Cure expression string into a Syntax tree.

Parse a Cure source string (module, declaration list, or expression) into a Syntax tree.

Render a Syntax tree to Cure source using the default 2-space indentation.

Atomically render, format, and parse-verify every file in files, returning all RenderedFiles or the first error.

Render and format a Syntax tree with Cure's canonical formatter.

Render and format a Syntax tree. Pass true for the algebra formatter or false for the text formatter.

Render, format, and parse-verify a Syntax tree, guaranteeing syntactically valid Cure output.

Render a Syntax tree, optionally format it, and verify that it lexes and parses cleanly.

Render a Syntax tree to Cure source with an explicit indentation width (spaces, clamped to 1..8).

Lift a Result(t, e) into Ok(<val>) or Error(<err>) using ok_fn and err_fn.

Sanitize a foreign identifier into a valid Cure identifier, escaping reserved keywords with a trailing _.

Convert a snake_case or kebab-case name into PascalCase.

Convert a camelCase, PascalCase, or kebab-case name into snake_case.

Convert value into its Cure Syntax representation.

Request a blank line before node inside a block or module body.

Attach a # <text> leading comment above node (call repeatedly to stack lines).

Attach a decorator @<name>(<args>) above node (call repeatedly to stack decorators).

Attach a ## <text> doc comment above node.

Attach a when <guard> clause to a function definition fn_node.

Attach a trailing inline # <text> comment on the same line as node.

Types

enum CodeGenError

 enum CodeGenError
   LowerError
   PrintError
   ParseError

Errors produced when lowering, printing, or parse-verifying generated syntax.

struct FieldSpec

 struct FieldSpec
   ?
   ?

A named, typed field specification for gen_rec/2.

struct GeneratedFile

 struct GeneratedFile
   ?
   ?

A planned generated source file pairing an output path with its Syntax tree.

struct RenderedFile

 struct RenderedFile
   ?
   ?

A rendered and parse-verified source file pairing an output path with its source text.

Callbacks

interface ToSyntax(t)

 interface ToSyntax(t)

Lift a Cure runtime value into a Std.Syntax.Syntax literal expression.

Functions

add_decl(container: Syntax, decl: Syntax) -> Syntax

 fn add_decl(container: Syntax, decl: Syntax) -> Syntax

Append a declaration decl to a module, proof, interface, implementation, or block container.

add_decls(container: Syntax, decls: List(Syntax)) -> Syntax

 fn add_decls(container: Syntax, decls: List(Syntax)) -> Syntax

Append multiple declarations decls to a module, proof, interface, implementation, or block container.

add_use(container: Syntax, module_name: String) -> Syntax

 fn add_use(container: Syntax, module_name: String) -> Syntax

Append a use <module_name> import to container.

append_list_attr(values: List(Attr), key: Atom, item: SynLit) -> List(Attr)

 fn append_list_attr(values: List(Attr), key: Atom, item: SynLit) -> List(Attr)

append_node_list_attr(node: Syntax, key: Atom, item: SynLit) -> Syntax

 fn append_node_list_attr(node: Syntax, key: Atom, item: SynLit) -> Syntax

append_synlit_list(existing: SynLit, item: SynLit) -> SynLit

 fn append_synlit_list(existing: SynLit, item: SynLit) -> SynLit

as_local(fn_node: Syntax) -> Syntax

 fn as_local(fn_node: Syntax) -> Syntax

Mark a function definition fn_node as private (local fn).

char_or(cp: Int, fallback: Char) -> Char

 fn char_or(cp: Int, fallback: Char) -> Char

field_nodes(fields: List(FieldSpec)) -> List(Syntax)

 fn field_nodes(fields: List(FieldSpec)) -> List(Syntax)

gen_arm(pattern: Syntax, body: Syntax) -> Syntax

 fn gen_arm(pattern: Syntax, body: Syntax) -> Syntax

Construct an unguarded match arm <pattern> -> <body>.

gen_atom(value: Atom) -> Syntax

 fn gen_atom(value: Atom) -> Syntax

Construct an atom literal syntax node.

gen_banner(generator_name: String) -> Syntax

 fn gen_banner(generator_name: String) -> Syntax

Construct a standard generated-file banner comment attributing generator_name.

gen_binop(op: String, left: Syntax, right: Syntax) -> Syntax

 fn gen_binop(op: String, left: Syntax, right: Syntax) -> Syntax

Construct a binary operator expression <left> <op> <right> (e.g. "+", "==", "*", "and").

gen_block(exprs: List(Syntax)) -> Syntax

 fn gen_block(exprs: List(Syntax)) -> Syntax

Construct a sequential expression block.

gen_bool(value: Bool) -> Syntax

 fn gen_bool(value: Bool) -> Syntax

Construct a boolean literal syntax node.

gen_call(name: String, args: List(Syntax)) -> Syntax

 fn gen_call(name: String, args: List(Syntax)) -> Syntax

Construct a function call <name>(<args>).

gen_char(value: Char) -> Syntax

 fn gen_char(value: Char) -> Syntax

Construct a character literal syntax node.

gen_comment(text: String) -> Syntax

 fn gen_comment(text: String) -> Syntax

Construct a standalone # <text> line comment node (multi-line strings emit one # per line).

gen_cons(head: Syntax, tail: Syntax) -> Syntax

 fn gen_cons(head: Syntax, tail: Syntax) -> Syntax

Construct a cons list expression [<head> | <tail>].

gen_decorator(name: String, args: List(Syntax)) -> Syntax

 fn gen_decorator(name: String, args: List(Syntax)) -> Syntax

Construct a decorator @<name>(<args>) (or bare @<name> when args is empty).

gen_doc(text: String) -> Syntax

 fn gen_doc(text: String) -> Syntax

Construct a standalone ## <text> doc comment node (multi-line strings emit one ## per line).

gen_extern(mod_name: Atom, fun_name: Atom, arity: Int, sig: Syntax) -> Syntax

 fn gen_extern(mod_name: Atom, fun_name: Atom, arity: Int, sig: Syntax) -> Syntax

Attach @extern(<mod_name>, <fun_name>, <arity>) to a function signature sig.

gen_field(name: String, kind: Syntax) -> FieldSpec

 fn gen_field(name: String, kind: Syntax) -> FieldSpec

Construct a FieldSpec pairing field name with type kind.

gen_field_access(target: Syntax, field: String) -> Syntax

 fn gen_field_access(target: Syntax, field: String) -> Syntax

Construct a field access expression <target>.<field>.

gen_float(value: Float) -> Syntax

 fn gen_float(value: Float) -> Syntax

Construct a float literal syntax node.

gen_fn(name: String, params: List(Syntax), ret: Syntax, body: Syntax) -> Syntax

 fn gen_fn(name: String, params: List(Syntax), ret: Syntax, body: Syntax) -> Syntax

Construct a public function definition fn <name>(<params>) -> <ret> = <body>.

gen_fn_clause(patterns: List(Syntax), body: Syntax) -> Syntax

 fn gen_fn_clause(patterns: List(Syntax), body: Syntax) -> Syntax

Construct a single clause | <patterns> -> <body> for a multi-clause function.

gen_fn_clauses(name: String, params: List(Syntax), ret: Syntax, clauses: List(Syntax)) -> Syntax

 fn gen_fn_clauses(name: String, params: List(Syntax), ret: Syntax, clauses: List(Syntax)) -> Syntax

Construct a multi-clause function definition fn <name>(<params>) -> <ret> with clauses.

gen_fn_sig(name: String, params: List(Syntax), ret: Syntax) -> Syntax

 fn gen_fn_sig(name: String, params: List(Syntax), ret: Syntax) -> Syntax

Construct a bodyless function signature fn <name>(<params>) -> <ret> (for interfaces and @extern).

gen_fn_type(domains: List(Syntax), ret: Syntax) -> Syntax

 fn gen_fn_type(domains: List(Syntax), ret: Syntax) -> Syntax

Construct a function type (<domains>) -> <ret>.

gen_guarded_arm(pattern: Syntax, guard: Syntax, body: Syntax) -> Syntax

 fn gen_guarded_arm(pattern: Syntax, guard: Syntax, body: Syntax) -> Syntax

Construct a guarded match arm <pattern> when <guard> -> <body>.

gen_guarded_fn_clause(patterns: List(Syntax), guard: Syntax, body: Syntax) -> Syntax

 fn gen_guarded_fn_clause(patterns: List(Syntax), guard: Syntax, body: Syntax) -> Syntax

Construct a guarded clause | <patterns> when <guard> -> <body> for a multi-clause function.

gen_if(cond: Syntax, then_br: Syntax, else_br: Syntax) -> Syntax

 fn gen_if(cond: Syntax, then_br: Syntax, else_br: Syntax) -> Syntax

Construct an if <cond> then <then_br> else <else_br> conditional expression.

gen_impl(interface_name: String, target_type: Syntax, fns: List(Syntax)) -> Syntax

 fn gen_impl(interface_name: String, target_type: Syntax, fns: List(Syntax)) -> Syntax

Construct an implementation block impl <interface_name> for <target_type> with methods fns.

gen_int(value: Int) -> Syntax

 fn gen_int(value: Int) -> Syntax

Construct an integer literal syntax node.

gen_interface(name: String, type_params: List(String), sigs: List(Syntax)) -> Syntax

 fn gen_interface(name: String, type_params: List(String), sigs: List(Syntax)) -> Syntax

Construct a protocol/interface declaration proto <name>(<type_params>) with method signatures sigs.

gen_lambda(param_names: List(String), body: Syntax) -> Syntax

 fn gen_lambda(param_names: List(String), body: Syntax) -> Syntax

Construct an anonymous function fn(<param_names>) -> <body>.

gen_let(name: String, value: Syntax) -> Syntax

 fn gen_let(name: String, value: Syntax) -> Syntax

Construct a let <name> = <value> binding.

gen_list(items: List(Syntax)) -> Syntax

 fn gen_list(items: List(Syntax)) -> Syntax

Construct a list literal [<items>].

gen_local_fn(name: String, params: List(Syntax), ret: Syntax, body: Syntax) -> Syntax

 fn gen_local_fn(name: String, params: List(Syntax), ret: Syntax, body: Syntax) -> Syntax

Construct a private function definition local fn <name>(<params>) -> <ret> = <body>.

gen_map(pairs: List(Syntax)) -> Syntax

 fn gen_map(pairs: List(Syntax)) -> Syntax

Construct a map literal %{<pairs>}.

gen_match(scrutinee: Syntax, arms: List(Syntax)) -> Syntax

 fn gen_match(scrutinee: Syntax, arms: List(Syntax)) -> Syntax

Construct a match <scrutinee> expression with arms.

gen_mod(name: String, decls: List(Syntax)) -> Syntax

 fn gen_mod(name: String, decls: List(Syntax)) -> Syntax

Construct a mod <name> container with body declarations decls.

gen_pair(key: Syntax, value: Syntax) -> Syntax

 fn gen_pair(key: Syntax, value: Syntax) -> Syntax

Construct a key-value pair <key>: <value> for maps and record literals.

gen_param(name: String, kind: Syntax) -> Syntax

 fn gen_param(name: String, kind: Syntax) -> Syntax

Construct a typed function parameter name: kind.

gen_pickup(clauses: List(Syntax)) -> Syntax

 fn gen_pickup(clauses: List(Syntax)) -> Syntax

Construct a pickup conditional block with clauses.

gen_pickup_clause(guard: Syntax, body: Syntax) -> Syntax

 fn gen_pickup_clause(guard: Syntax, body: Syntax) -> Syntax

Construct a pickup guard clause <guard> -> <body>.

gen_pickup_else(body: Syntax) -> Syntax

 fn gen_pickup_else(body: Syntax) -> Syntax

Construct a pickup terminator clause else -> <body>.

gen_pipe(initial: Syntax, steps: List(Syntax)) -> Syntax

 fn gen_pipe(initial: Syntax, steps: List(Syntax)) -> Syntax

Thread initial through a list of call expressions steps using the |> pipe operator.

gen_pipe_step(lhs: Syntax, fn_name: String, extra_args: List(Syntax)) -> Syntax

 fn gen_pipe_step(lhs: Syntax, fn_name: String, extra_args: List(Syntax)) -> Syntax

Construct a single pipe step <lhs> |> <fn_name>(<extra_args>).

gen_program(items: List(Syntax)) -> Syntax

 fn gen_program(items: List(Syntax)) -> Syntax

Construct a top-level program block containing items separated by canonical blank lines.

gen_proof(name: String, decls: List(Syntax)) -> Syntax

 fn gen_proof(name: String, decls: List(Syntax)) -> Syntax

Construct a proof <name> container with proof declarations decls.

gen_qual_call(mod_name: String, fn_name: String, args: List(Syntax)) -> Syntax

 fn gen_qual_call(mod_name: String, fn_name: String, args: List(Syntax)) -> Syntax

Construct a module-qualified function call <mod_name>.<fn_name>(<args>).

gen_rec(name: String, fields: List(FieldSpec)) -> Syntax

 fn gen_rec(name: String, fields: List(FieldSpec)) -> Syntax

Construct a rec <name> record declaration with fields.

gen_rec_generic(name: String, type_params: List(String), fields: List(FieldSpec)) -> Syntax

 fn gen_rec_generic(name: String, type_params: List(String), fields: List(FieldSpec)) -> Syntax

Construct a parameterized rec <name>(<type_params>) record declaration with fields.

gen_record_lit(name: String, field_pairs: List(Syntax)) -> Syntax

 fn gen_record_lit(name: String, field_pairs: List(Syntax)) -> Syntax

Construct a record construction literal <name>{<field_pairs>}.

gen_section(title: String) -> Syntax

 fn gen_section(title: String) -> Syntax

Construct an idiomatic section divider comment # -- <title> ---... padded to 76 columns.

gen_string(value: String) -> Syntax

 fn gen_string(value: String) -> Syntax

Construct a string literal syntax node.

gen_tuple(items: List(Syntax)) -> Syntax

 fn gen_tuple(items: List(Syntax)) -> Syntax

Construct a tuple literal (<items>).

gen_tuple_type(items: List(Syntax)) -> Syntax

 fn gen_tuple_type(items: List(Syntax)) -> Syntax

Construct a tuple type Tuple(<items>).

gen_type(name: String, variants: List(Syntax)) -> Syntax

 fn gen_type(name: String, variants: List(Syntax)) -> Syntax

Construct a sum type declaration type <name> = <variants>.

gen_type_app(name: String, args: List(Syntax)) -> Syntax

 fn gen_type_app(name: String, args: List(Syntax)) -> Syntax

Construct a parameterized type application <name>(<args>) (e.g. List(Int)).

gen_type_generic(name: String, type_params: List(String), variants: List(Syntax)) -> Syntax

 fn gen_type_generic(name: String, type_params: List(String), variants: List(Syntax)) -> Syntax

Construct a parameterized sum type declaration type <name>(<type_params>) = <variants>.

gen_type_ref(name: String) -> Syntax

 fn gen_type_ref(name: String) -> Syntax

Construct a bare type reference <name> (e.g. Int, String).

gen_typealias(name: String, rhs: Syntax) -> Syntax

 fn gen_typealias(name: String, rhs: Syntax) -> Syntax

Construct a typealias <name> = <rhs> declaration.

gen_typed_let(name: String, kind: Syntax, value: Syntax) -> Syntax

 fn gen_typed_let(name: String, kind: Syntax, value: Syntax) -> Syntax

Construct a typed let <name>: <kind> = <value> binding.

gen_unit() -> Syntax

 fn gen_unit() -> Syntax

Construct the unit value literal ().

gen_unop(op: String, operand: Syntax) -> Syntax

 fn gen_unop(op: String, operand: Syntax) -> Syntax

Construct a unary operator expression <op> <operand> (e.g. "-", "not").

gen_use(module_name: String) -> Syntax

 fn gen_use(module_name: String) -> Syntax

Construct a use <module_name> import declaration.

gen_use_as(module_name: String, alias_name: String) -> Syntax

 fn gen_use_as(module_name: String, alias_name: String) -> Syntax

Construct an aliased use <module_name> as <alias_name> import declaration.

gen_use_items(module_name: String, items: List(String)) -> Syntax

 fn gen_use_items(module_name: String, items: List(String)) -> Syntax

Construct a selective use <module_name>.{<items>} import declaration.

gen_var(name: String) -> Syntax

 fn gen_var(name: String) -> Syntax

Construct a variable reference syntax node.

gen_variant(name: String) -> Syntax

 fn gen_variant(name: String) -> Syntax

Construct a nullary enum variant name.

gen_variant_payload(name: String, payload_types: List(Syntax)) -> Syntax

 fn gen_variant_payload(name: String, payload_types: List(Syntax)) -> Syntax

Construct an enum variant name(payload_types...) carrying typed payloads.

generated_file(path: String, content: Syntax) -> GeneratedFile

 fn generated_file(path: String, content: Syntax) -> GeneratedFile

Construct a GeneratedFile entry pairing path with its Syntax tree content.

is_ascii_digit(cp: Int) -> Bool

 fn is_ascii_digit(cp: Int) -> Bool

is_ascii_lower(cp: Int) -> Bool

 fn is_ascii_lower(cp: Int) -> Bool

is_ascii_upper(cp: Int) -> Bool

 fn is_ascii_upper(cp: Int) -> Bool

is_ident_char(cp: Int) -> Bool

 fn is_ident_char(cp: Int) -> Bool

is_reserved_word(name: String) -> Bool

 fn is_reserved_word(name: String) -> Bool

Return true when name is a Cure reserved keyword.

lambda_params(names: List(String)) -> SynLit

 fn lambda_params(names: List(String)) -> SynLit

list_to_syntax(items: List(t), elem_fn: Function(t, Syntax)) -> Syntax

 fn list_to_syntax(items: List(t), elem_fn: Function(t, Syntax)) -> Syntax

Lift a List(t) into a list literal [...] using elem_fn for each element.

lower_cp(cp: Int) -> Int

 fn lower_cp(cp: Int) -> Int

map_to_syntax(items: List(t), f: Function(t, Syntax)) -> List(Syntax)

 fn map_to_syntax(items: List(t), f: Function(t, Syntax)) -> List(Syntax)

nil_binders(items: List(Syntax)) -> SynLit

 fn nil_binders(items: List(Syntax)) -> SynLit

option_to_syntax(opt: Option(t), elem_fn: Function(t, Syntax)) -> Syntax

 fn option_to_syntax(opt: Option(t), elem_fn: Function(t, Syntax)) -> Syntax

Lift an Option(t) into Some(<val>) or None() using elem_fn.

parse_expr(source: String) -> Result(Syntax, CodeGenError)

 fn parse_expr(source: String) -> Result(Syntax, CodeGenError)

Parse a single Cure expression string into a Syntax tree.

parse_source(source: String) -> Result(Syntax, CodeGenError)

 fn parse_source(source: String) -> Result(Syntax, CodeGenError)

Parse a Cure source string (module, declaration list, or expression) into a Syntax tree.

pascal_chars(chars: List(Char), cap_next: Bool) -> List(Char)

 fn pascal_chars(chars: List(Char), cap_next: Bool) -> List(Char)

put_attr(values: List(Attr), key: Atom, value: SynLit) -> List(Attr)

 fn put_attr(values: List(Attr), key: Atom, value: SynLit) -> List(Attr)

qualified_name(mod_name: String, fn_name: String) -> String

 fn qualified_name(mod_name: String, fn_name: String) -> String

render(syntax: Syntax) -> Result(String, CodeGenError)

 fn render(syntax: Syntax) -> Result(String, CodeGenError)

Render a Syntax tree to Cure source using the default 2-space indentation.

render_all(files: List(GeneratedFile)) -> Result(List(RenderedFile), CodeGenError)

 fn render_all(files: List(GeneratedFile)) -> Result(List(RenderedFile), CodeGenError)

Atomically render, format, and parse-verify every file in files, returning all RenderedFiles or the first error.

render_formatted(syntax: Syntax) -> Result(String, CodeGenError)

 fn render_formatted(syntax: Syntax) -> Result(String, CodeGenError)

Render and format a Syntax tree with Cure's canonical formatter.

render_formatted_with(syntax: Syntax, use_algebra: Bool) -> Result(String, CodeGenError)

 fn render_formatted_with(syntax: Syntax, use_algebra: Bool) -> Result(String, CodeGenError)

Render and format a Syntax tree. Pass true for the algebra formatter or false for the text formatter.

render_verified(syntax: Syntax) -> Result(String, CodeGenError)

 fn render_verified(syntax: Syntax) -> Result(String, CodeGenError)

Render, format, and parse-verify a Syntax tree, guaranteeing syntactically valid Cure output.

render_verified_with(syntax: Syntax, format: Bool) -> Result(String, CodeGenError)

 fn render_verified_with(syntax: Syntax, format: Bool) -> Result(String, CodeGenError)

Render a Syntax tree, optionally format it, and verify that it lexes and parses cleanly.

render_with_indent(syntax: Syntax, indent_spaces: Int) -> Result(String, CodeGenError)

 fn render_with_indent(syntax: Syntax, indent_spaces: Int) -> Result(String, CodeGenError)

Render a Syntax tree to Cure source with an explicit indentation width (spaces, clamped to 1..8).

repeat_dash(n: Int) -> String

 fn repeat_dash(n: Int) -> String

result_to_syntax(res: Result(t, e), ok_fn: Function(t, Syntax), err_fn: Function(e, Syntax)) -> Syntax

 fn result_to_syntax(res: Result(t, e), ok_fn: Function(t, Syntax), err_fn: Function(e, Syntax)) -> Syntax

Lift a Result(t, e) into Ok(<val>) or Error(<err>) using ok_fn and err_fn.

safe_ident(name: String) -> String

 fn safe_ident(name: String) -> String

Sanitize a foreign identifier into a valid Cure identifier, escaping reserved keywords with a trailing _.

sanitize_chars(chars: List(Char)) -> List(Char)

 fn sanitize_chars(chars: List(Char)) -> List(Char)

set_node_attr(node: Syntax, key: Atom, value: SynLit) -> Syntax

 fn set_node_attr(node: Syntax, key: Atom, value: SynLit) -> Syntax

snake_chars(chars: List(Char), prev_sep: Bool) -> List(Char)

 fn snake_chars(chars: List(Char), prev_sep: Bool) -> List(Char)

string_list(items: List(String)) -> SynLit

 fn string_list(items: List(String)) -> SynLit

to_pascal_case(name: String) -> String

 fn to_pascal_case(name: String) -> String

Convert a snake_case or kebab-case name into PascalCase.

to_snake_case(name: String) -> String

 fn to_snake_case(name: String) -> String

Convert a camelCase, PascalCase, or kebab-case name into snake_case.

to_syntax(value: t) -> Syntax

 fn to_syntax(value: t) -> Syntax

Convert value into its Cure Syntax representation.

upper_cp(cp: Int) -> Int

 fn upper_cp(cp: Int) -> Int

with_blank_before(node: Syntax) -> Syntax

 fn with_blank_before(node: Syntax) -> Syntax

Request a blank line before node inside a block or module body.

with_comment(node: Syntax, text: String) -> Syntax

 fn with_comment(node: Syntax, text: String) -> Syntax

Attach a # <text> leading comment above node (call repeatedly to stack lines).

with_decorator(node: Syntax, name: String, args: List(Syntax)) -> Syntax

 fn with_decorator(node: Syntax, name: String, args: List(Syntax)) -> Syntax

Attach a decorator @<name>(<args>) above node (call repeatedly to stack decorators).

with_doc(node: Syntax, text: String) -> Syntax

 fn with_doc(node: Syntax, text: String) -> Syntax

Attach a ## <text> doc comment above node.

with_guard(fn_node: Syntax, guard: Syntax) -> Syntax

 fn with_guard(fn_node: Syntax, guard: Syntax) -> Syntax

Attach a when <guard> clause to a function definition fn_node.

with_trailing_comment(node: Syntax, text: String) -> Syntax

 fn with_trailing_comment(node: Syntax, text: String) -> Syntax

Attach a trailing inline # <text> comment on the same line as node.