Skip to content

How to get Comments and Docstring in TreeSitter #2470

Closed Answered by Arnab9Codes
Arnab9Codes asked this question in General
Discussion options

You must be logged in to vote

I have got the answer myself.
use the following logic:

if (curr_node.type=='expression_statement' and len(curr_node.children)==1 and (curr_node.children[0].type=='string'):
         # do something

if(curr_node.type=='comment'):
        # do something

in tree_sitter docstring is an expression_statement and then it is a string under that,
a line comment is a single line comment.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by Arnab9Codes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant