Examples¶
Start from working code instead of the abstract API docs. Pegium ships four examples covering complementary aspects of the framework.
Overview¶
| Example | Highlights |
|---|---|
arithmetics |
compact language, evaluator, formatter, LSP |
domainmodel |
DomainModel DSL, structure-first AST, formatter, rename |
requirements |
multi-language workspace, references, richer scoping |
statemachine |
modeling DSL, validation, formatter, LSP |
Choose a starting point¶
arithmetics— the smallest end-to-end example.domainmodel— a DomainModel-style DSL with entities, nesting, and formatting rules.requirements— multiple related languages or files.statemachine— a graph- or state-oriented domain.
Practical advice¶
To reuse an example:
- Choose the closest domain shape.
- Keep the project structure and service wiring.
- Shrink the grammar and AST to your actual needs.
- Add back domain-specific validation, references, and formatting.
Read them as a progression in this order:
arithmetics— the smallest full parser-to-editor path.domainmodel— nested declarations, qualified names, and rename.statemachine— validation-heavy modeling.requirements— multiple related languages in one workspace.
Running them¶
After building the repository, each example exposes matching CLI and LSP entrypoints under ./build/examples/....
./build/examples/arithmetics/pegium-example-arithmetics-cli \
eval examples/arithmetics/example/example.calc
./build/examples/arithmetics/pegium-example-arithmetics-lsp
The arithmetics CLI takes an eval subcommand; the domainmodel, requirements, and statemachine CLIs take a generate subcommand instead. Run any CLI with no arguments to see its usage string.