Skip to content

Latest commit

 

History

History
82 lines (57 loc) · 1.79 KB

File metadata and controls

82 lines (57 loc) · 1.79 KB

Arithmetics

This example is the smallest end-to-end Pegium language in the repository.

It is a good starting point when you want to understand the full path from grammar to CLI and language server without first dealing with a large semantic model.

What it shows

  • a parser for the .calc language
  • an evaluator for arithmetic expressions
  • validation and formatting
  • a stdio LSP server for arithmetics
  • a VS Code client for interactive testing

Use this example when

  • your language is expression-heavy
  • you need precedence and associativity
  • you want to study Infix rules
  • you want the most compact full-stack Pegium example

Build

From the repository root:

cmake -S . -B build
cmake --build build

Run the CLI

./build/examples/arithmetics/pegium-example-arithmetics-cli \
  eval examples/arithmetics/example/example.calc

Run the LSP server

./build/examples/arithmetics/pegium-example-arithmetics-lsp

Run the VS Code client

1. Build the C++ server

cmake -S . -B build
cmake --build build

2. Install and compile the extension side

cd examples/arithmetics
npm install
npm run compile

3. Start the extension in VS Code

  • Open the repository root in VS Code.
  • Go to Run and Debug.
  • Start Run Arithmetics Extension with F5.

The launch configuration lives in the repository root .vscode/launch.json and opens an Extension Development Host on examples/arithmetics/example.

If the server binary is not found automatically, set either:

  • the pegium.arithmetics.serverPath setting
  • the PEGIUM_ARITHMETICS_SERVER environment variable

Where to go next