interdependence / tree-sitter-htmldjango

A tree-sitter grammar for the Django template language
MIT License
19 stars 5 forks source link

identiers incorrectly parsed as keywords when they start with the same letters #4

Closed luggage66 closed 7 months ago

luggage66 commented 7 months ago
{% get_foo as foo %}

Correctly parses as:

template [0, 0] - [1, 0]
  unpaired_statement [0, 0] - [0, 20]
    tag_name [0, 3] - [0, 10]
    keyword [0, 11] - [0, 13]
    variable [0, 14] - [0, 17]
      variable_name [0, 14] - [0, 17]

but if the variable has any keyword in the name is fails:

{% get_foo as randomfoo %}

Which parses as:

template [0, 0] - [1, 0]
  unpaired_statement [0, 0] - [0, 26]
    tag_name [0, 3] - [0, 10]
    keyword [0, 11] - [0, 13]
    keyword [0, 14] - [0, 20]  <- "random" keyword
    ERROR [0, 20] - [0, 23]   <- "foo"
interdependence commented 7 months ago

Thanks for finding and reporting this! I have written a new test and will see if I can fix it. Something to do with whitespace in the attribute rule.

interdependence commented 7 months ago

Should be fixed in ea71012.

I changed the keyword rule (and a few others with potential conflicts) to explicitly require a trailing whitespace. I also removed the standalone whitespace handling rule because it isn't needed.

luggage66 commented 7 months ago

Working great, thanks!