Pegium is a language engineering toolkit for C++20 with built-in support for parsing, AST/CST construction, references, validation, formatting, and language-server features.
Pegium is strongly inspired by Langium, and many of the core concepts are intentionally similar. The main difference is that Pegium centers on a PEG-based parser DSL in C++, instead of Langium's TypeScript grammar and parser stack.
- Semantics First: Pegium lets you shape the semantic model of your language directly through C++ AST types plus grammar assignments, while still keeping CST data available for source-aware tooling.
- Explicit Services, Customizable by Design: Pegium exposes parser, scoping, validation, workspace, formatting, and LSP behavior through visible service objects instead of hiding the wiring behind heavy code generation.
- Parser to Editor in One Toolkit: The same document model supports parsing, linking, diagnostics, formatting, completion, rename, references, and other editor features.
Open the repository root in VS Code, go to Run and Debug, pick one of
Run Arithmetics Extension, Run DomainModel Extension,
Run Requirements Extension, or Run Statemachine Extension, then press
F5.
On the first launch, VS Code runs the matching Prepare ... Extension task for
you: it configures CMake, builds the example language server, installs the
extension dependencies if needed, and compiles the VS Code extension.
VS Code then opens a new Extension Development Host window on the corresponding example workspace, so you can immediately try the language features on the shipped sample files.
If you are new to the project, the best documentation entry points are:
You can find the Pegium documentation on the documentation website.
The documentation is organized into several sections:
- Introduction: what Pegium is, why it exists, and how it relates to Langium
- Learn: the recommended workflow for building a language with Pegium
- Recipes: targeted guides for customization tasks such as scoping, validation, caching, and multiple languages
- Reference: canonical documentation for grammar, services, semantic model, and document lifecycle
- Examples: the shipped example languages and what each one demonstrates
The documentation sources live in docs/ in this repository.
Pegium ships several end-to-end examples in this repository:
- arithmetics: a compact expression language with evaluator, formatter, CLI, and LSP server
- DomainModel: a modeling DSL with qualified names, formatter rules, and rename support
- requirements: a multi-language example showing shared workspace behavior and cross-language references
- statemachine: a modeling language that emphasizes validation and editor integration
Pegium is MIT licensed (c) 2024-2026 Yannick Daveluy.