# @sanity/lezer-groq

> Lezer grammar for GROQ query language (CodeMirror 6)

Latest version **1.0.4** (published 2026-05-18) · MIT license · 0 weekly downloads

## Install

```sh
npm install @sanity/lezer-groq
pnpm add @sanity/lezer-groq
yarn add @sanity/lezer-groq
bun add @sanity/lezer-groq
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; has provenance.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2026-05-18 |
| First published | 2026-04-07 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM |
| Dependencies | 4 |
| Unpacked size | 22 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Provenance | attested (GitHub Actions) |
| Maintainers | sanity-svc.npm, sanity-io |

## Links

- npm: https://www.npmjs.com/package/@sanity/lezer-groq
- Repository: https://github.com/sanity-io/groq-syntax
- Homepage: https://github.com/sanity-io/groq-syntax#readme
- Issues: https://github.com/sanity-io/groq-syntax/issues
- npm.io page: https://npm.io/package/@sanity/lezer-groq

## Dependencies (4)

- [@lezer/lr](https://npm.io/package/@lezer/lr.md) ^1.0.0
- [@lezer/common](https://npm.io/package/@lezer/common.md) ^1.2.0
- [@lezer/highlight](https://npm.io/package/@lezer/highlight.md) ^1.0.0
- [@codemirror/language](https://npm.io/package/@codemirror/language.md) ^6.0.0

## Recent versions

- 1.0.4 (latest) — 2026-05-18
- 1.0.3 — 2026-04-07
- 1.0.2 — 2026-04-07

## README

# @sanity/lezer-groq

[Lezer](https://lezer.codemirror.net/) grammar for [GROQ](https://www.sanity.io/docs/groq), providing syntax highlighting, folding, and indentation for [CodeMirror 6](https://codemirror.net/).

## Install

```bash
npm install @sanity/lezer-groq
```

## Usage with CodeMirror

```ts
import {EditorView, basicSetup} from 'codemirror'
import {groq} from '@sanity/lezer-groq'

new EditorView({
  extensions: [basicSetup, groq()],
  parent: document.body,
})
```

## Exports

- `groq()` - returns a `LanguageSupport` instance with the GROQ parser, highlight tags, folding, and indentation configured
- `groqLanguage` - the raw `LRLanguage` instance for advanced configuration
- `parser` - the Lezer `LRParser` for 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:

```bash
pnpm build  # runs lezer-generator + rollup
```

## License

MIT

---
_Source: https://npm.io/package/@sanity/lezer-groq · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
