Skip to content

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

@vivax3794

Description

@vivax3794

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions