From be1e3f07d3099756026300c4e0fa2edf994d79af Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Mon, 8 Apr 2024 09:49:16 +0000 Subject: [PATCH] Make 'line_comment' more explicit about newlines Because of the way regular expressions work, they were already bounded at newlines here, but explicit is better than implicit :-). --- grammar.js | 2 +- src/grammar.json | 2 +- test/corpus/comments.txt | 17 +++++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/grammar.js b/grammar.js index 86d0dd6..929f36e 100644 --- a/grammar.js +++ b/grammar.js @@ -23,7 +23,7 @@ module.exports = grammar({ $.module, ), - line_comment: (_) => seq("//", /.*/), + line_comment: (_) => seq("//", /[^\n]*/), block_comment: (_) => seq("/*", /[^*]*\*+([^/*][^*]*\*+)*/, '/'), diff --git a/src/grammar.json b/src/grammar.json index c9b0e32..2ac5436 100644 --- a/src/grammar.json +++ b/src/grammar.json @@ -30,7 +30,7 @@ }, { "type": "PATTERN", - "value": ".*" + "value": "[^\\n]*" } ] }, diff --git a/test/corpus/comments.txt b/test/corpus/comments.txt index 5304a7e..6c91a89 100644 --- a/test/corpus/comments.txt +++ b/test/corpus/comments.txt @@ -85,6 +85,23 @@ Block comment with asterisks -------------------------------------------------------------------------------- +(source_file + (block_comment)) + +================================================================================ +Block comment (multiline) +================================================================================ + +/* + This + is + a + long + comment +*/ + +-------------------------------------------------------------------------------- + (source_file (block_comment))