Skip to content

Commit

Permalink
Use relaxed pattern for attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
kolen committed Feb 18, 2024
1 parent 40858d6 commit 01dfab2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
4 changes: 2 additions & 2 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ module.exports = grammar({
),
),
attr_name: $ => $._attr_name,
_attr_name: $ => /[a-zA-Z0-9_-]+/, // TODO: very wrong
_attr_name: $ => token(prec(-2, /[^ \t\n\\0\"\'></=()\[\]{}]+/)),
attr_assignment: $ => /[ \t]*=[ \t]*/,
attr_assignment_noescape: $ => /[ \t]*==[ \t]*/,
attr_value: $ => choice(
Expand All @@ -176,7 +176,7 @@ module.exports = grammar({
optional($._text_nested)
),

_element_rest_text: $ => token(prec(-2, /[^ \t][^\n]*/)),
_element_rest_text: $ => token(prec(-3, /[^ \t][^\n]*/)),

// From css grammar https://github.com/tree-sitter/tree-sitter-css/blob/master/grammar.js
// Originally: /\A(#{keys}+)((?:\p{Word}|-|\/\d+|:(\w|-)+)*)/
Expand Down
13 changes: 10 additions & 3 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -914,8 +914,15 @@
"name": "_attr_name"
},
"_attr_name": {
"type": "PATTERN",
"value": "[a-zA-Z0-9_-]+"
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -2,
"content": {
"type": "PATTERN",
"value": "[^ \\t\\n\\\\0\\\"\\'></=()\\[\\]{}]+"
}
}
},
"attr_assignment": {
"type": "PATTERN",
Expand Down Expand Up @@ -1020,7 +1027,7 @@
"type": "TOKEN",
"content": {
"type": "PREC",
"value": -2,
"value": -3,
"content": {
"type": "PATTERN",
"value": "[^ \\t][^\\n]*"
Expand Down

0 comments on commit 01dfab2

Please sign in to comment.