Cannot parse multi catch
statement when catch
keyword written after \n
#724
-
I'm doing some work based on tree-sitter-kotlin . When I parse something which include multi fun main() = try {
} catch(e: E1) {
}
// new line here
catch(e: E3) {
} output:
But if I write fun main() = try {
} catch(e: E1) {
}/* without newline*/ catch(e: E3) {
} output:
I have already try the methods that mentioned in conflicting-tokens, but none of them can work. Currently I can only make parser work correctly if add catch_block: $ => seq(
"catch",
"(",
repeat($.annotation),
$.simple_identifier,
":",
$._type,
")",
$._block,
// it looks like that tree-sitter will `eat` these tokens
optional(repeat(choice(
"\n",
"\r",
"\t",
" "
)))
), It just looks like tree-sitter will |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 1 reply
-
Issue-Label Bot is automatically applying the label Links: app homepage, dashboard and code for this bot. |
Beta Was this translation helpful? Give feedback.
-
I moved this to the Discussion board. We are trying to move away from using GH issues for these sorts of questions. |
Beta Was this translation helpful? Give feedback.
-
This isn't a bug in Tree-sitter. It is correct to give you a I'm not very familiar with kotlin, or its statement-termination rules. Is there any simple rule for determining when a newline should be interpreted as a statement-terminator? Allowing an optional |
Beta Was this translation helpful? Give feedback.
This isn't a bug in Tree-sitter. It is correct to give you a
\n
token when it sees a newline after thecatch
block, because a\n
token is valid in that position.I'm not very familiar with kotlin, or its statement-termination rules. Is there any simple rule for determining when a newline should be interpreted as a statement-terminator? Allowing an optional
\n
betweencatch
blocks might be a fine solution. Alternatively, you may need to define an external scanner that applies some arbitrary C code for deciding whether or not to create a\n
token. That is whattree-sitter-javascript
does, for example.