Skip to content

Commit ead6a3d

Browse files
committed
Read multi-scope leaves in the Monarch and tree-sitter generators
The prior commit gave YAML number/bool/null plain scalars a space-separated `string.unquoted constant.*` scope. The TextMate emitter wants the full chain, but a single Monarch token / tree-sitter capture wants the LEAF (the semantic type) — both `scopeToMonarch` and `scopeToCapture` matched the `string.` ancestor first and mis-mapped numbers/booleans to 'string' / @string. Extract the leaf of a space-separated scope before mapping; regenerate yaml.monarch.json. Refs #12
1 parent 547b019 commit ead6a3d

3 files changed

Lines changed: 67 additions & 60 deletions

File tree

src/gen-monarch.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ function delimStateSuffix(delim: string): string {
104104
// BOTH highlighters agree on roles while each speaks its engine's idiom. Driven
105105
// by scope PREFIXES — language-agnostic.
106106
function scopeToMonarch(scope: string): string {
107+
// A space-separated scope is `ancestor… leaf`; a single Monarch token wants the LEAF (the
108+
// semantic type), not the string ancestor that only supplies the TextMate chain.
109+
if (scope.includes(' ')) scope = scope.slice(scope.lastIndexOf(' ') + 1);
107110
if (scope.startsWith('comment')) return 'comment';
108111
if (scope.startsWith('string.regexp')) return 'regexp';
109112
if (scope.startsWith('string')) return 'string';

src/gen-treesitter.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -883,6 +883,10 @@ function buildGrammarJs(ctx: GrammarJsContext, grammarName: string): string {
883883
* not on specific keywords.
884884
*/
885885
function scopeToCapture(scope: string): string | null {
886+
// A space-separated scope is `ancestor… leaf` (e.g. `string.unquoted constant.numeric` for a
887+
// plain scalar that resolves to a number); a single tree-sitter capture wants the LEAF — the
888+
// semantic type — not the string ancestor that only supplies context for the TextMate chain.
889+
if (scope.includes(' ')) scope = scope.slice(scope.lastIndexOf(' ') + 1);
886890
// Ordered most-specific-first.
887891
const table: [string, string][] = [
888892
['comment.block.documentation', '@comment.documentation'],

0 commit comments

Comments
 (0)