tree-sitter / node-tree-sitter

Node.js bindings for tree-sitter
https://www.npmjs.com/package/tree-sitter
MIT License
649 stars 114 forks source link

Query: Negated Fields causing an error in Node/C++ #84

Closed caioliberali closed 3 years ago

caioliberali commented 3 years ago

When using the Playground the query works normally but when using Node with C++ parser the same query causes an error ( if I remove the Negated Field it works ).

Example: https://tree-sitter.github.io/tree-sitter/playground

Code

class MyClass
{
public:
    MyClass();
    MyClass(int b){}

    void Function();
    void FunctionB(){}
}

Query [ (declaration declarator: (function_declarator declarator: (identifier) @N)) @C (function_definition !type declarator: (function_declarator declarator: [ (identifier) @N (field_identifier) @N ] )) @C ]

!type is the keyword that is causing an error.

Can anybody help me? Thank you!

ahlinc commented 3 years ago

@caioliberali it's because negated patterns were added in the core tree-sitter library after v0.19.3 version and doesn't released yet even in the core library. Parsers in the playground were updated 5 days ago. but this nodejs binding was released only for v0.19.0 9 days ago.

In this situation you have one option to:

  1. Clone this repo.
  2. Update the core tree-sitter library in the vendor/tree-sitter to the master.
  3. Compile this binding.
  4. Install this compiled version to your node_modules.
caioliberali commented 3 years ago

@ahlinc Thank you very much again!!