Skip to content

Commit

Permalink
[Batch File] Fix empty comments exceeding to next line
Browse files Browse the repository at this point in the history
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 sublimehq#3992.
  • Loading branch information
deathaxe committed Jun 20, 2024
1 parent 6818519 commit 3406779
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Batch File/Batch File.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -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}}]'
Expand Down
36 changes: 27 additions & 9 deletions Batch File/tests/syntax_test_batch_file.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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
Expand Down Expand Up @@ -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 ] :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

@
Expand Down

0 comments on commit 3406779

Please sign in to comment.