Pegium Mental Model¶
This page gives a quick concept mapping for readers who want a high-level mental model before diving into Pegium-specific APIs.
Concept mapping¶
| General concept | Pegium concept |
|---|---|
| Grammar rules | Terminal<T>, Rule<T>, Infix<...> |
| AST nodes | pegium::AstNode subclasses |
| CST helpers | pegium::CstNodeView and pegium::CstUtils |
| Validation registry | pegium::validation::ValidationRegistry |
| Scope provider | pegium::references::ScopeProvider |
| Formatter | pegium::AbstractFormatter |
| Default LSP providers | pegium::Services::lsp |
Main differences¶
- Pegium grammars are written in C++ expressions instead of external grammar files.
- Pegium uses a PEG-based parser DSL as the foundation of the grammar layer.
- C++ types and member pointers are used directly for AST construction and formatter selections.
- Service composition happens through the Pegium services layer and explicit registration APIs.
How to translate your intuition¶
If you are used to language tooling frameworks:
- think of
PegiumParsersubclasses as the place where grammar structure lives - think of
Rule<T>andTerminal<T>as Pegium's named grammar rules and terminals - think of
AstNodestructs as the semantic node types of your language - think of
reference<T>plus linker/scope services as the reference pipeline - think of
AbstractFormatterandValidationRegistryas close conceptual equivalents of formatter and validation registries
The biggest mental shift is that grammar and language services are ordinary C++ code. You get stronger type coupling with the AST, but less of the declarative grammar-file feel.
What stays pleasantly similar¶
Even with the different implementation language, the workflow remains familiar:
- define the grammar
- shape the AST
- compute scopes and link references
- validate semantics
- add formatting and editor features
Recommended reading path¶
If you want the fastest orientation path, start with:
- Write the Grammar
- Resolve Cross-References
- Create Validations
- Add Formatting and LSP Services
- LSP Services
Then keep Reference nearby for the precise service and document-model terminology.