Developer Tools
vmacro
Expands expression macros in source text before the compiler sees it.
Released v1.0.0 · 2026-09-28use "stdlib/macro.ven"
Expression level, source to source macro expansion, applied to Venutian source text before it reaches the real compiler, built on the language's own text and pattern matching builtins rather than a new compiler stage. A macro rewrites one pattern of source text into another before compilation, not after it.
print MacroDef("square", ["x"], "(x) * (x)")
Reference (8 functions)
API reference
parse_macro_defs(source_text)
Scans source_text for every ::macro name(params) => body line.
parse_macro_defs("::macro square(x) => (x) * (x)")parse_one_macro_def(line, defs)
Parses one already-detected ::macro name(params) => body line into defs.
parse_one_macro_def("::macro double(x) => (x) + (x)", new_map())split_top_level(text)
Splits text on top-level commas, ignoring commas nested inside parens, brackets, or a string.
split_top_level("a, f(b, c), d")find_matching_paren(text, open_index)
Finds the index of the ) that closes the ( at open_index in text.
find_matching_paren("square(5)", 6)substitute_params(def_, call_args)
Substitutes every one of def_s parameters inside its body with its matching call argument.
substitute_params(MacroDef("square", ["x"], "(x) * (x)"), ["5"])expand_one_pass(line, defs)
Expands the single, earliest macro call found in line, once.
expand_one_pass("y = square(5)", parse_macro_defs("::macro square(x) => (x) * (x)"))expand_line(line, defs)
Repeatedly expands macro calls in line until none remain.
expand_line("y = double_square(3)", parse_macro_defs("::macro square(x) => (x) * (x)\n::macro double_square(x) => square(x) + square(x)"))expand_macros(source_text)
Parses every ::macro definition out of source_text, then expands every call site.
expand_macros("::macro square(x) => (x) * (x)\nmake main()\n print square(5)")