Skip to content

Commit

Permalink
tree-sitter: fix parsing of nested comments, extend tests (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
ttytm authored Mar 31, 2024
1 parent 819d9c4 commit 671fce5
Show file tree
Hide file tree
Showing 5 changed files with 199,730 additions and 199,951 deletions.
26 changes: 24 additions & 2 deletions tree_sitter_v/grammar.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,17 @@ module.exports = grammar({
block_comment: (_) =>
seq(
'/*',
token(choice(/(?:[^/][^*]+\/\*+[^/][^*]+)+(?:[^*][^/]+\*+\/[^*][^/]+)+/, /[^*]*\*/)),
'/',
repeat(
choice(
/\*/,
regexOr(
'[^*]', // any symbol except reserved
'[/][^*]', // start of nested comment
'[^*][/]', // end of nested comment
),
),
),
'*/',
),

comment: ($) => choice($.line_comment, $.block_comment),
Expand Down Expand Up @@ -1328,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,
};
}
8 changes: 4 additions & 4 deletions tree_sitter_v/src/grammar.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions tree_sitter_v/src/node-types.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 671fce5

Please sign in to comment.