Skip to content

Commit

Permalink
Merge pull request #16 from vrischmann/element-comment
Browse files Browse the repository at this point in the history
Fix HTML comment parsing
  • Loading branch information
vrischmann authored Dec 23, 2023
2 parents 60fe178 + 674c66f commit eab4f31
Show file tree
Hide file tree
Showing 6 changed files with 26,937 additions and 27,150 deletions.
50 changes: 50 additions & 0 deletions corpus/components.txt
Original file line number Diff line number Diff line change
Expand Up @@ -741,3 +741,53 @@ templ (d Data) Method() {
field: (field_identifier)))
(tag_end
name: (element_identifier))))))

====
HTML comment
====

package main

templ Component() {
<html>
<head>
<!--
<link rel="stylesheet" href="/assets/css/bulma.min.css"/> What is bulma??
<link rel="apple-touch-icon" sizes="180x180" href="/assets/favicon/apple-touch-icon.png"/>
-->
<link href="/style.css" rel="stylesheet"/>
</head>
</html>
}

---

(source_file
(package_clause
(package_identifier))
(component_declaration
(component_identifier)
(parameter_list)
(component_block
(element
(tag_start
(element_identifier))
(element
(tag_start
(element_identifier))
(element_comment)
(element
(self_closing_tag
(element_identifier)
(attribute
(attribute_name)
(quoted_attribute_value
(attribute_value)))
(attribute
(attribute_name)
(quoted_attribute_value
(attribute_value)))))
(tag_end
(element_identifier)))
(tag_end
(element_identifier))))))
8 changes: 1 addition & 7 deletions grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ module.exports = grammar(GO, {
externals: $ => [
$.css_property_value,
$.element_text,
$.element_comment,
$.style_element_text,
$.script_block_text,
$.script_element_text,
Expand Down Expand Up @@ -88,13 +89,6 @@ module.exports = grammar(GO, {
prec.right(1, $.comment),
),

// This matches HTML comment.
element_comment: $ => seq(
'<!--',
/[^-]*(?:-+[^->]+)*/,
'-->'
),

// This matches an if statement in a component block.
//
// Based on the $.if_statement rule of the Go grammar
Expand Down
21 changes: 4 additions & 17 deletions src/grammar.json
Original file line number Diff line number Diff line change
Expand Up @@ -7006,23 +7006,6 @@
}
]
},
"element_comment": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<!--"
},
{
"type": "PATTERN",
"value": "[^-]*(?:-+[^->]+)*"
},
{
"type": "STRING",
"value": "-->"
}
]
},
"component_if_statement": {
"type": "SEQ",
"members": [
Expand Down Expand Up @@ -8164,6 +8147,10 @@
"type": "SYMBOL",
"name": "element_text"
},
{
"type": "SYMBOL",
"name": "element_comment"
},
{
"type": "SYMBOL",
"name": "style_element_text"
Expand Down
17 changes: 4 additions & 13 deletions src/node-types.json
Original file line number Diff line number Diff line change
Expand Up @@ -1494,11 +1494,6 @@
]
}
},
{
"type": "element_comment",
"named": true,
"fields": {}
},
{
"type": "empty_statement",
"named": true,
Expand Down Expand Up @@ -3529,10 +3524,6 @@
"type": "--",
"named": false
},
{
"type": "-->",
"named": false
},
{
"type": "-=",
"named": false
Expand Down Expand Up @@ -3577,10 +3568,6 @@
"type": "<!",
"named": false
},
{
"type": "<!--",
"named": false
},
{
"type": "<-",
"named": false
Expand Down Expand Up @@ -3713,6 +3700,10 @@
"type": "defer",
"named": false
},
{
"type": "element_comment",
"named": true
},
{
"type": "element_identifier",
"named": true
Expand Down
Loading

0 comments on commit eab4f31

Please sign in to comment.