tree-sitter-css icon indicating copy to clipboard operation
tree-sitter-css copied to clipboard

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

Open vivax3794 opened this issue 1 year ago • 0 comments

Did you check existing issues?

  • [x] I have read all the tree-sitter docs if it relates to using the parser
  • [x] 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 avatar Feb 06 '25 13:02 vivax3794