Tutorial 1: Hello World DSL¶
Build the smallest possible Capy library: one function, one template, nothing else. Estimated time: 5 minutes.
Goal¶
Write a Capy library so this source:
Produces this output:
Step 1 — scaffold¶
You now have lib.capy, script.capy, and README.md.
Step 2 — define the function¶
Open lib.capy. Replace it with:
What this says:
- One function named
greet. - One
arg— a capture namedname, accepting any value. - Because there are zero
arg literallines, the engine auto-prepends the function name (greet) as a leading literal. So the surface shape isgreet <any>. - The function body
writesHello, <name>!\nper match. The newline inside the backtick literal is exactly what gets emitted.
Step 3 — write the source¶
Replace script.capy with:
Step 4 — run it¶
Output:
Step 5 — what just happened¶
The lexer tokenized each line into greet + "Alice". The parser
matched against the greet function shape, captured the name, and the
evaluator interpolated ${name} as "Alice" (note: the source text
includes the quotes because the input is a quoted string literal).
Try it¶
- Change the write to
write `hi ${name}\n`. Re-run. Output updates. - Add a second function
shoutthat emits uppercase using theupperhelper:write `${upper name}\n`. - Try invalid input:
greet(no argument) → see the structured error.
Next¶
Tutorial 2: Building a config DSL introduces types, context accumulation, and the file template.