Add block comments

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

View file

@ -12,6 +12,7 @@ module.exports = grammar({
extras: ($) => [ extras: ($) => [
/\s+/, /\s+/,
$.line_comment, $.line_comment,
$.block_comment,
], ],
rules: { rules: {
@ -24,6 +25,8 @@ module.exports = grammar({
line_comment: (_) => seq("//", /.*/), line_comment: (_) => seq("//", /.*/),
block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'),
// Definitions {{{ // Definitions {{{
assignment: ($) => seq( 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": { "assignment": {
"type": "SEQ", "type": "SEQ",
"members": [ "members": [
@ -936,6 +953,10 @@
{ {
"type": "SYMBOL", "type": "SYMBOL",
"name": "line_comment" "name": "line_comment"
},
{
"type": "SYMBOL",
"name": "block_comment"
} }
], ],
"conflicts": [], "conflicts": [],

13
src/node-types.json generated
View file

@ -167,6 +167,11 @@
} }
} }
}, },
{
"type": "block_comment",
"named": true,
"fields": {}
},
{ {
"type": "boolean_literal", "type": "boolean_literal",
"named": true, "named": true,
@ -648,6 +653,14 @@
"type": "-", "type": "-",
"named": false "named": false
}, },
{
"type": "/",
"named": false
},
{
"type": "/*",
"named": false
},
{ {
"type": "//", "type": "//",
"named": false "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 (source_file
(line_comment) (line_comment)
(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 '*')))