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
Generate a VS Code language configuration from the grammar
gen-vscode-config.ts derives a language-configuration.json (comments, bracket
pairs, auto-closing/surrounding pairs, colorized brackets, autoCloseBefore,
folding markers, word pattern, indentation, and comment-continuation onEnter
rules) from the grammar's tokens and scopes. cli.ts emits it next to the
TextMate grammar; CI's gen-sync check covers both.
Comments, folding, the /** */ pair, brackets and auto-close all match VS Code's
hand-written TypeScript config; the remaining differences are control-flow
indentation that isn't derivable from a grammar.
A 'string' token flag lets string delimiters be derived rather than hardcoded,
so the generator stays language-agnostic (test/agnostic.ts guards it).
Copy file name to clipboardExpand all lines: README.md
+11-8Lines changed: 11 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,6 +23,7 @@ From one grammar definition (a small TypeScript combinator API):
23
23
-**A lexer** — tokenizes source straight from the grammar's token definitions; usable on its own (`createLexer(grammar).tokenize`).
24
24
-**A CST parser** — recursive descent + Pratt operator precedence on top of the lexer, producing a full-fidelity concrete syntax tree where every token is a node.
25
25
-**A TextMate grammar** — a `.tmLanguage.json` for editor syntax highlighting, derived from the same rules.
26
+
-**A VS Code language configuration** — a `language-configuration.json` (comments, bracket pairs, auto-closing/surrounding pairs, folding, indentation) for editor behavior.
26
27
27
28
## Results
28
29
@@ -143,20 +144,22 @@ Matching the official grammar *exactly* would, in cases like `transform`, make t
143
144
## Architecture
144
145
145
146
```
146
-
examples/typescript.ts one grammar (TypeScript combinator API)
147
+
examples/typescript.ts one grammar (TypeScript combinator API)
shared src/grammar-utils.ts structural helpers used across stages
156
-
src/api.ts, types.ts the grammar's combinator + type surface
158
+
shared src/grammar-utils.ts structural helpers used across stages
159
+
src/api.ts, types.ts the grammar's combinator + type surface
157
160
```
158
161
159
-
-**One grammar, three derived stages.**`gen-lexer` builds a tokenizer from the token definitions + lexer hints; `gen-parser` composes that lexer and interprets the rules to build a CST; `gen-tm` reads the same rule *shapes* to derive TextMate patterns. Shared structural primitives (`grammar-utils.ts`) — e.g. one keyword/punctuation predicate — keep them classifying tokens identically.
162
+
-**One grammar, many derived artifacts.**`gen-lexer` builds a tokenizer from the token definitions + lexer hints; `gen-parser` composes that lexer and interprets the rules to build a CST; `gen-tm` reads the same rule *shapes* to derive TextMate patterns; `gen-vscode-config` derives the editor config (comments, brackets, auto-close) from the same tokens and `scopes`. Shared structural primitives (`grammar-utils.ts`) — e.g. one keyword/punctuation predicate — keep them consistent.
160
163
-**CST, not AST.** The parser keeps every token (punctuation, keywords) as a node — required for the highlighter and for lossless source reconstruction. Roughly 2× the nodes of an AST, by design.
161
164
-**Every stage is language-agnostic.** All language specifics live in the grammar; lexer, parser and generator are generic, reusable runtimes.
0 commit comments