Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>GJS BNF Language SupportNew to Visual Studio Code? Get it now.
GJS BNF Language Support

GJS BNF Language Support

GJ Software

| (0) | Free
Full-featured BNF (Backus-Naur Form) language support: syntax highlighting, real-time validation, formatting, hover, go-to-definition, rename, find-references and AST viewer
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

GJS BNF Language for VS Code Support

Full-featured VS Code extension for Backus-Naur Form (BNF) grammar files (.bnf).


Features

Syntax Highlighting

Distinct colours for every element of a BNF grammar:

Element Example Colour
Rule definition <digit> on the LHS Blue bold
::= operator ::= Purple
\| alternation \| Purple
Non-terminal reference <digit> in a body Cyan
Terminal string "0" 'hello' Green
Optional [ ] [ ] Yellow
Repetition { } { } Red
Group ( ) ( ) Teal
Comment (* … *) Grey italic

Includes a dedicated BNF Dark colour theme.


Real-time Validation

Errors and warnings appear inline as you type and in the Problems panel.

Code Severity Description
BNF001 🔴 Error Duplicate rule definition
BNF002 🔴 Error Undefined non-terminal referenced
BNF003 🟡 Warning Rule defined but never referenced
BNF004 🟡 Warning Empty terminal string
BNF005 🟡 Warning Direct left recursion detected

Validation fires on open, on type (debounced, configurable), and on save.


Formatting

Trigger with Shift+Alt+F / ⇧⌥F, or enable editor.formatOnSave.

  • Aligns all ::= operators to the same column across all rules
  • Wraps long alternations onto multiple lines with indented |
  • Normalises terminal string quote style (double / single / preserve)
  • Adds a blank line between rules for readability

IntelliSense

Feature Shortcut Description
Hover tooltip hover Shows rule body + usage count
Go to Definition F12 Jumps to the rule that defines a non-terminal
Find All References Shift+F12 Lists every use of a non-terminal
Rename F2 Renames a rule and all its references atomically
Autocomplete type < Completes rule names; structural snippets
Outline Outline panel All rules in breadcrumb and symbol list

Commands

Command Shortcut Description
BNF: Validate Document Ctrl+Shift+V Run validation manually
BNF: Show AST Ctrl+Shift+A Open the live AST viewer panel
BNF: Show Rule Dependency Graph Ctrl+Shift+G Interactive Mermaid dependency graph
BNF: Copy Rule as Regex — Export rule under cursor as JS regex
BNF: Insert New Rule — Prompt for name, insert rule snippet
BNF: Format Document Shift+Alt+F Format the active file

Supported BNF Syntax

(* This is a comment *)
<rule>      ::= <other-rule> | "terminal" | 'terminal'
<optional>  ::= [ <rule> ]
<repeated>  ::= { <rule> }
<grouped>   ::= ( <rule> | "x" )

Snippets

Prefix Inserts
rule <name> ::= expression
opt [ expression ]
rep { expression }
grp ( expression )
cmt (* comment *)
digit Standard <digit> ::= "0" \| … \| "9"
letter Standard <letter> a-z rule
ident Standard <identifier> rule
integer Standard <integer> rule
ws Standard <whitespace> rules

Configuration

All settings are under gjsBnf.*:

Formatter (gjsBnf.format.*)

Setting Default Description
maxLineWidth 80 Max line width before wrapping alternatives
alignDefinitions true Align all ::= to the same column
indentAlternatives true Wrap alternatives with indented \|
quoteStyle "double" "double" / "single" / "preserve"

Validation (gjsBnf.validation.*)

Setting Default Description
enabled true Enable/disable all validation
onType true Validate while typing
onSave true Validate on save
debounceMs 400 Debounce delay in ms
warnUnusedRules true Warn on unused rules
warnEmptyTerminals true Warn on empty terminals

Hover (gjsBnf.hover.*)

Setting Default Description
enabled true Enable hover tooltips
showRuleBody true Include rule body in tooltip

Graph (gjsBnf.graph.*)

Setting Default Description
direction "LR" Graph direction: LR, TB, RL, BT
showTerminals false Include terminal nodes in graph

Installation

From VSIX

code --install-extension gjs-bnf-extension-1.0.0.vsix

Or via VS Code: Extensions → ··· → Install from VSIX

From source

git clone https://github.com/gjs/gjs-bnf-extension
cd gjs-bnf-extension
npm install
npm run compile
npm run package   # produces gjs-bnf-extension-1.0.0.vsix

Development

npm run watch        # compile in watch mode
npm run test:unit    # run unit tests
npm run lint         # ESLint
npm run format:fix   # Prettier

See CHANGELOG.md for version history.


License

MIT

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft