tree-sitter-java icon indicating copy to clipboard operation
tree-sitter-java copied to clipboard

Failed to parse a switch statement before an update expression

Open lixinye-nju opened this issue 4 years ago • 0 comments

Problem description

Consider the following snippet where error happens if pos++ is changed to ++pos .

switch (c) {
case '\r':
case '\n':
case '\t':
case ' ':
          return;
case '"':
case '\'':
        setReplacementLength(getReplacementLength() + pos - offset + 1);
      return;
  }
  ++pos;

Parse the snippets with following code

snippets_tree = java_parser.parse(bytes(snippets, 'utf8')).root_node
snippets_tree.children

Expected parse tree output (optional)

[<Node kind=switch_expression, start_point=(1, 0), end_point=(12, 3)>,
 <Node kind=expression_statement, start_point=(13, 2), end_point=(13, 8)>]

Actual parse tree output (optional)

[<Node kind=expression_statement, start_point=(1, 0), end_point=(13, 8)>]

And this expression statement contains ERROR node

snippets_tree.children[0].children
[<Node kind=update_expression, start_point=(1, 0), end_point=(13, 4)>,
 <Node kind=ERROR, start_point=(13, 4), end_point=(13, 7)>,
 <Node kind=";", start_point=(13, 7), end_point=(13, 8)>]

lixinye-nju avatar Oct 15 '21 10:10 lixinye-nju