Skip to content

Commit

Permalink
final
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm committed Mar 31, 2024
1 parent f35dc40 commit ca6a863
Showing 1 changed file with 24 additions and 7 deletions.
31 changes: 24 additions & 7 deletions tree_sitter_v/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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,
};
}

0 comments on commit ca6a863

Please sign in to comment.