Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how can we pass double quote in the java tree sitter query language #31

Open
eankit opened this issue Nov 2, 2023 · 4 comments
Open

Comments

@eankit
Copy link

eankit commented Nov 2, 2023

how can we pass double quote in the java tree sitter query language
currently its giving following errror to me -
upon passing (#eq? @argument ""FG_CODE_CLEAN_FEATURE_FLAG"")
Error - Could not parse the query : "((\n (method_invocation \n name : () @name\n arguments: ((argument_list \n ([\n (field_access field: ()@argument)\n (_) @argument\n ])) )\n \n ) @method_invocation\n)\n(#eq? @name "flagEnabled")\n(#eq? @argument ""FG_CODE_CLEAN_FEATURE_FLAG"")\n)" Some(QueryError { row: 0, column: 0, offset: 0, message: "Wrong number of arguments to #eq? predicate. Expected 2, got 4.", kind: Predicate }

upon passing - (#eq? @argument '"FG_CODE_CLEAN_FEATURE_FLAG"')
'Incorrect Rule Graph - Cannot parse the tree-sitter query - ((
(method_invocation
name : () @name
arguments: ((argument_list
([
(field_access field: (
)@argument)
(_) @argument
])) )

) @method_invocation

)
(#eq? @name "flagEnabled")
(#eq? @argument '"FG_CODE_CLEAN_FEATURE_FLAG"')

Request you guide me to the right path!!!

@sogaiu
Copy link

sogaiu commented Nov 2, 2023

Have you tried escaping the inner double quotes with backslashes?

e.g.

(#eq? @argument "\"FG_CODE_CLEAN_FEATURE_FLAG\"")

@eankit
Copy link
Author

eankit commented Nov 3, 2023

yes I did and it didn't worked out

@sogaiu
Copy link

sogaiu commented Nov 3, 2023

Something similar did work here.

Perhaps you'd be willing to post more details of what you tried when you tried the escaping with backslashes and the specific output of what didn't work?

@sogaiu
Copy link

sogaiu commented Nov 3, 2023

FWIW, it's not quite the same but when I used a file named query.scm with content:

(((method_invocation                                                                     
     name: (_) @name                                                                     
     arguments: ((argument_list ([(_) @argument])))) @method_invocation)                 
 (#eq? @name "flagEnabled")                                                              
 (#eq? @argument "\"FG_CODE_CLEAN_FEATURE_FLAG\"")) 

and another file named sample.java with content:

flagEnabled("FG_CODE_CLEAN_FEATURE_FLAG");

the invocation:

tree-sitter query query.scm sample.java

gave:

sample.java
  pattern: 0
    capture: 2 - method_invocation, start: (0, 0), end: (0, 41), text: `flagEnabled("FG_CODE_CLEAN_FEATURE_FLAG")`
    capture: 0 - name, start: (0, 0), end: (0, 11), text: `flagEnabled`
    capture: 1 - argument, start: (0, 12), end: (0, 40), text: `"FG_CODE_CLEAN_FEATURE_FLAG"`

This was with tree-sitter cli version:

tree-sitter 0.20.8 (ddfbbb00a15a653ef0584ec555808d49d84279cb)

Does your query work with the cli?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants