diff --git a/tree_sitter_v/grammar.js b/tree_sitter_v/grammar.js index 7621c078..16a44dca 100644 --- a/tree_sitter_v/grammar.js +++ b/tree_sitter_v/grammar.js @@ -128,16 +128,20 @@ module.exports = grammar({ line_comment: (_) => seq('//', /.*/), - block_comment: ($) => - token( - seq( - '/*', + block_comment: (_) => + seq( + '/*', + repeat( choice( - /[^*]*\*+([^/*][^*]*\*+)*/, // Block comment body. - /(?:[^/][^*]+\/\*+[^/][^*]+)+(?:[^*][^/]+\*+\/[^*][^/]+)+/, // Nested block comment body. + /\*/, + regexOr( + '[^*]', // any symbol except reserved + '[/][^*]', // start of nested comment + '[^*][/]', // end of nested comment + ), ), - '/', ), + '*/', ), comment: ($) => choice($.line_comment, $.block_comment), @@ -1333,3 +1337,16 @@ function comma_sep1(rules) { function comma_sep(rule) { return optional(comma_sep1(rule)); } + +/** + * @param {...string} args - One or more regular expression patterns. + * + * @return {PatternRule} + */ +function regexOr(...args) { + const regex = args.length > 1 ? args.join('|') : args[0]; + return { + type: 'PATTERN', + value: regex, + }; +}