Skip to content

Commit 06bbf2e

Browse files
committedMay 13, 2023
feat: distinguish keys as @field
1 parent 6e245b4 commit 06bbf2e

File tree

8 files changed

+513
-568
lines changed

8 files changed

+513
-568
lines changed
 

‎bindings/node/binding.cc

+12-12
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,18 @@ namespace {
1111
NAN_METHOD(New) {}
1212

1313
void Init(Local<Object> exports, Local<Object> module) {
14-
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15-
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16-
tpl->InstanceTemplate()->SetInternalFieldCount(1);
17-
18-
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19-
Local<Object> instance =
20-
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
21-
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_cpon());
22-
23-
Nan::Set(instance, Nan::New("name").ToLocalChecked(),
24-
Nan::New("cpon").ToLocalChecked());
25-
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
14+
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
15+
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
16+
tpl->InstanceTemplate()->SetInternalFieldCount(1);
17+
18+
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
19+
Local<Object> instance =
20+
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
21+
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_cpon());
22+
23+
Nan::Set(instance, Nan::New("name").ToLocalChecked(),
24+
Nan::New("cpon").ToLocalChecked());
25+
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
2626
}
2727

2828
NODE_MODULE(tree_sitter_cpon, Init)

‎grammar.js

+2-4
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,9 @@ module.exports = grammar({
4141
),
4242
),
4343

44-
meta_map: $ => seq(
45-
'<', optionalCommaSep($._meta_pair), '>',
46-
),
44+
meta_map: $ => seq('<', optionalCommaSep($.meta_pair), '>'),
4745

48-
_meta_pair: $ => seq(
46+
meta_pair: $ => seq(
4947
field('key', choice($.string, $.number, $.float)),
5048
':',
5149
field('value', $._value),

‎queries/highlights.scm

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
"d" @character.special
1616
(_) @string.special)
1717

18+
(_ key: (_) @label)
19+
1820
(number) @number
1921

2022
(float) @float

‎src/grammar.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
"members": [
8787
{
8888
"type": "SYMBOL",
89-
"name": "_meta_pair"
89+
"name": "meta_pair"
9090
},
9191
{
9292
"type": "REPEAT",
@@ -102,7 +102,7 @@
102102
},
103103
{
104104
"type": "SYMBOL",
105-
"name": "_meta_pair"
105+
"name": "meta_pair"
106106
}
107107
]
108108
}
@@ -127,7 +127,7 @@
127127
}
128128
]
129129
},
130-
"_meta_pair": {
130+
"meta_pair": {
131131
"type": "SEQ",
132132
"members": [
133133
{

‎src/node-types.json

+18-3
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,25 @@
258258
{
259259
"type": "meta_map",
260260
"named": true,
261+
"fields": {},
262+
"children": {
263+
"multiple": true,
264+
"required": false,
265+
"types": [
266+
{
267+
"type": "meta_pair",
268+
"named": true
269+
}
270+
]
271+
}
272+
},
273+
{
274+
"type": "meta_pair",
275+
"named": true,
261276
"fields": {
262277
"key": {
263-
"multiple": true,
264-
"required": false,
278+
"multiple": false,
279+
"required": true,
265280
"types": [
266281
{
267282
"type": "float",
@@ -279,7 +294,7 @@
279294
},
280295
"value": {
281296
"multiple": true,
282-
"required": false,
297+
"required": true,
283298
"types": [
284299
{
285300
"type": "array",

‎src/parser.c

+445-507
Large diffs are not rendered by default.

‎test/corpus/main.txt

+28-22
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,20 @@ Meta
88

99
(document
1010
(meta_map
11-
(string
12-
(string_content))
13-
(string
14-
(string_content))
15-
(number)
16-
(meta_map
17-
(number)
18-
(string
19-
(string_content)))
20-
(string
21-
(string_content)))
11+
(meta_pair
12+
(string
13+
(string_content))
14+
(string
15+
(string_content)))
16+
(meta_pair
17+
(number)
18+
(meta_map
19+
(meta_pair
20+
(number)
21+
(string
22+
(string_content))))
23+
(string
24+
(string_content))))
2225
(number))
2326

2427

@@ -39,17 +42,20 @@ Meta with weird spacing
3942

4043
(document
4144
(meta_map
42-
(string
43-
(string_content))
44-
(string
45-
(string_content))
46-
(number)
47-
(meta_map
48-
(number)
49-
(string
50-
(string_content)))
51-
(string
52-
(string_content)))
45+
(meta_pair
46+
(string
47+
(string_content))
48+
(string
49+
(string_content)))
50+
(meta_pair
51+
(number)
52+
(meta_map
53+
(meta_pair
54+
(number)
55+
(string
56+
(string_content))))
57+
(string
58+
(string_content))))
5359
(number))
5460

5561

‎test/highlight/highlight.cpon

+3-17
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// <- comment
66

77
"Hello, World! // not a comment\n";
8-
// <- string
8+
// ^^^ string
99
// ^^ string.escape
1010

1111
true
@@ -17,25 +17,11 @@ false
1717
null
1818
// <- constant.builtin
1919

20-
-123
21-
// <- number
22-
23-
-12.3e-45
24-
// <- float
25-
123
26-
// ^^^ number
27-
-0x1b23A
28-
// ^^^^^^^^ number
29-
123u
30-
// ^^^^ number
31-
0xA123u
32-
// ^^^^ number
33-
3420
< "ahoj": 888 , 123 : 1 >
3521
// <- punctuation.bracket
3622
// ^ punctuation.bracket
37-
// ^^^^^^ string
38-
// ^^^ number
23+
// ^^^^ string
24+
// ^^^ label
3925
// ^ punctuation.delimiter
4026
// ^ punctuation.delimiter
4127

0 commit comments

Comments
 (0)
Please sign in to comment.