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

The parsing result of the return statement is wrong. #84

Open
fzxen opened this issue Mar 28, 2023 · 2 comments
Open

The parsing result of the return statement is wrong. #84

fzxen opened this issue Mar 28, 2023 · 2 comments
Labels
bug Something isn't working grammar Related to the grammar

Comments

@fzxen
Copy link

fzxen commented Mar 28, 2023

I think the parsing result in the return statement is incorrect in the following example.

image

It is expected that it can be parsed into an additive expression. Like this

image

@fzxen
Copy link
Author

fzxen commented Mar 28, 2023

I found the cause of the problem. tree-sitter-kotlin regards return/break/continue as expressions instead of statement.

{
  jump_expression: $ => choice(
      prec.left(PREC.RETURN_OR_THROW, seq("throw", $._expression)),
      prec.left(PREC.RETURN_OR_THROW, seq(choice("return", $._return_at), optional($._expression))),
      "continue",
      $._continue_at,
      "break",
      $._break_at
    ),
}

It hit the definition of infix expression.

{
  infix_expression: $ => prec.left(PREC.INFIX, seq($._expression, $.simple_identifier, $._expression)),
}

I think "return/break/continue/throw" should be converted to statement.

A distinction is often made between statements, which are executed, and expressions, which are evaluated. Expressions always evaluate to a value, which statements do not. However, expressions are often used as part of a larger statement. - copy from wikipedia

@fwcd fwcd added bug Something isn't working grammar Related to the grammar labels Oct 6, 2023
@ObserverOfTime
Copy link
Contributor

This has been fixed.

(source_file [0, 0] - [4, 0]
  (function_declaration [0, 0] - [3, 1]
    (simple_identifier [0, 4] - [0, 8])
    (function_value_parameters [0, 8] - [0, 16]
      (parameter [0, 9] - [0, 15]
        (simple_identifier [0, 9] - [0, 10])
        (user_type [0, 12] - [0, 15]
          (type_identifier [0, 12] - [0, 15]))))
    (function_body [0, 17] - [3, 1]
      (statements [1, 4] - [2, 17]
        (property_declaration [1, 4] - [1, 23]
          (variable_declaration [1, 8] - [1, 14]
            (simple_identifier [1, 8] - [1, 14]))
          (additive_expression [1, 17] - [1, 23]
            (simple_identifier [1, 17] - [1, 18])
            (integer_literal [1, 21] - [1, 23])))
        (jump_expression [2, 4] - [2, 17]
          (additive_expression [2, 11] - [2, 17]
            (simple_identifier [2, 11] - [2, 12])
            (integer_literal [2, 15] - [2, 17])))))))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working grammar Related to the grammar
Projects
None yet
Development

No branches or pull requests

3 participants