From efcf318f8d56a8bc405fa4af3d4c4b7e8227da3c Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 22 Oct 2013 18:11:22 -0400 Subject: [PATCH] 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. --- Source/cmListFileLexer.c | 2 +- Source/cmListFileLexer.in.l | 2 +- Tests/RunCMake/Syntax/RunCMakeTest.cmake | 3 +++ Tests/RunCMake/Syntax/StringBackslash-result.txt | 1 + Tests/RunCMake/Syntax/StringBackslash-stderr.txt | 6 ++++++ Tests/RunCMake/Syntax/StringBackslash.cmake | 2 ++ Tests/RunCMake/Syntax/StringContinuation1-result.txt | 1 + Tests/RunCMake/Syntax/StringContinuation1-stderr.txt | 4 ++++ Tests/RunCMake/Syntax/StringContinuation1.cmake | 2 ++ Tests/RunCMake/Syntax/StringContinuation2-result.txt | 1 + Tests/RunCMake/Syntax/StringContinuation2-stderr.txt | 4 ++++ Tests/RunCMake/Syntax/StringContinuation2.cmake | 2 ++ 12 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/Syntax/StringBackslash-result.txt create mode 100644 Tests/RunCMake/Syntax/StringBackslash-stderr.txt create mode 100644 Tests/RunCMake/Syntax/StringBackslash.cmake create mode 100644 Tests/RunCMake/Syntax/StringContinuation1-result.txt create mode 100644 Tests/RunCMake/Syntax/StringContinuation1-stderr.txt create mode 100644 Tests/RunCMake/Syntax/StringContinuation1.cmake create mode 100644 Tests/RunCMake/Syntax/StringContinuation2-result.txt create mode 100644 Tests/RunCMake/Syntax/StringContinuation2-stderr.txt create mode 100644 Tests/RunCMake/Syntax/StringContinuation2.cmake diff --git a/Source/cmListFileLexer.c b/Source/cmListFileLexer.c index 3b08b03c1..be27884a5 100644 --- a/Source/cmListFileLexer.c +++ b/Source/cmListFileLexer.c @@ -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; } diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l index ecaf156e9..d45a8ea50 100644 --- a/Source/cmListFileLexer.in.l +++ b/Source/cmListFileLexer.in.l @@ -222,7 +222,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\" } \\\n { - cmListFileLexerAppend(lexer, yytext, yyleng); + /* Continuation: text is not part of string */ ++lexer->line; lexer->column = 1; } diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake index f5e0d11e0..2d49f7684 100644 --- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake +++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake @@ -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) diff --git a/Tests/RunCMake/Syntax/StringBackslash-result.txt b/Tests/RunCMake/Syntax/StringBackslash-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/StringBackslash-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/StringBackslash-stderr.txt b/Tests/RunCMake/Syntax/StringBackslash-stderr.txt new file mode 100644 index 000000000..214f91439 --- /dev/null +++ b/Tests/RunCMake/Syntax/StringBackslash-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at StringBackslash.cmake:1 \(message\): + a\\ + + b +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/StringBackslash.cmake b/Tests/RunCMake/Syntax/StringBackslash.cmake new file mode 100644 index 000000000..066be965d --- /dev/null +++ b/Tests/RunCMake/Syntax/StringBackslash.cmake @@ -0,0 +1,2 @@ +message(FATAL_ERROR "a\\ +b") diff --git a/Tests/RunCMake/Syntax/StringContinuation1-result.txt b/Tests/RunCMake/Syntax/StringContinuation1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/StringContinuation1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/StringContinuation1-stderr.txt b/Tests/RunCMake/Syntax/StringContinuation1-stderr.txt new file mode 100644 index 000000000..05771da2a --- /dev/null +++ b/Tests/RunCMake/Syntax/StringContinuation1-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at StringContinuation1.cmake:1 \(message\): + ab +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/StringContinuation1.cmake b/Tests/RunCMake/Syntax/StringContinuation1.cmake new file mode 100644 index 000000000..ae86bb22c --- /dev/null +++ b/Tests/RunCMake/Syntax/StringContinuation1.cmake @@ -0,0 +1,2 @@ +message(FATAL_ERROR "a\ +b") diff --git a/Tests/RunCMake/Syntax/StringContinuation2-result.txt b/Tests/RunCMake/Syntax/StringContinuation2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/StringContinuation2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/StringContinuation2-stderr.txt b/Tests/RunCMake/Syntax/StringContinuation2-stderr.txt new file mode 100644 index 000000000..2f4964ca9 --- /dev/null +++ b/Tests/RunCMake/Syntax/StringContinuation2-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at StringContinuation2.cmake:1 \(message\): + a\\b +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/StringContinuation2.cmake b/Tests/RunCMake/Syntax/StringContinuation2.cmake new file mode 100644 index 000000000..490a40890 --- /dev/null +++ b/Tests/RunCMake/Syntax/StringContinuation2.cmake @@ -0,0 +1,2 @@ +message(FATAL_ERROR "a\\\ +b")