Skip to content

Commit 737162e

Browse files
committed
rename attribute_value to unquoted_attribute_value etc
1 parent 6bfa9ea commit 737162e

File tree

6 files changed

+969
-998
lines changed

6 files changed

+969
-998
lines changed

grammar.js

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -117,27 +117,29 @@ module.exports = grammar({
117117
$.attribute_name,
118118
optional(seq(
119119
'=',
120-
choice(
121-
$.attribute_value,
122-
$.quoted_attribute_value,
123-
),
120+
$._attribute_value,
124121
)),
125122
),
126123

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

129-
attribute_value: _ => /[^<>"'=\s]+/,
130-
131126
// An entity can be named, numeric (decimal), or numeric (hexacecimal). The
132127
// longest entity name is 29 characters long, and the HTML spec says that
133128
// no more will ever be added.
134129
entity: _ => /&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?/,
135130

136-
quoted_attribute_value: $ => choice(
137-
seq('\'', optional(alias(/[^']+/, $.attribute_value)), '\''),
138-
seq('"', optional(alias(/[^"]+/, $.attribute_value)), '"'),
131+
_attribute_value: $ => choice(
132+
$.doublequoted_attribute_value,
133+
$.singlequoted_attribute_value,
134+
$.unquoted_attribute_value,
139135
),
140136

137+
doublequoted_attribute_value: $ => seq('"', /[^"]*/, '"'),
138+
139+
singlequoted_attribute_value: $ => seq('\'', /[^']*/, '\''),
140+
141+
unquoted_attribute_value: $ => /[^"'>\s][^>\s]*/,
142+
141143
text: _ => /[^<>&\s]([^<>&]*[^<>&\s])?/,
142144
},
143145
});

queries/highlights.scm

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
(erroneous_end_tag_name) @tag.error
33
(doctype) @constant
44
(attribute_name) @attribute
5-
(attribute_value) @string
5+
(doublequoted_attribute_value) @string
6+
(singlequoted_attribute_value) @string
7+
(unquoted_attribute_value) @string
68
(comment) @comment
79

810
[

src/grammar.json

Lines changed: 49 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -342,17 +342,8 @@
342342
"value": "="
343343
},
344344
{
345-
"type": "CHOICE",
346-
"members": [
347-
{
348-
"type": "SYMBOL",
349-
"name": "attribute_value"
350-
},
351-
{
352-
"type": "SYMBOL",
353-
"name": "quoted_attribute_value"
354-
}
355-
]
345+
"type": "SYMBOL",
346+
"name": "_attribute_value"
356347
}
357348
]
358349
},
@@ -367,79 +358,65 @@
367358
"type": "PATTERN",
368359
"value": "[^<>\"'/=\\s]+"
369360
},
370-
"attribute_value": {
371-
"type": "PATTERN",
372-
"value": "[^<>\"'=\\s]+"
373-
},
374361
"entity": {
375362
"type": "PATTERN",
376363
"value": "&(#([xX][0-9a-fA-F]{1,6}|[0-9]{1,5})|[A-Za-z]{1,30});?"
377364
},
378-
"quoted_attribute_value": {
365+
"_attribute_value": {
379366
"type": "CHOICE",
380367
"members": [
381368
{
382-
"type": "SEQ",
383-
"members": [
384-
{
385-
"type": "STRING",
386-
"value": "'"
387-
},
388-
{
389-
"type": "CHOICE",
390-
"members": [
391-
{
392-
"type": "ALIAS",
393-
"content": {
394-
"type": "PATTERN",
395-
"value": "[^']+"
396-
},
397-
"named": true,
398-
"value": "attribute_value"
399-
},
400-
{
401-
"type": "BLANK"
402-
}
403-
]
404-
},
405-
{
406-
"type": "STRING",
407-
"value": "'"
408-
}
409-
]
369+
"type": "SYMBOL",
370+
"name": "doublequoted_attribute_value"
410371
},
411372
{
412-
"type": "SEQ",
413-
"members": [
414-
{
415-
"type": "STRING",
416-
"value": "\""
417-
},
418-
{
419-
"type": "CHOICE",
420-
"members": [
421-
{
422-
"type": "ALIAS",
423-
"content": {
424-
"type": "PATTERN",
425-
"value": "[^\"]+"
426-
},
427-
"named": true,
428-
"value": "attribute_value"
429-
},
430-
{
431-
"type": "BLANK"
432-
}
433-
]
434-
},
435-
{
436-
"type": "STRING",
437-
"value": "\""
438-
}
439-
]
373+
"type": "SYMBOL",
374+
"name": "singlequoted_attribute_value"
375+
},
376+
{
377+
"type": "SYMBOL",
378+
"name": "unquoted_attribute_value"
379+
}
380+
]
381+
},
382+
"doublequoted_attribute_value": {
383+
"type": "SEQ",
384+
"members": [
385+
{
386+
"type": "STRING",
387+
"value": "\""
388+
},
389+
{
390+
"type": "PATTERN",
391+
"value": "[^\"]*"
392+
},
393+
{
394+
"type": "STRING",
395+
"value": "\""
440396
}
441397
]
442398
},
399+
"singlequoted_attribute_value": {
400+
"type": "SEQ",
401+
"members": [
402+
{
403+
"type": "STRING",
404+
"value": "'"
405+
},
406+
{
407+
"type": "PATTERN",
408+
"value": "[^']*"
409+
},
410+
{
411+
"type": "STRING",
412+
"value": "'"
413+
}
414+
]
415+
},
416+
"unquoted_attribute_value": {
417+
"type": "PATTERN",
418+
"value": "[^\"'>\\s][^>\\s]*"
419+
},
443420
"text": {
444421
"type": "PATTERN",
445422
"value": "[^<>&\\s]([^<>&]*[^<>&\\s])?"

src/node-types.json

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@
1212
"named": true
1313
},
1414
{
15-
"type": "attribute_value",
15+
"type": "doublequoted_attribute_value",
1616
"named": true
1717
},
1818
{
19-
"type": "quoted_attribute_value",
19+
"type": "singlequoted_attribute_value",
20+
"named": true
21+
},
22+
{
23+
"type": "unquoted_attribute_value",
2024
"named": true
2125
}
2226
]
@@ -66,6 +70,11 @@
6670
]
6771
}
6872
},
73+
{
74+
"type": "doublequoted_attribute_value",
75+
"named": true,
76+
"fields": {}
77+
},
6978
{
7079
"type": "element",
7180
"named": true,
@@ -147,21 +156,6 @@
147156
]
148157
}
149158
},
150-
{
151-
"type": "quoted_attribute_value",
152-
"named": true,
153-
"fields": {},
154-
"children": {
155-
"multiple": false,
156-
"required": false,
157-
"types": [
158-
{
159-
"type": "attribute_value",
160-
"named": true
161-
}
162-
]
163-
}
164-
},
165159
{
166160
"type": "script_element",
167161
"named": true,
@@ -204,6 +198,11 @@
204198
]
205199
}
206200
},
201+
{
202+
"type": "singlequoted_attribute_value",
203+
"named": true,
204+
"fields": {}
205+
},
207206
{
208207
"type": "start_tag",
209208
"named": true,
@@ -282,10 +281,6 @@
282281
"type": "attribute_name",
283282
"named": true
284283
},
285-
{
286-
"type": "attribute_value",
287-
"named": true
288-
},
289284
{
290285
"type": "comment",
291286
"named": true
@@ -313,5 +308,9 @@
313308
{
314309
"type": "text",
315310
"named": true
311+
},
312+
{
313+
"type": "unquoted_attribute_value",
314+
"named": true
316315
}
317316
]

0 commit comments

Comments
 (0)