Skip to content

Commit

Permalink
feat: distinguish keys as @field
Browse files Browse the repository at this point in the history
  • Loading branch information
amaanq committed May 13, 2023
1 parent 6e245b4 commit 06bbf2e
Show file tree
Hide file tree
Showing 8 changed files with 513 additions and 568 deletions.
24 changes: 12 additions & 12 deletions bindings/node/binding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@ namespace {
NAN_METHOD(New) {}

void Init(Local<Object> exports, Local<Object> module) {
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance =
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_cpon());

Nan::Set(instance, Nan::New("name").ToLocalChecked(),
Nan::New("cpon").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New);
tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tpl->InstanceTemplate()->SetInternalFieldCount(1);

Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked();
Local<Object> instance =
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked();
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_cpon());

Nan::Set(instance, Nan::New("name").ToLocalChecked(),
Nan::New("cpon").ToLocalChecked());
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance);
}

NODE_MODULE(tree_sitter_cpon, Init)
Expand Down
6 changes: 2 additions & 4 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ module.exports = grammar({
),
),

meta_map: $ => seq(
'<', optionalCommaSep($._meta_pair), '>',
),
meta_map: $ => seq('<', optionalCommaSep($.meta_pair), '>'),

_meta_pair: $ => seq(
meta_pair: $ => seq(
field('key', choice($.string, $.number, $.float)),
':',
field('value', $._value),
Expand Down
2 changes: 2 additions & 0 deletions queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
"d" @character.special
(_) @string.special)

(_ key: (_) @label)

(number) @number

(float) @float
Expand Down
6 changes: 3 additions & 3 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
"members": [
{
"type": "SYMBOL",
"name": "_meta_pair"
"name": "meta_pair"
},
{
"type": "REPEAT",
Expand All @@ -102,7 +102,7 @@
},
{
"type": "SYMBOL",
"name": "_meta_pair"
"name": "meta_pair"
}
]
}
Expand All @@ -127,7 +127,7 @@
}
]
},
"_meta_pair": {
"meta_pair": {
"type": "SEQ",
"members": [
{
Expand Down
21 changes: 18 additions & 3 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -258,10 +258,25 @@
{
"type": "meta_map",
"named": true,
"fields": {},
"children": {
"multiple": true,
"required": false,
"types": [
{
"type": "meta_pair",
"named": true
}
]
}
},
{
"type": "meta_pair",
"named": true,
"fields": {
"key": {
"multiple": true,
"required": false,
"multiple": false,
"required": true,
"types": [
{
"type": "float",
Expand All @@ -279,7 +294,7 @@
},
"value": {
"multiple": true,
"required": false,
"required": true,
"types": [
{
"type": "array",
Expand Down
Loading

0 comments on commit 06bbf2e

Please sign in to comment.