Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[batch] prevent ^ from counting as an escape for % #4095

Merged
merged 2 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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