Add \-continuation to CMake language quoted arguments

Teach the CMake language lexer to treat the \-LF pair terminating a
line ending in an odd number of backslashes inside a quoted argument
as a continuation.  Drop the pair from the returned quoted argument
token text.  This will allow long lines inside quoted argument
strings to be divided across multiple lines in the source file.
It will also allow quoted argument text to start on the line after
the opening quote.  For example, the code:

 set(x "\
 ...")

sets variable "x" to the value "..." with no opening newline.

Previously an odd number of backslashes at the end of a line inside
a quoted argument would put a \-LF pair (or a \-CR pair) literally
in the argument.  Then the command-argument evaluator would complain
that the \-escape sequence is invalid.  Therefore this syntax is
available to use without changing behavior of valid existing code.

Teach the RunCMake.Syntax test to cover cases of quoted arguments
with lines ending in \, \\, and \\\.  Odd counts are continuations.
This commit is contained in:
Brad King 2013-10-22 18:11:22 -04:00
parent e48faced66
commit efcf318f8d
12 changed files with 28 additions and 2 deletions

View File

@ -1127,7 +1127,7 @@ case 17:
YY_RULE_SETUP
#line 224 "cmListFileLexer.in.l"
{
cmListFileLexerAppend(lexer, yytext, yyleng);
/* Continuation: text is not part of string */
++lexer->line;
lexer->column = 1;
}

View File

@ -222,7 +222,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
}
<STRING>\\\n {
cmListFileLexerAppend(lexer, yytext, yyleng);
/* Continuation: text is not part of string */
++lexer->line;
lexer->column = 1;
}

View File

@ -14,7 +14,10 @@ run_cmake(CommandError1)
run_cmake(CommandError2)
run_cmake(String0)
run_cmake(String1)
run_cmake(StringBackslash)
run_cmake(StringCRLF)
run_cmake(StringContinuation1)
run_cmake(StringContinuation2)
run_cmake(StringNoSpace)
run_cmake(OneLetter)
run_cmake(Unquoted0)

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,6 @@
CMake Error at StringBackslash.cmake:1 \(message\):
a\\
b
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
message(FATAL_ERROR "a\\
b")

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
CMake Error at StringContinuation1.cmake:1 \(message\):
ab
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
message(FATAL_ERROR "a\
b")

View File

@ -0,0 +1 @@
1

View File

@ -0,0 +1,4 @@
CMake Error at StringContinuation2.cmake:1 \(message\):
a\\b
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)

View File

@ -0,0 +1,2 @@
message(FATAL_ERROR "a\\\
b")