Skip to content
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

shorthand - in classes should ERROR #16

Closed
bennypowers opened this issue Mar 16, 2022 · 2 comments
Closed

shorthand - in classes should ERROR #16

bennypowers opened this issue Mar 16, 2022 · 2 comments

Comments

@bennypowers
Copy link
Contributor

$ cat shorthand.re
/[\w-.]/
$ tree-sitter parse shorthand.re
(pattern [0, 0] - [1, 0]
  (term [0, 0] - [0, 8]
    (pattern_character [0, 0] - [0, 1])
    (character_class [0, 1] - [0, 7]
      (class_range [0, 2] - [0, 6]
        (character_class_escape [0, 2] - [0, 4])
        (class_character [0, 5] - [0, 6])))
    (pattern_character [0, 7] - [0, 8])))

expected: error

@the-mikedavis
Copy link
Contributor

Tree-sitter grammars are usually very permissive and are not meant to be used for validation.

The docs have some notes on how to structure rules:

that suggest optimizing the grammar for easy consumption rather than full spec conformance. In this case, if you were looking to mark this as invalid, you could have a highlight query:

(class_range
  (character_class_escape) @error)

which would highlight the \w. IMO this is a better indication of the problem than what regex101 provides in this example if you interpret this as an invalid range (albeit it's arguable).

See also similar discussion: tree-sitter/tree-sitter-javascript#209

@bennypowers
Copy link
Contributor Author

The problem isn't the \w it's the invalid -
This is an interesting case. while regex101 flags it as invalid, regexr allows it bennypowers/nvim-regexplainer@98c45db

and firefox and node both run runs it, as well.

Thanks for the background info!

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