I will try to discover a bit the rules for legal label names and how they work.
Normally you choose a name containing numbers and characters.
But you could also use any character with different effects.
Code: Select all
set "amp=^&"
set "pipe=^|"
set "lt=^<"
set "gt=^>"
call :%%%%this%%%%"label"^looks:%%lt%%a%%pipe%%bit%%gt%%^^odd
exit /b
:%this%"label"^looks<quite|a> ^^:+bit&normally
echo The function is called via "%0"
exit /b
Output wrote:The function is called via ":%this%"label"looks:<a|bit>^odd"
It seems that the label does not fit to the calling name, but both labels and call-names have different rules.
A call-name (the destination label behind a CALL) is parsed normally and stored in %0 by the normal argument rules.
But the destination label can be shorter than %0, as there exists some STOP characters.
Code: Select all
+:,;= <space>,<TAB> and <LF>
These characters stop the call-name, independent if they are escaped or quoted.
There exists some more characters which can be used, but they are a bit more tricky to handle, like
Code: Select all
|&<>(
They can be used but only with late expansion in the call.
Like
Code: Select all
set "amp=^&"
call :Test%%amp%%yes
exit /b
:test^&yes
echo Called by "%0"
exit /b
At this point it's necessary to understand, how the CALL build the name. As each CALL parses a line two times, you need to escape each special character two times.
And as you can't escape it directly two times with carets, I used here late percent expansion.
You could also use the late expansion only for the caret, like
Code: Select all
set "caret=^"
call :test%%caret%%^&yes
exit /b
:test^&yes
echo Called by "%0"
exit /b
GOTO is similar to CALL, but as it uses only one parse phase, it's easier to create the GOTO-names.
Now the label names.
They also use STOP characters, but not the same, I only know two
Code: Select all
:+
So these labels are equivalent
Code: Select all
:one
:one:two
:one+two
:one^
Btw. label names have completly different parser phases, only a bit escaping is done,
but the percent expansion nor the remove phase for CR's are executed.
A caret escape the next character, even in quotes, but it can't be used as multiline character (for the label name).
And a label can be found even if it does not begin with a colon
These labels are all equivalent
Code: Select all
:label
=,,;; ,;= :label
X =,,;; ,;= :label
< :label
The rule is here:
<Anyone character or none> followed by any ,;=<space> then the colon and the name.
This can sometimes be handy.
Code: Select all
@echo off
cls
call :#;#
%:#+~%,=*
>=,;=;,,=,;:%%+,=;echo\=%01>&2&call=;:%%%%%%%%;%*
echo *%*
hope it helps
jeb