Add support for nested comments

Unfortunately, the 'extras' array expects single tokens only, so one
can't really use a recursive parsing rule to express nesting comments...
This commit is contained in:
Bruno BELANYI 2022-06-02 16:13:55 +02:00
parent 75bb2c7009
commit 50a0eaa071
5 changed files with 1672 additions and 1661 deletions

View file

@ -25,6 +25,11 @@ module.exports = grammar({
[$._lvalue, $.array_expression],
],
externals: ($) => [
// Nested comments need to be tokenized externally
$.comment,
],
extras: ($) => [
/( |\n|\r|\t)+/,
$.comment,
@ -36,21 +41,6 @@ module.exports = grammar({
optional($._declaration_chunks),
),
comment: ($) => token(
seq(
"/*",
repeat(
choice(
// Match anything but the end-delimiter
/(\*[^/]|[^*])+/,
// Comments can be nested
// $.comment,
),
),
"*/",
),
),
// Expressions {{{
_expr: ($) => choice(