Any way to catch the node type information (for example by assigning to meta variable)? #1491
-
Hi, I need to find a way to print a specific node type. for example if i am searching for a node of type "string_literal" now for each of string node parents, the meta variable $NODE_PARENT hold the whole textual content of the node. however what i need to print is something like: $NODE x has parent of type "pair" for example, or type "arguments". example rule: language: java
id: extract-context
rule:
pattern: $NODE
kind: string_literal
inside:
pattern: $NODE_PARENT
stopBy: end
message: $NODE -------> $NODE_PARENT Note: ^ this is a very simple rule as an example. the actual rule(s) are targeting specific strings in a very large corpus of data where we use AST-Grep to easily extract these data. however we couldn't easily find any workaround this, so i appreciate your help:) Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Hi, thanks for using ast-grep. Unfortunately, the kind data is not available in CLI. However, you can try using programmatic API https://ast-grep.github.io/guide/api-usage.html |
Beta Was this translation helpful? Give feedback.
-
Thanks for the quick reply! I just took a look over the Python API and it seems impressive, however i have a question, |
Beta Was this translation helpful? Give feedback.
Hi, thanks for using ast-grep.
Unfortunately, the kind data is not available in CLI. However, you can try using programmatic API https://ast-grep.github.io/guide/api-usage.html