@gram-data/tree-sitter-gram 0.3.3 → 0.3.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bindings/node/binding_test.js +18 -19
- package/editors/zed/README.md +30 -13
- package/editors/zed/extension.toml +3 -3
- package/editors/zed/languages/gram/highlights.scm +54 -13
- package/editors/zed/languages/gram/indents.scm +14 -0
- package/editors/zed/languages/gram/injections.scm +29 -0
- package/editors/zed/languages/gram/locals.scm +37 -0
- package/grammar.js +13 -4
- package/package.json +1 -1
- package/prebuilds/darwin-arm64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/darwin-x64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/linux-arm64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/linux-x64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/win32-arm64/@gram-data+tree-sitter-gram.node +0 -0
- package/prebuilds/win32-x64/@gram-data+tree-sitter-gram.node +0 -0
- package/queries/highlights.scm +54 -13
- package/queries/indents.scm +14 -0
- package/queries/injections.scm +29 -0
- package/queries/locals.scm +37 -0
- package/src/grammar.json +83 -5
- package/src/node-types.json +60 -24
- package/src/parser.c +1846 -2060
- package/tree-sitter-gram.wasm +0 -0
- package/tree-sitter.json +5 -4
|
@@ -8,30 +8,29 @@ test("can load grammar", () => {
|
|
|
8
8
|
assert.doesNotThrow(() => parser.setLanguage(require(".")));
|
|
9
9
|
});
|
|
10
10
|
|
|
11
|
-
test("
|
|
11
|
+
test("parses a simple node pattern", () => {
|
|
12
12
|
const Parser = require("tree-sitter");
|
|
13
13
|
const GramLang = require(".");
|
|
14
14
|
const parser = new Parser();
|
|
15
15
|
parser.setLanguage(GramLang);
|
|
16
16
|
|
|
17
|
-
const
|
|
17
|
+
const tree = parser.parse("(a)");
|
|
18
|
+
const pattern = tree.rootNode.child(0);
|
|
19
|
+
assert(pattern, "root should have a pattern child");
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
21
|
+
// Find the symbol 'a' in the pattern
|
|
22
|
+
function findSymbol(node, text) {
|
|
23
|
+
if (node.isNamed && node.type === "symbol" && node.text === text) {
|
|
24
|
+
return node;
|
|
25
|
+
}
|
|
26
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
27
|
+
const result = findSymbol(node.child(i), text);
|
|
28
|
+
if (result) return result;
|
|
29
|
+
}
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
27
32
|
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
assert(
|
|
31
|
-
const annotations2 = ap2.childForFieldName("annotations");
|
|
32
|
-
assert(annotations2, "annotations node should exist");
|
|
33
|
-
const first2 = annotations2.child(0);
|
|
34
|
-
assert.strictEqual(first2?.type, "property_annotation", "@ form should be property_annotation");
|
|
35
|
-
assert(first2?.childForFieldName("key"), "property_annotation should have key field");
|
|
36
|
-
assert(first2?.childForFieldName("value"), "property_annotation should have value field");
|
|
33
|
+
const symbol = findSymbol(pattern, "a");
|
|
34
|
+
assert(symbol, "pattern should contain symbol 'a'");
|
|
35
|
+
assert.strictEqual(symbol.type, "symbol");
|
|
37
36
|
});
|
package/editors/zed/README.md
CHANGED
|
@@ -115,27 +115,44 @@ To work on this extension:
|
|
|
115
115
|
|
|
116
116
|
```
|
|
117
117
|
editors/zed/
|
|
118
|
-
├── extension.toml
|
|
119
|
-
├── grammars/
|
|
120
|
-
│ └── tree-sitter-gram/ # Grammar files
|
|
121
|
-
│ ├── grammar.js # Tree-sitter grammar definition
|
|
122
|
-
│ └── src/ # Generated parser source
|
|
118
|
+
├── extension.toml # Extension metadata; points at grammar repo (repository + rev)
|
|
123
119
|
├── languages/
|
|
124
120
|
│ └── gram/
|
|
125
|
-
│ ├── config.toml #
|
|
126
|
-
│
|
|
127
|
-
│
|
|
128
|
-
|
|
121
|
+
│ ├── config.toml # Zed language config (brackets, suffixes, etc.)
|
|
122
|
+
│ ├── highlights.scm # → ../../../../queries/ (symlink; edit queries/ in repo root)
|
|
123
|
+
│ ├── indents.scm
|
|
124
|
+
│ ├── locals.scm
|
|
125
|
+
│ └── injections.scm
|
|
126
|
+
├── test.gram # Example file for testing
|
|
127
|
+
└── .gitignore # Ignores grammars/ (populated by Zed from extension.toml)
|
|
129
128
|
```
|
|
130
129
|
|
|
130
|
+
Query files (`.scm`) in `languages/gram/` are symlinks to the canonical `queries/` directory at the repo root. Edit `queries/*.scm` there; do not edit the copies under `editors/zed` directly. Running `scripts/prepare-zed-extension.sh` copies `queries/*.scm` into this directory (e.g. for distribution) and updates extension version/rev.
|
|
131
|
+
|
|
132
|
+
The `grammars/` directory is created by Zed when it loads the extension (it clones the grammar from the URL in `extension.toml`). It is gitignored. If you see a nested `editors/zed/grammars/gram/...` path, that is the cloned repo inside Zed’s cache; you can ignore or delete `editors/zed/grammars/` locally.
|
|
133
|
+
|
|
134
|
+
### Keeping the grammar revision in sync
|
|
135
|
+
|
|
136
|
+
The extension pins the tree-sitter-gram grammar with `repository` and `rev` in `extension.toml`. Zed uses that to fetch and build the parser. To keep it aligned with the latest version:
|
|
137
|
+
|
|
138
|
+
| Goal | Command | What it does |
|
|
139
|
+
|------|---------|---------------|
|
|
140
|
+
| **Local testing** | `npm run zed:dev` | Sets `repository = "file://<repo-root>"` and `rev = HEAD`. Zed uses your local clone at the current commit, so you can test grammar/query changes without pushing. |
|
|
141
|
+
| **Prepare for publish** | `npm run zed:publish` | Sets `repository` to the public GitHub URL (from `package.json`) and `rev = HEAD`. Run this before committing a release so the published extension points at the correct commit on GitHub. |
|
|
142
|
+
|
|
143
|
+
After either command, `extension.toml` is updated in place. For local dev you typically don’t commit that change (so the repo keeps a rev that matches the last release). For a release, run `zed:publish`, then commit and push so the extension and the tagged release stay aligned.
|
|
144
|
+
|
|
145
|
+
**If Zed shows an old version (e.g. 0.1.11) after installing the dev extension:** Zed may be using a cached clone of the grammar (at an old rev) or an older copy of the extension. Try: (1) Uninstall the Gram extension from Zed’s Extensions panel. (2) Delete the grammar cache: remove `editors/zed/grammars/` if it exists (Zed recreates it when needed). (3) Run `npm run zed:dev` again so `extension.toml` has the current version and rev. (4) In Zed, run “Install Dev Extension” and select `editors/zed` again. Restart Zed and recheck the extension version.
|
|
146
|
+
|
|
131
147
|
## Contributing
|
|
132
148
|
|
|
133
149
|
Contributions are welcome! Please see the main [repository](https://github.com/gram-data/tree-sitter-gram) for contribution guidelines.
|
|
134
150
|
|
|
135
|
-
To improve syntax highlighting:
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
151
|
+
To improve syntax highlighting and editor behavior:
|
|
152
|
+
|
|
153
|
+
1. Edit the canonical query files under `queries/` at the repo root (e.g. `queries/highlights.scm`).
|
|
154
|
+
2. The extension uses those via symlinks in `languages/gram/`; run `scripts/prepare-zed-extension.sh` if you need to copy them for distribution.
|
|
155
|
+
3. Test with various Gram files, then submit a pull request.
|
|
139
156
|
|
|
140
157
|
## License
|
|
141
158
|
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
id = "gram"
|
|
2
2
|
name = "Gram Language Support"
|
|
3
|
-
version = "0.3.
|
|
3
|
+
version = "0.3.5"
|
|
4
4
|
schema_version = 1
|
|
5
5
|
authors = ["Gram Data Contributors"]
|
|
6
|
-
description = "Support for Gram notation -
|
|
6
|
+
description = "Support for Gram notation - composable data patterns"
|
|
7
7
|
|
|
8
8
|
# path = "grammars/tree-sitter-gram"
|
|
9
9
|
[grammars.gram]
|
|
10
10
|
repository = "https://github.com/gram-data/tree-sitter-gram"
|
|
11
|
-
rev = "
|
|
11
|
+
rev = "869488b6bbea325b4c4153a7a6bee97df7931a58"
|
|
@@ -12,9 +12,58 @@
|
|
|
12
12
|
; Boolean literals
|
|
13
13
|
(boolean_literal) @boolean
|
|
14
14
|
|
|
15
|
-
;
|
|
15
|
+
; Comment (FR-003)
|
|
16
|
+
(comment) @comment
|
|
17
|
+
|
|
18
|
+
; Tagged-string tag distinct from content (FR-002)
|
|
19
|
+
(tagged_string tag: (symbol) @attribute)
|
|
20
|
+
|
|
21
|
+
; Reference identifier: pattern_reference (FR-001)
|
|
22
|
+
(pattern_reference identifier: (_) @variable)
|
|
23
|
+
|
|
24
|
+
; Symbols and identifiers (generic; definition/reference/tag captured above)
|
|
16
25
|
(symbol) @variable
|
|
17
26
|
|
|
27
|
+
; Definition-like identifiers and labels (FR-001): @type
|
|
28
|
+
; These must come AFTER generic symbol rule to take priority
|
|
29
|
+
|
|
30
|
+
; Labels (symbols and quoted names in labels nodes)
|
|
31
|
+
(labels (symbol) @type)
|
|
32
|
+
(labels (quoted_name) @type)
|
|
33
|
+
|
|
34
|
+
; Annotation identifiers and labels
|
|
35
|
+
(identified_annotation identifier: (_) @type)
|
|
36
|
+
(identified_annotation labels: (labels (symbol) @type))
|
|
37
|
+
(identified_annotation labels: (labels (quoted_name) @type))
|
|
38
|
+
|
|
39
|
+
; Subject, node, and relationship pattern definitions (FR-001): @type
|
|
40
|
+
; subject/node subject is _subject (use wildcard _ as it may be hidden in some runtimes)
|
|
41
|
+
(subject_pattern subject: (_ identifier: (_) @type))
|
|
42
|
+
(subject_pattern subject: (_ labels: (labels (symbol) @type)))
|
|
43
|
+
(subject_pattern subject: (_ labels: (labels (quoted_name) @type)))
|
|
44
|
+
(node_pattern subject: (_ identifier: (_) @type))
|
|
45
|
+
(node_pattern subject: (_ labels: (labels (symbol) @type)))
|
|
46
|
+
(node_pattern subject: (_ labels: (labels (quoted_name) @type)))
|
|
47
|
+
(relationship_pattern left: (node_pattern subject: (_ identifier: (_) @type)))
|
|
48
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (symbol) @type))))
|
|
49
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (quoted_name) @type))))
|
|
50
|
+
(relationship_pattern right: (node_pattern subject: (_ identifier: (_) @type)))
|
|
51
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (symbol) @type))))
|
|
52
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (quoted_name) @type))))
|
|
53
|
+
; Arrow kind: subject is inside optional brackets on the arrow
|
|
54
|
+
(relationship_pattern kind: (right_arrow subject: (_ identifier: (_) @type)))
|
|
55
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
56
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
57
|
+
(relationship_pattern kind: (left_arrow subject: (_ identifier: (_) @type)))
|
|
58
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
59
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
60
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ identifier: (_) @type)))
|
|
61
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
62
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
63
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ identifier: (_) @type)))
|
|
64
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
65
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
66
|
+
|
|
18
67
|
; Keywords and operators
|
|
19
68
|
[
|
|
20
69
|
"@"
|
|
@@ -40,22 +89,14 @@
|
|
|
40
89
|
|
|
41
90
|
; Field names in records and maps
|
|
42
91
|
(record_property key: (symbol) @property)
|
|
43
|
-
(record_property key: (
|
|
44
|
-
(record_property key: (
|
|
92
|
+
(record_property key: (quoted_name) @property)
|
|
93
|
+
(record_property key: (double_quoted_name) @property)
|
|
45
94
|
(map_entry key: (symbol) @property)
|
|
46
|
-
(map_entry key: (
|
|
47
|
-
(map_entry key: (
|
|
95
|
+
(map_entry key: (quoted_name) @property)
|
|
96
|
+
(map_entry key: (double_quoted_name) @property)
|
|
48
97
|
|
|
49
98
|
; Annotation keys (property-style) and headers (identified/label-style)
|
|
50
99
|
(property_annotation key: (symbol) @attribute)
|
|
51
|
-
(identified_annotation identifier: (_) @attribute)
|
|
52
|
-
(identified_annotation labels: (_) @attribute)
|
|
53
|
-
|
|
54
|
-
; Subject Pattern notation (special highlighting)
|
|
55
|
-
(subject_pattern) @type
|
|
56
|
-
|
|
57
|
-
; Node with labels
|
|
58
|
-
(node_pattern (labels (symbol) @type))
|
|
59
100
|
|
|
60
101
|
; Relationship arrows (special highlighting for graph syntax)
|
|
61
102
|
(relationship_pattern) @keyword
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
; Indentation: 2 spaces per level for brackets and multi-line structures
|
|
2
|
+
; FR-007 — specs/004-editor-improvements/contracts/indents.md
|
|
3
|
+
|
|
4
|
+
; Record {}
|
|
5
|
+
"{" @indent
|
|
6
|
+
"}" @indent.end
|
|
7
|
+
|
|
8
|
+
; Subject pattern []
|
|
9
|
+
"[" @indent
|
|
10
|
+
"]" @indent.end
|
|
11
|
+
|
|
12
|
+
; Node pattern ()
|
|
13
|
+
"(" @indent
|
|
14
|
+
")" @indent.end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
; Language injection for tagged strings: tag`content` and ```tag\ncontent\n```
|
|
2
|
+
;
|
|
3
|
+
; The tag symbol is used as the injection language so that downstream and editors
|
|
4
|
+
; can support arbitrary tags without changing the grammar. Well-known tags (md, ts,
|
|
5
|
+
; date, datetime, time, sql, json, html, etc.) are documented in docs/tagged-strings-and-injections.md.
|
|
6
|
+
;
|
|
7
|
+
; Overrides below map tags that do not match common parser names. The final
|
|
8
|
+
; rule uses the tag's text as the language name for all other tags (e.g. "sql",
|
|
9
|
+
; "json", "html" often match parser names).
|
|
10
|
+
|
|
11
|
+
; md -> markdown
|
|
12
|
+
(tagged_string
|
|
13
|
+
tag: (symbol) @_tag
|
|
14
|
+
content: (string_content) @injection.content)
|
|
15
|
+
(#eq? @_tag "md")
|
|
16
|
+
(#set! injection.language "markdown")
|
|
17
|
+
|
|
18
|
+
; ts -> typescript
|
|
19
|
+
(tagged_string
|
|
20
|
+
tag: (symbol) @_tag
|
|
21
|
+
content: (string_content) @injection.content)
|
|
22
|
+
(#eq? @_tag "ts")
|
|
23
|
+
(#set! injection.language "typescript")
|
|
24
|
+
|
|
25
|
+
; Dynamic: use tag text as language name for all other tags (sql, json, html, etc.)
|
|
26
|
+
; Editors may map additional tags (e.g. date, datetime, time) to parsers or leave as plain.
|
|
27
|
+
(tagged_string
|
|
28
|
+
tag: (symbol) @injection.language
|
|
29
|
+
content: (string_content) @injection.content)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
; Locals: go to definition and highlight references (file scope)
|
|
2
|
+
; FR-005, FR-006 — specs/004-editor-improvements/contracts/locals.md
|
|
3
|
+
|
|
4
|
+
; File scope: all definitions and references in one scope
|
|
5
|
+
(gram_pattern) @local.scope
|
|
6
|
+
|
|
7
|
+
; Definitions: identifiers that define a pattern or annotation
|
|
8
|
+
(subject_pattern subject: (_ identifier: (_) @local.definition))
|
|
9
|
+
(subject_pattern subject: (_ labels: (labels (symbol) @local.definition)))
|
|
10
|
+
(subject_pattern subject: (_ labels: (labels (quoted_name) @local.definition)))
|
|
11
|
+
(node_pattern subject: (_ identifier: (_) @local.definition))
|
|
12
|
+
(node_pattern subject: (_ labels: (labels (symbol) @local.definition)))
|
|
13
|
+
(node_pattern subject: (_ labels: (labels (quoted_name) @local.definition)))
|
|
14
|
+
(relationship_pattern left: (node_pattern subject: (_ identifier: (_) @local.definition)))
|
|
15
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (symbol) @local.definition))))
|
|
16
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
17
|
+
(relationship_pattern right: (node_pattern subject: (_ identifier: (_) @local.definition)))
|
|
18
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (symbol) @local.definition))))
|
|
19
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
20
|
+
(relationship_pattern kind: (right_arrow subject: (_ identifier: (_) @local.definition)))
|
|
21
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
22
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
23
|
+
(relationship_pattern kind: (left_arrow subject: (_ identifier: (_) @local.definition)))
|
|
24
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
25
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
26
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ identifier: (_) @local.definition)))
|
|
27
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
28
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
29
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ identifier: (_) @local.definition)))
|
|
30
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
31
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
32
|
+
(identified_annotation identifier: (_) @local.definition)
|
|
33
|
+
(identified_annotation labels: (labels (symbol) @local.definition))
|
|
34
|
+
(identified_annotation labels: (labels (quoted_name) @local.definition))
|
|
35
|
+
|
|
36
|
+
; References: pattern_reference identifier
|
|
37
|
+
(pattern_reference identifier: (_) @local.reference)
|
package/grammar.js
CHANGED
|
@@ -69,7 +69,7 @@ module.exports = grammar({
|
|
|
69
69
|
|
|
70
70
|
pattern_reference: ($) => field("identifier", $._identifier),
|
|
71
71
|
|
|
72
|
-
_identifier: ($) => choice($.symbol, $.
|
|
72
|
+
_identifier: ($) => choice($.symbol, $.quoted_name, $.integer),
|
|
73
73
|
|
|
74
74
|
_subject: ($) =>
|
|
75
75
|
choice(
|
|
@@ -114,13 +114,13 @@ module.exports = grammar({
|
|
|
114
114
|
|
|
115
115
|
labels: ($) => repeat1($._label),
|
|
116
116
|
|
|
117
|
-
_label: ($) => seq(choice(":", "::"), $.symbol),
|
|
117
|
+
_label: ($) => seq(choice(":", "::"), choice($.symbol, $.quoted_name)),
|
|
118
118
|
|
|
119
119
|
record: ($) => seq("{", commaSep($.record_property), "}"),
|
|
120
120
|
|
|
121
121
|
record_property: ($) =>
|
|
122
122
|
seq(
|
|
123
|
-
field("key", $.
|
|
123
|
+
field("key", $._key_name),
|
|
124
124
|
choice(":", "::"),
|
|
125
125
|
field("value", $._value),
|
|
126
126
|
),
|
|
@@ -128,7 +128,7 @@ module.exports = grammar({
|
|
|
128
128
|
map: ($) => seq("{", commaSep($.map_entry), "}"),
|
|
129
129
|
|
|
130
130
|
map_entry: ($) =>
|
|
131
|
-
seq(field("key", $.
|
|
131
|
+
seq(field("key", $._key_name), ":", field("value", $._scalar_value)),
|
|
132
132
|
|
|
133
133
|
symbol: ($) => token(/[a-zA-Z_][0-9a-zA-Z_.\-@]*/),
|
|
134
134
|
|
|
@@ -174,6 +174,15 @@ module.exports = grammar({
|
|
|
174
174
|
return token(measurement);
|
|
175
175
|
},
|
|
176
176
|
|
|
177
|
+
quoted_name: ($) =>
|
|
178
|
+
delimit_string(alias($._backticked_text, $.string_content), "`"),
|
|
179
|
+
|
|
180
|
+
double_quoted_name: ($) =>
|
|
181
|
+
delimit_string(alias($._double_quoted_text, $.string_content), '"'),
|
|
182
|
+
|
|
183
|
+
_key_name: ($) =>
|
|
184
|
+
choice($.symbol, $.quoted_name, $.double_quoted_name),
|
|
185
|
+
|
|
177
186
|
string_literal: ($) =>
|
|
178
187
|
choice(
|
|
179
188
|
$._single_quoted_string,
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/queries/highlights.scm
CHANGED
|
@@ -12,9 +12,58 @@
|
|
|
12
12
|
; Boolean literals
|
|
13
13
|
(boolean_literal) @boolean
|
|
14
14
|
|
|
15
|
-
;
|
|
15
|
+
; Comment (FR-003)
|
|
16
|
+
(comment) @comment
|
|
17
|
+
|
|
18
|
+
; Tagged-string tag distinct from content (FR-002)
|
|
19
|
+
(tagged_string tag: (symbol) @attribute)
|
|
20
|
+
|
|
21
|
+
; Reference identifier: pattern_reference (FR-001)
|
|
22
|
+
(pattern_reference identifier: (_) @variable)
|
|
23
|
+
|
|
24
|
+
; Symbols and identifiers (generic; definition/reference/tag captured above)
|
|
16
25
|
(symbol) @variable
|
|
17
26
|
|
|
27
|
+
; Definition-like identifiers and labels (FR-001): @type
|
|
28
|
+
; These must come AFTER generic symbol rule to take priority
|
|
29
|
+
|
|
30
|
+
; Labels (symbols and quoted names in labels nodes)
|
|
31
|
+
(labels (symbol) @type)
|
|
32
|
+
(labels (quoted_name) @type)
|
|
33
|
+
|
|
34
|
+
; Annotation identifiers and labels
|
|
35
|
+
(identified_annotation identifier: (_) @type)
|
|
36
|
+
(identified_annotation labels: (labels (symbol) @type))
|
|
37
|
+
(identified_annotation labels: (labels (quoted_name) @type))
|
|
38
|
+
|
|
39
|
+
; Subject, node, and relationship pattern definitions (FR-001): @type
|
|
40
|
+
; subject/node subject is _subject (use wildcard _ as it may be hidden in some runtimes)
|
|
41
|
+
(subject_pattern subject: (_ identifier: (_) @type))
|
|
42
|
+
(subject_pattern subject: (_ labels: (labels (symbol) @type)))
|
|
43
|
+
(subject_pattern subject: (_ labels: (labels (quoted_name) @type)))
|
|
44
|
+
(node_pattern subject: (_ identifier: (_) @type))
|
|
45
|
+
(node_pattern subject: (_ labels: (labels (symbol) @type)))
|
|
46
|
+
(node_pattern subject: (_ labels: (labels (quoted_name) @type)))
|
|
47
|
+
(relationship_pattern left: (node_pattern subject: (_ identifier: (_) @type)))
|
|
48
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (symbol) @type))))
|
|
49
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (quoted_name) @type))))
|
|
50
|
+
(relationship_pattern right: (node_pattern subject: (_ identifier: (_) @type)))
|
|
51
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (symbol) @type))))
|
|
52
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (quoted_name) @type))))
|
|
53
|
+
; Arrow kind: subject is inside optional brackets on the arrow
|
|
54
|
+
(relationship_pattern kind: (right_arrow subject: (_ identifier: (_) @type)))
|
|
55
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
56
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
57
|
+
(relationship_pattern kind: (left_arrow subject: (_ identifier: (_) @type)))
|
|
58
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
59
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
60
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ identifier: (_) @type)))
|
|
61
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
62
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
63
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ identifier: (_) @type)))
|
|
64
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (symbol) @type))))
|
|
65
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (quoted_name) @type))))
|
|
66
|
+
|
|
18
67
|
; Keywords and operators
|
|
19
68
|
[
|
|
20
69
|
"@"
|
|
@@ -40,22 +89,14 @@
|
|
|
40
89
|
|
|
41
90
|
; Field names in records and maps
|
|
42
91
|
(record_property key: (symbol) @property)
|
|
43
|
-
(record_property key: (
|
|
44
|
-
(record_property key: (
|
|
92
|
+
(record_property key: (quoted_name) @property)
|
|
93
|
+
(record_property key: (double_quoted_name) @property)
|
|
45
94
|
(map_entry key: (symbol) @property)
|
|
46
|
-
(map_entry key: (
|
|
47
|
-
(map_entry key: (
|
|
95
|
+
(map_entry key: (quoted_name) @property)
|
|
96
|
+
(map_entry key: (double_quoted_name) @property)
|
|
48
97
|
|
|
49
98
|
; Annotation keys (property-style) and headers (identified/label-style)
|
|
50
99
|
(property_annotation key: (symbol) @attribute)
|
|
51
|
-
(identified_annotation identifier: (_) @attribute)
|
|
52
|
-
(identified_annotation labels: (_) @attribute)
|
|
53
|
-
|
|
54
|
-
; Subject Pattern notation (special highlighting)
|
|
55
|
-
(subject_pattern) @type
|
|
56
|
-
|
|
57
|
-
; Node with labels
|
|
58
|
-
(node_pattern (labels (symbol) @type))
|
|
59
100
|
|
|
60
101
|
; Relationship arrows (special highlighting for graph syntax)
|
|
61
102
|
(relationship_pattern) @keyword
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
; Indentation: 2 spaces per level for brackets and multi-line structures
|
|
2
|
+
; FR-007 — specs/004-editor-improvements/contracts/indents.md
|
|
3
|
+
|
|
4
|
+
; Record {}
|
|
5
|
+
"{" @indent
|
|
6
|
+
"}" @indent.end
|
|
7
|
+
|
|
8
|
+
; Subject pattern []
|
|
9
|
+
"[" @indent
|
|
10
|
+
"]" @indent.end
|
|
11
|
+
|
|
12
|
+
; Node pattern ()
|
|
13
|
+
"(" @indent
|
|
14
|
+
")" @indent.end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
; Language injection for tagged strings: tag`content` and ```tag\ncontent\n```
|
|
2
|
+
;
|
|
3
|
+
; The tag symbol is used as the injection language so that downstream and editors
|
|
4
|
+
; can support arbitrary tags without changing the grammar. Well-known tags (md, ts,
|
|
5
|
+
; date, datetime, time, sql, json, html, etc.) are documented in docs/tagged-strings-and-injections.md.
|
|
6
|
+
;
|
|
7
|
+
; Overrides below map tags that do not match common parser names. The final
|
|
8
|
+
; rule uses the tag's text as the language name for all other tags (e.g. "sql",
|
|
9
|
+
; "json", "html" often match parser names).
|
|
10
|
+
|
|
11
|
+
; md -> markdown
|
|
12
|
+
(tagged_string
|
|
13
|
+
tag: (symbol) @_tag
|
|
14
|
+
content: (string_content) @injection.content)
|
|
15
|
+
(#eq? @_tag "md")
|
|
16
|
+
(#set! injection.language "markdown")
|
|
17
|
+
|
|
18
|
+
; ts -> typescript
|
|
19
|
+
(tagged_string
|
|
20
|
+
tag: (symbol) @_tag
|
|
21
|
+
content: (string_content) @injection.content)
|
|
22
|
+
(#eq? @_tag "ts")
|
|
23
|
+
(#set! injection.language "typescript")
|
|
24
|
+
|
|
25
|
+
; Dynamic: use tag text as language name for all other tags (sql, json, html, etc.)
|
|
26
|
+
; Editors may map additional tags (e.g. date, datetime, time) to parsers or leave as plain.
|
|
27
|
+
(tagged_string
|
|
28
|
+
tag: (symbol) @injection.language
|
|
29
|
+
content: (string_content) @injection.content)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
; Locals: go to definition and highlight references (file scope)
|
|
2
|
+
; FR-005, FR-006 — specs/004-editor-improvements/contracts/locals.md
|
|
3
|
+
|
|
4
|
+
; File scope: all definitions and references in one scope
|
|
5
|
+
(gram_pattern) @local.scope
|
|
6
|
+
|
|
7
|
+
; Definitions: identifiers that define a pattern or annotation
|
|
8
|
+
(subject_pattern subject: (_ identifier: (_) @local.definition))
|
|
9
|
+
(subject_pattern subject: (_ labels: (labels (symbol) @local.definition)))
|
|
10
|
+
(subject_pattern subject: (_ labels: (labels (quoted_name) @local.definition)))
|
|
11
|
+
(node_pattern subject: (_ identifier: (_) @local.definition))
|
|
12
|
+
(node_pattern subject: (_ labels: (labels (symbol) @local.definition)))
|
|
13
|
+
(node_pattern subject: (_ labels: (labels (quoted_name) @local.definition)))
|
|
14
|
+
(relationship_pattern left: (node_pattern subject: (_ identifier: (_) @local.definition)))
|
|
15
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (symbol) @local.definition))))
|
|
16
|
+
(relationship_pattern left: (node_pattern subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
17
|
+
(relationship_pattern right: (node_pattern subject: (_ identifier: (_) @local.definition)))
|
|
18
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (symbol) @local.definition))))
|
|
19
|
+
(relationship_pattern right: (node_pattern subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
20
|
+
(relationship_pattern kind: (right_arrow subject: (_ identifier: (_) @local.definition)))
|
|
21
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
22
|
+
(relationship_pattern kind: (right_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
23
|
+
(relationship_pattern kind: (left_arrow subject: (_ identifier: (_) @local.definition)))
|
|
24
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
25
|
+
(relationship_pattern kind: (left_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
26
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ identifier: (_) @local.definition)))
|
|
27
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
28
|
+
(relationship_pattern kind: (undirected_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
29
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ identifier: (_) @local.definition)))
|
|
30
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (symbol) @local.definition))))
|
|
31
|
+
(relationship_pattern kind: (bidirectional_arrow subject: (_ labels: (labels (quoted_name) @local.definition))))
|
|
32
|
+
(identified_annotation identifier: (_) @local.definition)
|
|
33
|
+
(identified_annotation labels: (labels (symbol) @local.definition))
|
|
34
|
+
(identified_annotation labels: (labels (quoted_name) @local.definition))
|
|
35
|
+
|
|
36
|
+
; References: pattern_reference identifier
|
|
37
|
+
(pattern_reference identifier: (_) @local.reference)
|