Add block comments

This commit is contained in:
Bruno BELANYI 2024-04-08 08:48:10 +01:00
parent f76248b670
commit 540f28e55e
5 changed files with 2347 additions and 1744 deletions

View file

@ -12,6 +12,7 @@ module.exports = grammar({
extras: ($) => [
/\s+/,
$.line_comment,
$.block_comment,
],
rules: {
@ -24,6 +25,8 @@ module.exports = grammar({
line_comment: (_) => seq("//", /.*/),
block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'),
// Definitions {{{
assignment: ($) => seq(

21
src/grammar.json generated
View file

@ -34,6 +34,23 @@
}
]
},
"block_comment": {
"type": "SEQ",
"members": [
{
"type": "STRING",
"value": "/*"
},
{
"type": "PATTERN",
"value": "[^*]*\\*+([^/*][^*]*\\*+)*"
},
{
"type": "STRING",
"value": "/"
}
]
},
"assignment": {
"type": "SEQ",
"members": [
@ -936,6 +953,10 @@
{
"type": "SYMBOL",
"name": "line_comment"
},
{
"type": "SYMBOL",
"name": "block_comment"
}
],
"conflicts": [],

13
src/node-types.json generated
View file

@ -167,6 +167,11 @@
}
}
},
{
"type": "block_comment",
"named": true,
"fields": {}
},
{
"type": "boolean_literal",
"named": true,
@ -648,6 +653,14 @@
"type": "-",
"named": false
},
{
"type": "/",
"named": false
},
{
"type": "/*",
"named": false
},
{
"type": "//",
"named": false

3965
src/parser.c generated

File diff suppressed because it is too large Load diff

View file

@ -32,3 +32,92 @@ Multiple comments
(source_file
(line_comment)
(line_comment))
================================================================================
Empty block comment
================================================================================
/**/
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Whitespace block comment
================================================================================
/* */
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Block comment
================================================================================
/* This is a comment */
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Block comment with slashes
================================================================================
/* /// */
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Block comment with asterisks
================================================================================
/* *** */
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Block comment is not recursive
================================================================================
/* /* */
--------------------------------------------------------------------------------
(source_file
(block_comment))
================================================================================
Unterminated comment
================================================================================
/*
--------------------------------------------------------------------------------
(source_file
(ERROR))
================================================================================
Comment end-delimiter only
================================================================================
*/
--------------------------------------------------------------------------------
(source_file
(ERROR
(UNEXPECTED '*')))