From 340677972f07c19c6775e22dcf5040518f35127c Mon Sep 17 00:00:00 2001 From: deathaxe Date: Wed, 19 Jun 2024 17:29:15 +0200 Subject: [PATCH] [Batch File] Fix empty comments exceeding to next line This commit fixes "label comment" related patterns, to only scope leading colons `punctuation.definition.comment`. Label comments make use of invalid labels being ignored. A label is invalid, if the first character after leading colon is a "metachar". A label starting with `::` is already an invalid label and thus can be followed by any (meta) char to still be a "valid" comment. The wrong pattern was the real reason for the issue addressed by PR #3992. --- Batch File/Batch File.sublime-syntax | 2 +- Batch File/tests/syntax_test_batch_file.bat | 36 +++++++++++++++------ 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/Batch File/Batch File.sublime-syntax b/Batch File/Batch File.sublime-syntax index c2bc3c1508b..3b8a1070f84 100644 --- a/Batch File/Batch File.sublime-syntax +++ b/Batch File/Batch File.sublime-syntax @@ -48,7 +48,7 @@ variables: eoc: (?=\s*{{eoc_char}}) eoc_char: '[\n|&]' - label_comment: ':+[^{{label_start}}]' + label_comment: ':(?::+|(?!{{label_start}}))' label_start: '[^{{metachar}}:+]' path_terminator_chars: '[\s,;"{{redir_or_eoc_char}}]' diff --git a/Batch File/tests/syntax_test_batch_file.bat b/Batch File/tests/syntax_test_batch_file.bat index 1628327dcd7..08c70851fcc 100644 --- a/Batch File/tests/syntax_test_batch_file.bat +++ b/Batch File/tests/syntax_test_batch_file.bat @@ -68,19 +68,19 @@ continuation :: ^^^^^^^^^^ comment.line.colon.dosbatch :+ Me too! -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch := Me too! -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch :, Me too! -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch :; Me too! -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch : Me too! -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch ::^ Me too! @@ -97,19 +97,19 @@ continuation :> ignored content ( & | ) :: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.colon.dosbatch -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch :< ignored content ( & | ) :: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.colon.dosbatch -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch :& ignored content ( & | ) :: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.colon.dosbatch -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch :| ignored content ( & | ) :: ^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.colon.dosbatch -:: ^^ punctuation.definition.comment.dosbatch +:: ^ punctuation.definition.comment.dosbatch ECHO &&:: A comment :: ^^ keyword.operator.logical.dosbatch @@ -139,6 +139,24 @@ ECHO : Not a comment ^ :: <- - comment ::^^^^^^^^^^^^ - comment +: empty comment line, followed by command +: +ECHO Not a comment +:: <- - comment +::^^^^^^^^^^^^^^^^ - comment + +:: empty comment line, followed by command +:: +ECHO Not a comment +:: <- - comment +::^^^^^^^^^^^^^^^^ - comment + +::: empty comment line, followed by command +::: +ECHO Not a comment +:: <- - comment +::^^^^^^^^^^^^^^^^ - comment + :::: [ @ Operator ] ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: @