Examples¶
Pegium ships four examples that cover complementary aspects of the framework.
Use this section when you want to start from working code rather than from the abstract API documentation.
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¶
- Use
arithmeticsif you want the smallest end-to-end example. - Use
domainmodelif you want a DomainModel-style DSL with entities, nesting, and formatting rules. - Use
requirementsif you need multiple related languages or files. - Use
statemachineif your domain is graph- or state-oriented.
How to use the examples¶
The best way to reuse an example is usually:
- 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
Running them¶
After building the repository, each example exposes matching CLI and LSP
entrypoints under ./build/examples/....
For a quick first pass:
./build/examples/arithmetics/pegium-example-arithmetics-cli \
examples/arithmetics/example/example.calc
./build/examples/arithmetics/pegium-example-arithmetics-lsp
A good reading order¶
If you want to understand the examples as a progression rather than as isolated projects, a useful order is:
arithmeticsfor the smallest full parser-to-editor pathdomainmodelfor nested declarations, qualified names, and renamestatemachinefor validation-heavy modelingrequirementsfor multiple related languages in one workspace