Comments (5)
FWIW, I tried running a similar query on query.rs that is part of this project:
M-x tree-sitter-mode
M-: (ts-query-captures (ts-make-query (tree-sitter-require 'rust) [(function_item (identifier) @function)]) (ts-root-node tree-sitter-tree))
and this generated the expected vector of results. Something busted with the c/cpp grammar maybe?
from elisp-tree-sitter.
The C++ grammar is different:
function_definition:
primitive_type:
function_declarator:
scoped_identifier:
namespace_identifier:
identifier:
parameter_list:
parameter_declaration:
primitive_type:
identifier:
parameter_declaration:
primitive_type:
identifier:
parameter_declaration:
primitive_type:
identifier:
This query works:
[(function_definition
(function_declarator
(scoped_identifier) @function))]
Also, if you are using the latest version, captures are now cons cells, not vectors.
from elisp-tree-sitter.
I wasn't getting the query syntax. I reread the S-expression description on tree-sitter and it makes more sense now. Thanks for the help!
from elisp-tree-sitter.
One more question, actually. I found that the example above missed out on regular functions that aren't part of a class or namespace. I considered two approaches:
- Add another S-expression to the query:
(function_definition (function_declarator (identifer) @function)
- Change the query to capture the function_declarator and then pull the first child with (ts-get-nth-child node 0), which is always "identifier" or "scoped_identifier" and works for both cases.
In general, which is more performant? Are queries really cheap and fast? Faster than processing the node/capture when it comes back?
from elisp-tree-sitter.
The first approach should be more performant, for 2 reasons:
- Rust is faster than Lisp.
- Crossing the module boundary (calling
ts-
functions) has some overhead.
from elisp-tree-sitter.
Related Issues (20)
- `Unsupported Operating System: OpenBSD` HOT 7
- bin/build not work on linux because builtin cd will output the folder name. HOT 1
- tree-sitter languages download of windows binaries failed with error
- tsc-lang-abi-too-new when installing new language HOT 11
- Crash when large file contains an ERROR node
- Invalid version syntax: ‘[email protected] HOT 2
- Colors look wrong in haskell mode. HOT 3
- `tree-sitter-debug-mode` is broken
- Crash when loading one particular Markdown file HOT 7
- Reporting Vulnerability
- (ts-fold-indicators-mode) not working when running emacs from terminal
- How do I add a new grammer to this mode? HOT 2
- why the submodule langs pointed to an old commit?
- tree-sitter-hl-mode doesn't honor the :extend font face in single line comments HOT 1
- request to rebuild tsc-dyn.so with older Linux OS
- Provide `aarch64` build of `tsc-dyn.so` for AArch64 Linux
- Repetitions and Predicate Problems
- Tree sitter not loading in Raspberry Pi 5 with Emacs GNU Emacs 28.2 HOT 2
- `tsc-current-field` doesn't work against starting node HOT 7
- Returned parent node doesn't contain given node as child HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from elisp-tree-sitter.