Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Pegen PEG Grammar HighlightingNew to Visual Studio Code? Get it now.
Pegen PEG Grammar Highlighting

Pegen PEG Grammar Highlighting

Lysandros Nikolaou

|
2,781 installs
| (0) | Free
Syntax highlighting for the PEG syntax that the pegen project uses
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Pegen PEG Grammar Highlighting

Syntax highlighting in VS Code for .gram files written in the PEG syntax used by pegen, the parser generator behind CPython's parser. It covers the full syntax used in CPython's Grammar/python.gram.

Screenshot

Features

  • Rule definitions, with return types (rule[asdl_stmt_seq*], rule[frozenset[str]]) and flags (rule[expr_ty] (memo))
  • Meta directives like @trailer, @subheader and @include, including triple-quoted blocks
  • Clickable @include paths: Cmd/Ctrl+Click opens the included file, resolved relative to the current .gram file
  • Go to Definition and Find All References for rules: Cmd/Ctrl+Click a rule to jump to its definition, or Shift+F12 to list every use. Rules defined in @included files are found too
  • Keywords and soft keywords: 'if' and "match" are highlighted differently
  • Tokens such as NAME, NEWLINE and ENDMARKER
  • Named items, including typed ones (a=expression, a[asdl_expr_seq*]=','.NAME+)
  • All PEG operators: alternatives |, lookaheads & / !, forced tokens &&, cut ~, quantifiers ? * +, gather s.e+, optional [...] and grouping (...)
  • Actions ({ ... }), including actions that span several lines or contain nested braces, plus strings, comments and numbers inside them
  • Comment toggling, bracket matching and auto-closing of brackets and quotes

Installation

Install Pegen PEG Grammar Highlighting from the VS Code Marketplace, or run:

code --install-extension lysnikolaou.pegen-peg

Any file with the .gram extension is then highlighted.

Development

  1. Clone this repository and run npm install.
  2. Open it in VS Code and press F5. This compiles the TypeScript in src/ in watch mode and starts an Extension Development Host with the extension loaded.
  3. Open a .gram file, e.g. CPython's Grammar/python.gram.

The grammar is in syntaxes/pegen.tmLanguage.json. To see which scope a token gets, run Developer: Inspect Editor Tokens and Scopes from the Command Palette. After you change the grammar, run Developer: Reload Window in the development host.

Releasing

Pushing a v* tag publishes the extension to the VS Code Marketplace and creates a GitHub release with the .vsix attached. The tag has to match the version in package.json.

  1. Bump version in package.json and add a section to CHANGELOG.md.

  2. Commit, then tag and push:

    git tag v0.4.0
    git push origin main v0.4.0
    

Known Issues

Code inside actions isn't highlighted as C or Python. Only strings, comments, numbers and NULL / True / False / None get highlighted there.

License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
  • Your Privacy Choices
  • Consumer Health Privacy
© 2026 Microsoft