Commit efcf318f authored by Brad King's avatar Brad King

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.
parent e48faced
......@@ -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;
}
......
......@@ -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;
}
......
......@@ -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)
......
CMake Error at StringBackslash.cmake:1 \(message\):
a\\
b
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
CMake Error at StringContinuation1.cmake:1 \(message\):
ab
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
CMake Error at StringContinuation2.cmake:1 \(message\):
a\\b
Call Stack \(most recent call first\):
CMakeLists.txt:3 \(include\)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment