@sanity/lezer-groq
v1.0.4
Published
Lezer grammar for GROQ query language (CodeMirror 6)
Readme
@sanity/lezer-groq
Lezer grammar for GROQ, providing syntax highlighting, folding, and indentation for CodeMirror 6.
Install
npm install @sanity/lezer-groqUsage with CodeMirror
import {EditorView, basicSetup} from 'codemirror'
import {groq} from '@sanity/lezer-groq'
new EditorView({
extensions: [basicSetup, groq()],
parent: document.body,
})Exports
groq()- returns aLanguageSupportinstance with the GROQ parser, highlight tags, folding, and indentation configuredgroqLanguage- the rawLRLanguageinstance for advanced configurationparser- the LezerLRParserfor direct access to the parse tables
What's in the box
The Lezer grammar is an incremental LR parser that handles the full GROQ expression language:
- Filters, projections, pipes, dereferences, dot access, array traversal
- All operators with correct precedence (pipe, logical, comparison, arithmetic, exponentiation)
- Function calls and namespaced function calls (
math::sum(),pt::text()) - String literals with escape sequence highlighting
- Keyword specialization (
true,false,null,in,match,asc,desc) - Code folding for filters, projections, arrays, and objects
- Auto-indentation and bracket closing
Build
The grammar source is src/groq.grammar. To regenerate the parser after editing:
pnpm build # runs lezer-generator + rollupLicense
MIT
