Add comments

For now it only supports non-nested comments. It seems like I *will*
need to write an external lexer to account for nesting properly.
This commit is contained in:
Bruno BELANYI 2022-06-02 11:03:55 +02:00
parent e5e958cac9
commit 75bb2c7009
5 changed files with 2239 additions and 1718 deletions

View file

@ -25,12 +25,32 @@ module.exports = grammar({
[$._lvalue, $.array_expression],
],
extras: ($) => [
/( |\n|\r|\t)+/,
$.comment,
],
rules: {
source_file: ($) => choice(
$._expr,
optional($._declaration_chunks),
),
comment: ($) => token(
seq(
"/*",
repeat(
choice(
// Match anything but the end-delimiter
/(\*[^/]|[^*])+/,
// Comments can be nested
// $.comment,
),
),
"*/",
),
),
// Expressions {{{
_expr: ($) => choice(