Page 2 of 2

Re: Examination of Linefeeds with CALL

Posted: 13 Jun 2019 18:43
by dbenham
No, because the newlines don't exist until after phase 1 is complete. Within Phase 1, only the outer loop looks for <LF> to truncate. After the %\n% gets replaced, the outer loop scanner continues with the next character after the replacement, so the <LF> is never seen by the scanner, and it is safe.


Dave Benham

Re: Examination of Linefeeds with CALL

Posted: 14 Jun 2019 00:53
by jeb
Hi Dave,

it's hard to remember all the problems parsing CALL/LF variables.

I retested some of the behaviour and I suppose your rules are correct now.

jeb

Re: Examination of Linefeeds with CALL

Posted: 14 Jun 2019 07:11
by dbenham
Below is evidence that Phase 0 preserves the end of line newline, and that phase 1 truly truncates the line at the first appearing newline not within expanding percents. Also, percent expansion error is not fatal after CALL.

It is important that the last line of the script does not end with a newline.

Code: Select all

@echo off
if "%~1" neq "" goto %1
setlocal
set var=CONTENT

(set \n=^
%= Creates a newline character =%
)

for /l %%N in (1 1 4) do (
  echo ====== TEST %%N ======
  cmd /v:on /c ^""%~f0" test%%N^"
  echo --------------------
)
exit /b

:test1
call echo %%var:=WRONG SYNTAX!\n!%% NEWLINE PRESERVED WITHIN PERCENTS
echo The syntax error is not fatal after CALL
exit /b

:test2
call echo Line truncated at newline so no error!\n! %%var:=WRONG SYNTAX%%
exit /b

:test3
%var:=WRONG SYNTAX% THE END-OF-LINE NEWLINE IS PRESERVED AFTER PHASE 0

:test4
%var:=WRONG SYNTAX% THIS LINE HAS NO NEWLINE, SO ERROR MESSAGE NOT SPLIT
OUTPUT wrote: ====== TEST 1 ======
=WRONG SYNTAX
% NEWLINE PRESERVED WITHIN PERCENTS was unexpected at this time.
The syntax error is not fatal after CALL
--------------------
====== TEST 2 ======
Line truncated at newline so no error
--------------------
====== TEST 3 ======
=WRONG SYNTAX% THE END-OF-LINE NEWLINE IS PRESERVED AFTER PHASE 0
was unexpected at this time.
The syntax of the command is incorrect.
--------------------
====== TEST 4 ======
=WRONG SYNTAX% THIS LINE HAS NO NEWLINE, SO ERROR MESSAGE NOT SPLIT was unexpected at this time.
The syntax of the command is incorrect.
--------------------

Dave Benham

Re: Examination of Linefeeds with CALL

Posted: 24 Jun 2019 11:05
by dbenham
I just realized I had to make another change to step 2.3 in the phase rules - Both the search and replace terms allow <LF> characters.

I also corrected step 5.2 in delayed expansion to also allow <LF> in search and replace terms. Not sure why this one wasn't caught ages ago.


Dave Benham