Skip to content

Commit

Permalink
rename attribute_value to unquoted_attribute_value etc
Browse files Browse the repository at this point in the history
  • Loading branch information
milahu committed Mar 5, 2024
1 parent 6bfa9ea commit 737162e
Show file tree
Hide file tree
Showing 6 changed files with 969 additions and 998 deletions.
20 changes: 11 additions & 9 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,27 +117,29 @@ module.exports = grammar({
$.attribute_name,
optional(seq(
'=',
choice(
$.attribute_value,
$.quoted_attribute_value,
),
$._attribute_value,
)),
),

attribute_name: _ => /[^<>"'/=\s]+/,

attribute_value: _ => /[^<>"'=\s]+/,

// An entity can be named, numeric (decimal), or numeric (hexacecimal). The
// longest entity name is 29 characters long, and the HTML spec says that
// no more will ever be added.
entity: _ => /&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?/,

quoted_attribute_value: $ => choice(
seq('\'', optional(alias(/[^']+/, $.attribute_value)), '\''),
seq('"', optional(alias(/[^"]+/, $.attribute_value)), '"'),
_attribute_value: $ => choice(
$.doublequoted_attribute_value,
$.singlequoted_attribute_value,
$.unquoted_attribute_value,
),

doublequoted_attribute_value: $ => seq('"', /[^"]*/, '"'),

singlequoted_attribute_value: $ => seq('\'', /[^']*/, '\''),

unquoted_attribute_value: $ => /[^"'>\s][^>\s]*/,

text: _ => /[^<>&\s]([^<>&]*[^<>&\s])?/,
},
});
4 changes: 3 additions & 1 deletion queries/highlights.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
(erroneous_end_tag_name) @tag.error
(doctype) @constant
(attribute_name) @attribute
(attribute_value) @string
(doublequoted_attribute_value) @string
(singlequoted_attribute_value) @string
(unquoted_attribute_value) @string
(comment) @comment

[
Expand Down
121 changes: 49 additions & 72 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -342,17 +342,8 @@
"value": "="
},
{
"type": "CHOICE",
"members": [
{
"type": "SYMBOL",
"name": "attribute_value"
},
{
"type": "SYMBOL",
"name": "quoted_attribute_value"
}
]
"type": "SYMBOL",
"name": "_attribute_value"
}
]
},
Expand All @@ -367,79 +358,65 @@
"type": "PATTERN",
"value": "[^<>\"'/=\\s]+"
},
"attribute_value": {
"type": "PATTERN",
"value": "[^<>\"'=\\s]+"
},
"entity": {
"type": "PATTERN",
"value": "&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?"
},
"quoted_attribute_value": {
"_attribute_value": {
"type": "CHOICE",
"members": [
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^']+"
},
"named": true,
"value": "attribute_value"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "'"
}
]
"type": "SYMBOL",
"name": "doublequoted_attribute_value"
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "CHOICE",
"members": [
{
"type": "ALIAS",
"content": {
"type": "PATTERN",
"value": "[^\"]+"
},
"named": true,
"value": "attribute_value"
},
{
"type": "BLANK"
}
]
},
{
"type": "STRING",
"value": "\""
}
]
"type": "SYMBOL",
"name": "singlequoted_attribute_value"
},
{
"type": "SYMBOL",
"name": "unquoted_attribute_value"
}
]
},
"doublequoted_attribute_value": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "\""
},
{
"type": "PATTERN",
"value": "[^\"]*"
},
{
"type": "STRING",
"value": "\""
}
]
},
"singlequoted_attribute_value": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "'"
},
{
"type": "PATTERN",
"value": "[^']*"
},
{
"type": "STRING",
"value": "'"
}
]
},
"unquoted_attribute_value": {
"type": "PATTERN",
"value": "[^\"'>\\s][^>\\s]*"
},
"text": {
"type": "PATTERN",
"value": "[^<>&\\s]([^<>&]*[^<>&\\s])?"
Expand Down
41 changes: 20 additions & 21 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@
"named": true
},
{
"type": "attribute_value",
"type": "doublequoted_attribute_value",
"named": true
},
{
"type": "quoted_attribute_value",
"type": "singlequoted_attribute_value",
"named": true
},
{
"type": "unquoted_attribute_value",
"named": true
}
]
Expand Down Expand Up @@ -66,6 +70,11 @@
]
}
},
{
"type": "doublequoted_attribute_value",
"named": true,
"fields": {}
},
{
"type": "element",
"named": true,
Expand Down Expand Up @@ -147,21 +156,6 @@
]
}
},
{
"type": "quoted_attribute_value",
"named": true,
"fields": {},
"children": {
"multiple": false,
"required": false,
"types": [
{
"type": "attribute_value",
"named": true
}
]
}
},
{
"type": "script_element",
"named": true,
Expand Down Expand Up @@ -204,6 +198,11 @@
]
}
},
{
"type": "singlequoted_attribute_value",
"named": true,
"fields": {}
},
{
"type": "start_tag",
"named": true,
Expand Down Expand Up @@ -282,10 +281,6 @@
"type": "attribute_name",
"named": true
},
{
"type": "attribute_value",
"named": true
},
{
"type": "comment",
"named": true
Expand Down Expand Up @@ -313,5 +308,9 @@
{
"type": "text",
"named": true
},
{
"type": "unquoted_attribute_value",
"named": true
}
]
Loading

0 comments on commit 737162e

Please sign in to comment.