You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .agents/skills/grammar-sync-update/SKILL.md
+123-8Lines changed: 123 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -2,37 +2,53 @@
2
2
name: grammar-sync-update
3
3
description: >
4
4
Use this skill when a grammar sync PR has landed (updating src/parser/antlr/) and a follow-up PR
5
-
is needed to wire a new ES|QL command into the AST layer. Covers all 7 files that need changes
6
-
and the exact patterns to follow.
5
+
is needed to wire a new ES|QL command or update an existing one in the AST layer. Covers all files
6
+
that need changes and the exact patterns to follow for both new and existing commands.
7
7
---
8
8
9
9
# Grammar Sync Update
10
10
11
11
## When to use
12
12
13
-
After the automated grammar sync bot merges a PR that adds a **new command**, run this skill to produce the follow-up wiring PR.
13
+
After the automated grammar sync bot merges a PR, this skill covers two scenarios:
14
+
15
+
**Scenario A — New command** (7 files to change): A brand-new `xxxCommand` rule appeared in the grammar with no handler anywhere in the TypeScript layer.
16
+
17
+
**Scenario B — Existing command update** (1–3 files to change): An existing command's grammar rule gained a new option, new labeled field, or new sub-rule (e.g. `CHANGE_POINT` gained `BY`, `WHERE IN` gained subquery support).
14
18
15
19
**You do NOT need this skill when:**
16
20
- The grammar sync PR only updated ANTLR-generated files with no new grammar rules (`.ts`, `.interp`, `.tokens` only) — those are handled automatically.
17
21
18
22
**You DO need this skill when:**
19
-
- A new `xxxCommand` rule appears in `src/parser/antlr/esql_parser.g4` with no corresponding `fromXxxCommand()` in `cst_to_ast_converter.ts`.
20
-
- The `esql_parser_listener.ts` has new `enterXxxCommand` / `exitXxxCommand` entries with no converter handler.
23
+
- A new `xxxCommand` rule appears in `src/parser/antlr/esql_parser.g4` with no corresponding `fromXxxCommand()` in `cst_to_ast_converter.ts`. → **Use Scenario A below.**
24
+
- The `esql_parser_listener.ts` has new `enterXxxCommand` / `exitXxxCommand` entries with no converter handler. → **Use Scenario A below.**
25
+
- An existing command's grammar rule changed (new context method, new labeled alternative, new keyword option) and the converter no longer covers it. → **Use Scenario B below.**
21
26
22
27
## How to detect what changed
23
28
24
29
```bash
25
-
# Find new command rules added in the grammar sync commit
@@ -258,6 +274,105 @@ Reference test files: `src/parser/__tests__/user_agent.test.ts`, `src/parser/__t
258
274
-[ ]`yarn build` passes (no TypeScript errors)
259
275
-[ ]`yarn lint` passes
260
276
277
+
---
278
+
279
+
## Scenario B — Existing command update
280
+
281
+
The grammar changed an **existing** command's rule: it gained a new option keyword (`BY`, `WITH`, `AS`), a new labeled alternative (`_newField`), or a new sub-rule. The converter method already exists — you only need to extend it.
282
+
283
+
### Files to change
284
+
285
+
#### `src/parser/core/cst_to_ast_converter.ts`
286
+
287
+
Find the existing `fromXxxCommand()` method and add handling for what's new.
288
+
289
+
**New keyword option** (e.g. `CHANGE_POINT … BY field1, field2`):
// ← add new field only if consumers need typed access
336
+
}
337
+
```
338
+
339
+
Skip this if the new option is only accessible via generic `args` — that's fine for options that don't need first-class API access.
340
+
341
+
#### Tests
342
+
343
+
Always update or add tests. For an existing command update, add to the existing test file (`src/parser/__tests__/xxx.test.ts`) rather than creating a new one.
344
+
345
+
Cover:
346
+
1. The new option/field parses correctly
347
+
2. The AST shape is correct (`toMatchObject`)
348
+
3. The pretty-printer round-trips the new syntax
349
+
4. Walker traversal visits any new nodes (if the new option introduces new AST nodes)
350
+
351
+
**Real example — `CHANGE_POINT BY`** (PR #104):
352
+
- Added 21 lines to `change_point.test.ts`
353
+
- Added 14 lines to `fromChangePointCommand()` in `cst_to_ast_converter.ts`
354
+
- No `types.ts` change (BY option fits in generic `args`)
355
+
- No visitor changes
356
+
357
+
**Real example — `WHERE IN` subquery** (PR #107):
358
+
- Refactored `fromLogicalIn()` in `cst_to_ast_converter.ts` into smaller methods + added subquery branch
359
+
- Added tests to `src/parser/__tests__/function.test.ts` and `src/ast/walker/__tests__/walker.test.ts`
360
+
- Added pretty-printer tests to 4 existing test files
361
+
- No `types.ts` or visitor changes (subquery uses existing `ESQLParens` type)
362
+
363
+
### Checklist — Scenario B (existing command update)
0 commit comments