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

bug: Fail to parse type expression #252

Open
2 tasks done
mingodad opened this issue Feb 7, 2024 · 0 comments
Open
2 tasks done

bug: Fail to parse type expression #252

mingodad opened this issue Feb 7, 2024 · 0 comments
Labels

Comments

@mingodad
Copy link

mingodad commented Feb 7, 2024

Did you check existing issues?

  • I have read all the tree-sitter docs if it relates to using the parser
  • I have searched the existing issues of tree-sitter-python

Tree-Sitter CLI Version, if relevant (output of tree-sitter --version)

tree-sitter 0.20.9 (4f3a3debe86ec8261f48d950ce5b65ba92d26496)

Describe the bug

The sample code shown bellow is parsed fine on the online playground bu fails with this repo:

def get_var(name) -> T[bool] or None:
    return 0

Playground:

[module](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [2, 0]
  [function_definition](https://tree-sitter.github.io/tree-sitter/playground#) [0, 0] - [1, 12]
    name: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 4] - [0, 11]
    parameters: [parameters](https://tree-sitter.github.io/tree-sitter/playground#) [0, 11] - [0, 17]
      [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 12] - [0, 16]
    return_type: [type](https://tree-sitter.github.io/tree-sitter/playground#) [0, 21] - [0, 36]
      [boolean_operator](https://tree-sitter.github.io/tree-sitter/playground#) [0, 21] - [0, 36]
        left: [subscript](https://tree-sitter.github.io/tree-sitter/playground#) [0, 21] - [0, 28]
          value: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 21] - [0, 22]
          subscript: [identifier](https://tree-sitter.github.io/tree-sitter/playground#) [0, 23] - [0, 27]
        right: [none](https://tree-sitter.github.io/tree-sitter/playground#) [0, 32] - [0, 36]
    body: [block](https://tree-sitter.github.io/tree-sitter/playground#) [1, 4] - [1, 12]
      [return_statement](https://tree-sitter.github.io/tree-sitter/playground#) [1, 4] - [1, 12]
        [integer](https://tree-sitter.github.io/tree-sitter/playground#) [1, 11] - [1, 12]

This repo:

(module [0, 0] - [2, 0]
  (function_definition [0, 0] - [1, 12]
    name: (identifier [0, 4] - [0, 11])
    parameters: (parameters [0, 11] - [0, 17]
      (identifier [0, 12] - [0, 16]))
    return_type: (type [0, 21] - [0, 28]
      (generic_type [0, 21] - [0, 28]
        (identifier [0, 21] - [0, 22])
        (type_parameter [0, 22] - [0, 28]
          (type [0, 23] - [0, 27]
            (identifier [0, 23] - [0, 27])))))
    (ERROR [0, 29] - [0, 36]
      (identifier [0, 29] - [0, 31])
      (none [0, 32] - [0, 36]))
    body: (block [1, 4] - [1, 12]
      (return_statement [1, 4] - [1, 12]
        (integer [1, 11] - [1, 12])))))
pyparser-nb/test.py	   0.10 ms	   535 bytes/ms	(ERROR [0, 29] - [0, 36])

Steps To Reproduce/Bad Parse Tree

tree-sitter parse test.py

Expected Behavior/Parse Tree

module [0, 0] - [2, 0]
function_definition [0, 0] - [1, 12]
name: identifier [0, 4] - [0, 11]
parameters: parameters [0, 11] - [0, 17]
identifier [0, 12] - [0, 16]
return_type: type [0, 21] - [0, 36]
boolean_operator [0, 21] - [0, 36]
left: subscript [0, 21] - [0, 28]
value: identifier [0, 21] - [0, 22]
subscript: identifier [0, 23] - [0, 27]
right: none [0, 32] - [0, 36]
body: block [1, 4] - [1, 12]
return_statement [1, 4] - [1, 12]
integer [1, 11] - [1, 12]

Repro

def get_var(name) -> T[bool] or None:
    return 0
@mingodad mingodad added the bug label Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant