Skip to content

bug: Class name expects valid identifier start after escape sequence. #68

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

Open
2 tasks done
vivax3794 opened this issue Feb 6, 2025 · 0 comments
Open
2 tasks done
Labels
bug Something isn't working

Comments

@vivax3794
Copy link

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-css

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

tree-sitter 0.25.1

Describe the bug

Currently the grammar defines a class name as

    class_name: $ => repeat1(choice(
      $.identifier,
      $.escape_sequence,
    )),

this means it expects a fully valid identifier after a escape sequence, which includes enforcing the extra restriction on the starting character, which should not be applied after an escape sequence.

(in fact parsing of escape sequences are part of the identifiers job according to the css grammar, https://www.w3.org/TR/css-syntax-3/#consume-an-ident-sequence )

Steps To Reproduce/Bad Parse Tree

when parsing this file it reports a error:

.a\.5 {}

which happens because 5 isnt a valid start to an identifier.

(stylesheet [0, 0] - [1, 0]
  (rule_set [0, 0] - [0, 8]
    (selectors [0, 0] - [0, 4]
      (class_selector [0, 0] - [0, 4]
        (class_name [0, 1] - [0, 4]
          (identifier [0, 1] - [0, 2])
          (escape_sequence [0, 2] - [0, 4]))))
    (ERROR [0, 4] - [0, 5])
    (block [0, 6] - [0, 8])))

Expected Behavior/Parse Tree

Not sure how we would want the nodes to look, would likely need a new identifier_continuation or similar (I'm bad at names)

(stylesheet [0, 0] - [1, 0]
  (rule_set [0, 0] - [0, 8]
    (selectors [0, 0] - [0, 4]
      (class_selector [0, 0] - [0, 4]
        (class_name [0, 1] - [0, 4]
          (identifier [0, 1] - [0, 2])
          (escape_sequence [0, 2] - [0, 4])
          (identifier_continuation [0, 4] - [0, 5]))))
    (block [0, 6] - [0, 8])))

Repro

@vivax3794 vivax3794 added the bug Something isn't working label Feb 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant