Is it possible to @append_space in the middle of a node #958
-
I am writing a formatter for Fortran. Some of the nodes e.g., Is it possible to match part of a node and append a space after that. Something like the following:
When I try the above it crashes with error:
|
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 2 replies
-
It's hard to tell without the grammar at hand, but I suspect the answer is "yes", in that |
Beta Was this translation helpful? Give feedback.
-
Thanks @yannham and @Xophmeister , the grammar that I am using can be found here: https://github.com/stadelmanma/tree-sitter-fortran/blob/master/grammar.js @Xophmeister I tried using your suggestion but it didn't work. I am brand new to tree-sitter so I don't understand why. Is it due to the nesting you mentioned? I think these lines are relevant from 428 end_subroutine_statement: $ => blockStructureEnding($, 'subroutine'), and 2281 // This can be merged with whiteSpacedKeyword, keeping for now.
2282 function blockStructureEnding ($, structType) {
2283 const obj = prec.right(seq(
2284 alias(choice(
2285 seq(
2286 caseInsensitive('end', false),
2287 optional(caseInsensitive(structType, false))),
2288 caseInsensitive('end' + structType, false)),
2289 'end' + structType),
2290 optional($._name),
2291 $._end_of_statement
2292 ))
2293 return obj
2294 } A lot of the end statements i.e., program, subroutine, module etc. all use the same format. Is there a general way in tree-sitter query to make a general query for all of these types? Or do I have to do each one separately? |
Beta Was this translation helpful? Give feedback.
-
FWIW I also tried this, which doesn't work.
The tree looks like this for a simple subroutine: subroutine parens_but_no_args()
print *, "hello world"
end subroutine
|
Beta Was this translation helpful? Give feedback.
-
Beta Was this translation helpful? Give feedback.
You could do
(end_subroutine_statement _ @append_space . _)
; that is, using wildcard patterns instead of explicitly mentioning those anonymous nodes.