Skip to content

Commit

Permalink
[BatchFile] prevent ^ from counting as an escape for % (#4095)
Browse files Browse the repository at this point in the history
In batch scripts (but not on the command line itself), `%` is only escaped by another `%`
  • Loading branch information
God-damnit-all authored Nov 17, 2024
1 parent e90ba2a commit f794bce
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Batch File/Batch File.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ contexts:
- include: quoted-eol-pop

escaped-characters:
- match: \^.
- match: \^[^%\n]
scope: constant.character.escape.dosbatch

escaped-variables:
Expand Down
40 changes: 40 additions & 0 deletions Batch File/tests/syntax_test_batch_file.bat
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,12 @@ ECHO : Not a comment ^
::^^ - entity
:: ^ punctuation.definition.label.dosbatch
:: ^^ entity.name.label.dosbatch constant.character.escape.dosbatch - punctuation
:: ^ - entity

:^%
::^^ - entity
:: ^ punctuation.definition.label.dosbatch
:: ^^ entity.name.label.dosbatch - constant.character.escape - punctuation
:: ^ - entity

:%%
Expand Down Expand Up @@ -795,6 +801,17 @@ ECHO : Not a comment ^
:: ^ punctuation.definition.label.dosbatch
:: ^^^ variable.label.dosbatch - keyword
:: ^^ constant.character.escape.dosbatch
:: ^^ meta.number.integer.decimal.dosbatch constant.numeric.value.dosbatch

CALL :^% 10
::^ - meta.function-call
:: ^^^^^ meta.function-call.dosbatch
:: ^^^ meta.function-call.identifier.dosbatch
:: ^^^ meta.function-call.arguments.dosbatch
:: ^ - meta.function-call
:: ^^^^ keyword.control.flow.call.dosbatch
:: ^ punctuation.definition.label.dosbatch
:: ^^^ variable.label.dosbatch - keyword - constant.character
:: ^^ meta.number.integer.decimal.dosbatch constant.numeric.value.dosbatch

CALL :%% 10
Expand Down Expand Up @@ -1278,6 +1295,23 @@ bar baz
:: ^ variable.label.dosbatch
:: ^ - variable

GOTO ^%
:: ^^^^^^^ meta.command.goto.dosbatch
:: ^ - meta.command
:: ^^^^ keyword.control.flow.goto.dosbatch
:: ^ - keyword - variable
:: ^^ variable.label.dosbatch - constant.character
:: ^ - variable

GOTO ^%var%
:: ^^^^^^^^^^^ meta.command.goto.dosbatch
:: ^ - meta.command
:: ^^^^ keyword.control.flow.goto.dosbatch
:: ^ - keyword - variable
:: ^ variable.label.dosbatch - meta.interpolation - constant.character
:: ^^^^^ variable.label.dosbatch meta.interpolation.dosbatch - constant.character
:: ^ - variable

GOTO %var% ignored content ( & echo foo
:: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.command.goto.dosbatch
:: ^^^ - meta.command
Expand Down Expand Up @@ -2508,6 +2542,12 @@ put arg1 arg2
:: ^^^^^^^ meta.interpolation.dosbatch
:: ^ punctuation.section.interpolation.end.dosbatch

ren example.txt example_^%today%.txt
:: ^ - constant.character.escape
:: ^ punctuation.section.interpolation.begin.dosbatch
:: ^^^^^^^ meta.interpolation.dosbatch
:: ^ punctuation.section.interpolation.end.dosbatch

powershell get-date -uformat "%%Y%%m%%d">today.txt
:: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.arguments.dosbatch
:: ^^^^^^^^ - variable.parameter
Expand Down

0 comments on commit f794bce

Please sign in to comment.