Better comments

Problem
-------
The following comment combinations are not parsed:
1. ```
// /*
// *
// */
```
2. ```
/* // */
```
Solution
-------
- set higher lexing priority for `$._comment_text` token
- include "//" as an alternative to the contents of `$.block_comment`
text_sliders
susliko 2023-06-12 15:48:51 +07:00
parent 199cf060ee
commit 0e89e94d5f
2 changed files with 31 additions and 6 deletions

@ -29,8 +29,33 @@ Block comments
(block_comment)
(block_comment
(block_comment
(block_comment)
(comment))))
(block_comment))))
================================================================================
Single line comments with block comment
================================================================================
// /*
// * This is awesome comment
// */
--------------------------------------------------------------------------------
(compilation_unit
(comment)
(comment)
(comment))
================================================================================
Block comment with single-line comment inside
================================================================================
/* // */
--------------------------------------------------------------------------------
(compilation_unit
(block_comment))
================================================================================
Using directives

@ -1,6 +1,6 @@
const PREC = {
comment: 0,
using_directive: 1,
comment: 1,
using_directive: 2,
control: 1,
stable_type_id: 2,
while: 2,
@ -1602,7 +1602,6 @@ module.exports = grammar({
),
comment: $ => seq(token("//"), choice($.using_directive, $._comment_text)),
_comment_text: $ => token(prec(PREC.comment, /.*/)),
using_directive: $ =>
@ -1615,7 +1614,8 @@ module.exports = grammar({
using_directive_key: $ => token(/[^\s]+/),
using_directive_value: $ => token(/.*/),
block_comment: $ => seq(token("/*"), repeat(token(/./)), token("*/")),
block_comment: $ =>
seq(token("/*"), repeat(choice(token(/./), token("//"))), token("*/")),
},
});