Merge pull request #241 from nmote/html

Add HTML comments
pull/502/head
Yoann Padioleau 2023-02-24 13:50:01 +07:00 committed by GitHub
commit 5720b24949
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 25262 additions and 24798 deletions

@ -951,7 +951,18 @@ module.exports = grammar({
'/*',
/[^*]*\*+([^/*][^*]*\*+)*/,
'/'
)
),
// https://tc39.es/ecma262/#sec-html-like-comments
seq('<!--', /.*/),
// This allows code to exist before this token on the same line.
//
// Technically, --> is supposed to have nothing before it on the same line
// except for comments and whitespace, but that is difficult to express,
// and in general tree sitter grammars tend to prefer to be overly
// permissive anyway.
//
// This approach does not appear to cause problems in practice.
seq('-->', /.*/)
)),
template_string: $ => seq(

26
src/grammar.json vendored

@ -4960,6 +4960,32 @@
"value": "/"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "<!--"
},
{
"type": "PATTERN",
"value": ".*"
}
]
},
{
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "-->"
},
{
"type": "PATTERN",
"value": ".*"
}
]
}
]
}

49987
src/parser.c vendored

File diff suppressed because it is too large Load Diff

@ -648,6 +648,40 @@ y // comment
(program (expression_statement
(binary_expression (identifier) (comment) (identifier))))
==========================================
HTML Comments
==========================================
<!-- we can put whatever we like here. this affects one line only.
y * z;
<!-- and here as well. these do not have to have matching close comments.
x + 1; --> for some reason you can put text after a close comment.
--> note that the x + 1 above should be rejected according to the spec.
--> it should instead be rejected as invalid.
--> you are supposed to only have whitespace or comments before
--> an HTML close comment.
---
(program
(comment)
(expression_statement
(binary_expression
(identifier)
(identifier)))
(comment)
(expression_statement
(binary_expression
(identifier)
(number)))
(comment)
(comment)
(comment)
(comment)
(comment))
============================================
Switch statements
============================================