<commit_before>@echo off

:: http://forum.script-coding.com/viewtopic.php?pid=94390#p94390
if not defined CMDCALLER (
	(echo on & goto) 2>nul
	call set "CMDCALLER=%%~f0"
	call "%~f0" %*
	set "CMDCALLER="
)
if /i "%CMDCALLER%" == "%%~f0" set "CMDCALLER="


if defined CMDCALLER (
	call :heredoc %*
	goto :EOF
)


call :heredoc :HEREDOCHELP & goto :EOF
heredoc: attempt to embed the idea of heredoc to batch scripts.

There are few ways for using this solution:

1. call heredoc :LABEL & goto :LABEL
Calling the external script "heredoc.bat" passing the heredoc LABEL. 

2. call :heredoc :LABEL & goto :LABEL
Embed the subroutine ":heredoc" into yuor script.

NOTES:
Both LABEL and :LABEL forms are possible. Instead of "goto :LABEL" it is 
possible to use "goto" with another label, or "goto :EOF", or "exit /b".

Variables to be evaluated within the heredoc should be called in the 
delayed expansion style ^("^!var^!" rather than "%var%", for instance^).

Literal exclamation marks "^!" and carets "^^" must be escaped with a 
caret "^".

Additionally, parantheses "(" and ")" should be escaped, as well, if they 
are part of the heredoc content within parantheses of the script block.
:HEREDOCHELP


:: http://stackoverflow.com/a/15032476/3627676
:heredoc LABEL
setlocal enabledelayedexpansion
if not defined CMDCALLER set "CMDCALLER=%~f0"
set go=
for /f "delims=" %%A in ( '
	findstr /n "^" "%CMDCALLER%"
' ) do (
	set "line=%%A"
	set "line=!line:*:=!"

	if defined go (
		if /i "!line!" == "!go!" goto :EOF
		echo:!line!
	) else (
		rem delims are ( ) > & | TAB , ; = SPACE
		for /f "tokens=1-3 delims=()>&|	,;= " %%i in ( "!line!" ) do (
			if /i "%%i %%j %%k" == "call :heredoc %1" set "go=%%k"
			if /i "%%i %%j %%k" == "call heredoc %1" set "go=%%k"<commit_msg>heredoc.bat improved<commit_after>:: http://forum.script-coding.com/viewtopic.php?pid=94390#p94390
@if not defined CMDCALLER @(
	(echo on & goto) 2>nul
	call set "CMDCALLER=%%~f0"
	call "%~f0" %*
	set "CMDCALLER="
)
@if /i "%CMDCALLER%" == "%%~f0" set "CMDCALLER="


@echo off

if defined CMDCALLER (
	call :heredoc %*
	goto :EOF
)


call :heredoc :HEREDOCHELP & goto :EOF
heredoc: attempt to embed the idea of heredoc to batch scripts.

There are few ways for using this solution:

1. call heredoc :LABEL & goto :LABEL
Calling the external script "heredoc.bat" passing the heredoc LABEL. 

2. call :heredoc :LABEL & goto :LABEL
Embed the subroutine ":heredoc" into yuor script.

NOTES:
Both LABEL and :LABEL forms are possible. Instead of "goto :LABEL" it is 
possible to use "goto" with another label, or "goto :EOF", or "exit /b".

Variables to be evaluated within the heredoc should be called in the 
delayed expansion style ^("^!var^!" rather than "%var%", for instance^).

Literal exclamation marks "^!" and carets "^^" must be escaped with a 
caret "^".

Additionally, parantheses "(" and ")" should be escaped, as well, if they 
are part of the heredoc content within parantheses of the script block.
:HEREDOCHELP


:: http://stackoverflow.com/a/15032476/3627676
:heredoc LABEL
setlocal enabledelayedexpansion
if not defined CMDCALLER set "CMDCALLER=%~f0"
set go=
for /f "delims=" %%A in ( '
	findstr /n "^" "%CMDCALLER%"
' ) do (
	set "line=%%A"
	set "line=!line:*:=!"

	if defined go (
		if /i "!line!" == "!go!" goto :EOF
		echo:!line!
	) else (
		rem delims are @ ( ) > & | TAB , ; = SPACE
		for /f "tokens=1-3 delims=@()>&|	,;= " %%i in ( "!line!" ) do (
			if /i "%%i %%j %%k" == "call :heredoc %1" set "go=%%k"
			if /i "%%i %%j %%k" == "call heredoc %1" set "go=%%k"
{'fraction_non_alphanumeric': 0.15713883413123064, 'fraction_numerical': 0.020275978597578147, 'mean_word_length': 3.9747899159663866, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1015963', 'n_tokens_mistral': 1443, 'n_tokens_neox': 1320, 'n_words': 471}