Skip to content

Commit f12401b

Browse files
Sync styx tree-sitter grammar from upstream (#141)
## Summary - Updates grammar.js with improved sequence whitespace handling (`_seq_ws` rule) - Updates highlights.scm with better key/sequence highlighting - Adds brackets.scm for bracket matching - Adds indents.scm for indentation support ## Test plan - CI should run grammar tests
1 parent 0e54134 commit f12401b

File tree

4 files changed

+30
-7
lines changed

4 files changed

+30
-7
lines changed

langs/group-maple/styx/def/grammar/grammar.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ module.exports = grammar({
119119
$.raw_scalar,
120120
),
121121

122-
immediate_sequence: ($) => seq(token.immediate("("), repeat(seq($.expr, optional($._ws))), ")"),
122+
immediate_sequence: ($) =>
123+
seq(token.immediate("("), repeat($._seq_ws), repeat(seq($.expr, repeat($._seq_ws))), ")"),
123124
immediate_object: ($) => seq(token.immediate("{"), optional($._object_body), "}"),
124125
immediate_unit: ($) => $._immediate_unit_at,
125126

@@ -153,7 +154,8 @@ module.exports = grammar({
153154
unit: ($) => $._unit_at,
154155

155156
// Sequence: (expr expr ...)
156-
sequence: ($) => seq("(", repeat(seq($.expr, optional($._ws))), ")"),
157+
// Per spec, WS includes newlines inside sequences
158+
sequence: ($) => seq("(", repeat($._seq_ws), repeat(seq($.expr, repeat($._seq_ws))), ")"),
157159

158160
// Object: { entries }
159161
object: ($) => seq("{", optional($._object_body), "}"),
@@ -194,5 +196,7 @@ module.exports = grammar({
194196
// Whitespace helpers
195197
_ws: ($) => /[ \t]+/,
196198
_newline: ($) => /\r?\n/,
199+
// Whitespace inside sequences (includes newlines and comments per spec)
200+
_seq_ws: ($) => choice(/[ \t]+/, $._newline, $.line_comment),
197201
},
198202
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
; Bracket pairs for Styx
2+
3+
("{" @open "}" @close)
4+
("(" @open ")" @close)

langs/group-maple/styx/def/queries/highlights.scm

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,24 @@
1717
; Unit value
1818
(unit) @constant.builtin
1919

20-
; Tags - more specific than bare_scalar, so comes after
21-
(tag) @label
20+
; Tags - styled same as unit since @ is the tag sigil
21+
(tag) @constant.builtin
2222

2323
; Attributes - key in attribute syntax
24+
; Use @keyword or @punctuation.special to make > stand out
2425
(attribute
2526
key: (bare_scalar) @property
26-
">" @operator)
27+
">" @keyword)
2728

28-
; Keys in entries - bare scalars in the key position (overrides @string above)
29+
; Keys in entries - any scalar in the key position (overrides @string above)
2930
(entry
3031
key: (expr
31-
payload: (scalar (bare_scalar) @property)))
32+
payload: (scalar (_) @property)))
33+
34+
; Sequence items are values, not keys (must come AFTER entry key rule to override)
35+
(sequence
36+
(expr
37+
payload: (scalar (_) @string)))
3238

3339
; Punctuation
3440
"{" @punctuation.bracket
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
; Indentation queries for Styx
2+
3+
; Objects and sequences increase indent
4+
(object) @indent
5+
(sequence) @indent
6+
7+
; Closing brackets decrease indent
8+
"}" @outdent
9+
")" @outdent

0 commit comments

Comments
 (0)