Skip to content

Incorrect parse tree for comparison operator #2

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

Closed
rewinfrey opened this issue Apr 28, 2017 · 2 comments
Closed

Incorrect parse tree for comparison operator #2

rewinfrey opened this issue Apr 28, 2017 · 2 comments

Comments

@rewinfrey
Copy link
Member

Given the expression:

assert isinstance(copy2, variables.Variable)

The parse tree generated is:

(module [0, 0] - [1, 0]
  (expression_statement [0, 0] - [0, 44]
    (comparison_operator [0, 0] - [0, 44]
      (identifier [0, 0] - [0, 6])
      (call [0, 9] - [0, 44]
        (identifier [0, 9] - [0, 17])
        (identifier [0, 18] - [0, 23])
        (attribute [0, 25] - [0, 43]
          (identifier [0, 25] - [0, 34])
          (identifier [0, 35] - [0, 43]))))))

The comparison_operator rule contains in, and it appears the isinstance call is being incorrectly labeled as a comparison_operator because it's matching in. Is that what you think is happening @maxbrunsfeld?

@maxbrunsfeld
Copy link
Contributor

I think the problem is that the grammar did not include assert statements, so tree-sitter was parsing this code as if assert was just a normal identifier. It was then interpreting the word is in isinstance as a relational operator, as if the code was

a is instance(copy2, variables.Variable)

I had an un-pushed commit adding assert statements, so I just pushed that. Maybe it will fix this issue.

@rewinfrey
Copy link
Member Author

@maxbrunsfeld ah thanks so much! I didn't think of assert as a Python keyword, instead seeing it in test files assuming it was a method call for a test framework used by tensorflow. That said, my Python knowledge is very limited 😅 .

Given the statement:

assert isinstance(copy2, variables.Variable)

The assert_statement rule now correctly parses this as:

(module [0, 0] - [1, 0]
  (assert_statement [0, 0] - [0, 44]
    (call [0, 7] - [0, 44]
      (identifier [0, 7] - [0, 17])
      (identifier [0, 18] - [0, 23])
      (attribute [0, 25] - [0, 43]
        (identifier [0, 25] - [0, 34])
        (identifier [0, 35] - [0, 43])))))

All looks 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants