lezer-grammar

Write, debug, and integrate Lezer grammars for Liftosaur parsers and CodeMirror editors.

692|107|Updated Feb 29, 2020
One-click install
npx skills add https://github.com/astashov/liftosaur --skill lezer-grammar
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: lezer-grammar
Source: https://github.com/astashov/liftosaur/tree/main/.claude/skills/lezer-grammar
Command: npx skills add https://github.com/astashov/liftosaur --skill lezer-grammar

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill requires @lezer/generator, @lezer/lr, @lezer/common, @lezer/highlight, @codemirror/language.

What problem does it solve?

Writing Lezer grammars involves tricky concepts like token precedence, shift/reduce conflicts, and tree traversal patterns. This Skill provides a complete reference and workflow for creating, compiling, and integrating .grammar files in the Liftosaur codebase without trial-and-error debugging.

Core Features & Use Cases

  • Grammar Authoring: Full Lezer syntax reference covering rules, tokens, precedence, @skip, @specialize, external tokens, and dialects.
  • Build & Integration: Commands to compile .grammar files with lezer-generator, plus patterns for evaluators, NodeName enums, and error handling with line/offset info.
  • CodeMirror & Highlighting: Instructions for LRLanguage definitions, styleTags mappings, HTML highlighting via highlightTree, and nested parsing with parseMixed.
  • Use Case: You need to add a new workout notation to the planner. Use this Skill to write the grammar rules, regenerate the parser with npm run grammar:planner, update the PlannerNodeName enum, and wire up syntax highlighting.

Quick Start

Write a Lezer grammar for parsing workout notes with dates and exercise names, then show me how to compile it and traverse the parse tree.

Frequently Asked Questions about lezer-grammar

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I write a Lezer grammar for a custom language?▼

Define a @top rule, add context-free rules for tree structure, and declare lexical tokens in a @tokens block. Use @skip for whitespace, @precedence for conflicts, then compile with lezer-generator --output parser.ts your.grammar.

How to fix shift/reduce conflicts in Lezer grammars?▼

Shift/reduce conflicts mean the grammar is ambiguous at the rule level. Restructure the rules or add rule-level @precedence with !markers in the conflicting rules, using @left or @right to set associativity.

How do I add syntax highlighting to a Lezer parser in CodeMirror?▼

Configure the parser with styleTags mapping node names to @lezer/highlight tags, then wrap it in LRLanguage.define from @codemirror/language. Selectors like "SetPart/..." apply tags recursively to descendants.

Why does my Lezer grammar fail with overlapping tokens error?▼

Overlapping tokens occur when multiple tokens can match the same text at the same position. Add an @precedence block inside @tokens listing the conflicting tokens in priority order, since earlier entries win.

Can Lezer embed one language inside another grammar?▼

Yes, use parseMixed from @lezer/common to nest parsers. Capture the embedded region as a single token in the outer grammar, then return the inner parser for matching nodes, as Liftosaur does for Liftoscript blocks.