From 56457837e28de29d4f94b0cc9c47ef314d8f05e1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Oct 2013 15:24:06 -0400 Subject: [PATCH 1/4] cmListFileLexer: Allow command names with one letter (#14181) Teach the lexer to treat a single letter as an identifier instead of an unquoted argument. Outside of a command invocation, the parser treats an identifier as a command name and an unquoted argument as an error. Inside of a command invocation, the parser treats an identifier as an unquoted argument. Therefore this change to the lexer will make what was previously an error case work with no other behavioral change. --- Source/cmListFileLexer.c | 2 +- Source/cmListFileLexer.in.l | 2 +- Tests/RunCMake/Syntax/OneLetter-stderr.txt | 1 + Tests/RunCMake/Syntax/OneLetter.cmake | 7 +++++++ Tests/RunCMake/Syntax/RunCMakeTest.cmake | 1 + 5 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 Tests/RunCMake/Syntax/OneLetter-stderr.txt create mode 100644 Tests/RunCMake/Syntax/OneLetter.cmake diff --git a/Source/cmListFileLexer.c b/Source/cmListFileLexer.c index f127adde7..ad5a83d3d 100644 --- a/Source/cmListFileLexer.c +++ b/Source/cmListFileLexer.c @@ -381,7 +381,7 @@ struct yy_trans_info static yyconst flex_int16_t yy_accept[45] = { 0, 0, 0, 0, 0, 17, 6, 14, 1, 8, 2, - 6, 3, 4, 6, 15, 9, 11, 12, 13, 6, + 6, 3, 4, 5, 15, 9, 11, 12, 13, 6, 0, 6, 0, 14, 2, 0, 5, 6, 9, 0, 10, 0, 7, 0, 0, 0, 7, 0, 7, 0, 0, 0, 0, 0 diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l index bd3c1eb27..89f29173a 100644 --- a/Source/cmListFileLexer.in.l +++ b/Source/cmListFileLexer.in.l @@ -107,7 +107,7 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t])*\" return 1; } -[A-Za-z_][A-Za-z0-9_]+ { +[A-Za-z_][A-Za-z0-9_]* { lexer->token.type = cmListFileLexer_Token_Identifier; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; diff --git a/Tests/RunCMake/Syntax/OneLetter-stderr.txt b/Tests/RunCMake/Syntax/OneLetter-stderr.txt new file mode 100644 index 000000000..87c01c71c --- /dev/null +++ b/Tests/RunCMake/Syntax/OneLetter-stderr.txt @@ -0,0 +1 @@ +message diff --git a/Tests/RunCMake/Syntax/OneLetter.cmake b/Tests/RunCMake/Syntax/OneLetter.cmake new file mode 100644 index 000000000..3c341fab0 --- /dev/null +++ b/Tests/RunCMake/Syntax/OneLetter.cmake @@ -0,0 +1,7 @@ +function(f) + g(${ARGN}) +endfunction() +macro(g) + message(${ARGN}) +endmacro() +f(message) diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake index 94963f348..2d87328e8 100644 --- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake +++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake @@ -9,6 +9,7 @@ run_cmake(CommandError1) run_cmake(String0) run_cmake(String1) run_cmake(StringNoSpace) +run_cmake(OneLetter) run_cmake(Unquoted0) run_cmake(Unquoted1) run_cmake(ParenNoSpace) From dbd933365ec780d27ab7c0dfba30dc1af1094607 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Oct 2013 15:13:11 -0400 Subject: [PATCH 2/4] cmListFileLexer: Allow a leading UTF-8 Byte-Order-Mark (#11137) Teach the lexer to read a UTF-8, UTF-16 BE/LE, or UTF-32 BE/LE Byte-Order-Mark from the start of a file if any is present. Report an error on files using UTF-16 or UTF-32 and accept a UTF-8 or missing BOM. --- Source/cmListFileCache.cxx | 15 ++++- Source/cmListFileLexer.c | 57 ++++++++++++++++-- Source/cmListFileLexer.h | 14 ++++- Source/cmListFileLexer.in.l | 57 ++++++++++++++++-- .../RunCMake/Syntax/BOM-UTF-16-BE-result.txt | 1 + .../RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt | 6 ++ Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake | Bin 0 -> 54 bytes .../RunCMake/Syntax/BOM-UTF-16-LE-result.txt | 1 + .../RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt | 6 ++ Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake | Bin 0 -> 54 bytes .../RunCMake/Syntax/BOM-UTF-32-BE-result.txt | 1 + .../RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt | 6 ++ Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake | Bin 0 -> 108 bytes .../RunCMake/Syntax/BOM-UTF-32-LE-result.txt | 1 + .../RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt | 6 ++ Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake | Bin 0 -> 108 bytes Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt | 1 + Tests/RunCMake/Syntax/BOM-UTF-8.cmake | 1 + Tests/RunCMake/Syntax/RunCMakeTest.cmake | 5 ++ 19 files changed, 168 insertions(+), 10 deletions(-) create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-16-LE-result.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-32-BE-result.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-32-LE-result.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt create mode 100644 Tests/RunCMake/Syntax/BOM-UTF-8.cmake diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index 898f379ad..f6ea4b128 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -57,13 +57,26 @@ cmListFileParser::~cmListFileParser() bool cmListFileParser::ParseFile() { // Open the file. - if(!cmListFileLexer_SetFileName(this->Lexer, this->FileName)) + cmListFileLexer_BOM bom; + if(!cmListFileLexer_SetFileName(this->Lexer, this->FileName, &bom)) { cmSystemTools::Error("cmListFileCache: error can not open file ", this->FileName); return false; } + // Verify the Byte-Order-Mark, if any. + if(bom != cmListFileLexer_BOM_None && + bom != cmListFileLexer_BOM_UTF8) + { + cmListFileLexer_SetFileName(this->Lexer, 0, 0); + cmOStringStream m; + m << "File\n " << this->FileName << "\n" + << "starts with a Byte-Order-Mark that is not UTF-8."; + this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str()); + return false; + } + // Use a simple recursive-descent parser to process the token // stream. bool haveNewline = true; diff --git a/Source/cmListFileLexer.c b/Source/cmListFileLexer.c index ad5a83d3d..394bd172a 100644 --- a/Source/cmListFileLexer.c +++ b/Source/cmListFileLexer.c @@ -2307,19 +2307,68 @@ cmListFileLexer* cmListFileLexer_New() /*--------------------------------------------------------------------------*/ void cmListFileLexer_Delete(cmListFileLexer* lexer) { - cmListFileLexer_SetFileName(lexer, 0); + cmListFileLexer_SetFileName(lexer, 0, 0); free(lexer); } /*--------------------------------------------------------------------------*/ -int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name) +static cmListFileLexer_BOM cmListFileLexer_ReadBOM(FILE* f) +{ + unsigned char b[2]; + if(fread(b, 1, 2, f) == 2) + { + if(b[0] == 0xEF && b[1] == 0xBB) + { + if(fread(b, 1, 1, f) == 1 && b[0] == 0xBF) + { + return cmListFileLexer_BOM_UTF8; + } + } + else if(b[0] == 0xFE && b[1] == 0xFF) + { + /* UTF-16 BE */ + return cmListFileLexer_BOM_UTF16BE; + } + else if(b[0] == 0 && b[1] == 0) + { + if(fread(b, 1, 2, f) == 2 && b[0] == 0xFE && b[1] == 0xFF) + { + return cmListFileLexer_BOM_UTF32BE; + } + } + else if(b[0] == 0xFF && b[1] == 0xFE) + { + fpos_t p; + fgetpos(f, &p); + if(fread(b, 1, 2, f) == 2 && b[0] == 0 && b[1] == 0) + { + return cmListFileLexer_BOM_UTF32LE; + } + fsetpos(f, &p); + return cmListFileLexer_BOM_UTF16LE; + } + } + rewind(f); + return cmListFileLexer_BOM_None; +} + +/*--------------------------------------------------------------------------*/ +int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name, + cmListFileLexer_BOM* bom) { int result = 1; cmListFileLexerDestroy(lexer); if(name) { lexer->file = fopen(name, "r"); - if(!lexer->file) + if(lexer->file) + { + if(bom) + { + *bom = cmListFileLexer_ReadBOM(lexer->file); + } + } + else { result = 0; } @@ -2365,7 +2414,7 @@ cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer) } else { - cmListFileLexer_SetFileName(lexer, 0); + cmListFileLexer_SetFileName(lexer, 0, 0); return 0; } } diff --git a/Source/cmListFileLexer.h b/Source/cmListFileLexer.h index cc78b5c2f..719347c1a 100644 --- a/Source/cmListFileLexer.h +++ b/Source/cmListFileLexer.h @@ -36,6 +36,17 @@ struct cmListFileLexer_Token_s int column; }; +enum cmListFileLexer_BOM_e +{ + cmListFileLexer_BOM_None, + cmListFileLexer_BOM_UTF8, + cmListFileLexer_BOM_UTF16BE, + cmListFileLexer_BOM_UTF16LE, + cmListFileLexer_BOM_UTF32BE, + cmListFileLexer_BOM_UTF32LE +}; +typedef enum cmListFileLexer_BOM_e cmListFileLexer_BOM; + typedef struct cmListFileLexer_s cmListFileLexer; #ifdef __cplusplus @@ -44,7 +55,8 @@ extern "C" #endif cmListFileLexer* cmListFileLexer_New(); -int cmListFileLexer_SetFileName(cmListFileLexer*, const char*); +int cmListFileLexer_SetFileName(cmListFileLexer*, const char*, + cmListFileLexer_BOM* bom); int cmListFileLexer_SetString(cmListFileLexer*, const char*); cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer*); long cmListFileLexer_GetCurrentLine(cmListFileLexer*); diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l index 89f29173a..a660d3772 100644 --- a/Source/cmListFileLexer.in.l +++ b/Source/cmListFileLexer.in.l @@ -328,19 +328,68 @@ cmListFileLexer* cmListFileLexer_New() /*--------------------------------------------------------------------------*/ void cmListFileLexer_Delete(cmListFileLexer* lexer) { - cmListFileLexer_SetFileName(lexer, 0); + cmListFileLexer_SetFileName(lexer, 0, 0); free(lexer); } /*--------------------------------------------------------------------------*/ -int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name) +static cmListFileLexer_BOM cmListFileLexer_ReadBOM(FILE* f) +{ + unsigned char b[2]; + if(fread(b, 1, 2, f) == 2) + { + if(b[0] == 0xEF && b[1] == 0xBB) + { + if(fread(b, 1, 1, f) == 1 && b[0] == 0xBF) + { + return cmListFileLexer_BOM_UTF8; + } + } + else if(b[0] == 0xFE && b[1] == 0xFF) + { + /* UTF-16 BE */ + return cmListFileLexer_BOM_UTF16BE; + } + else if(b[0] == 0 && b[1] == 0) + { + if(fread(b, 1, 2, f) == 2 && b[0] == 0xFE && b[1] == 0xFF) + { + return cmListFileLexer_BOM_UTF32BE; + } + } + else if(b[0] == 0xFF && b[1] == 0xFE) + { + fpos_t p; + fgetpos(f, &p); + if(fread(b, 1, 2, f) == 2 && b[0] == 0 && b[1] == 0) + { + return cmListFileLexer_BOM_UTF32LE; + } + fsetpos(f, &p); + return cmListFileLexer_BOM_UTF16LE; + } + } + rewind(f); + return cmListFileLexer_BOM_None; +} + +/*--------------------------------------------------------------------------*/ +int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name, + cmListFileLexer_BOM* bom) { int result = 1; cmListFileLexerDestroy(lexer); if(name) { lexer->file = fopen(name, "r"); - if(!lexer->file) + if(lexer->file) + { + if(bom) + { + *bom = cmListFileLexer_ReadBOM(lexer->file); + } + } + else { result = 0; } @@ -386,7 +435,7 @@ cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer) } else { - cmListFileLexer_SetFileName(lexer, 0); + cmListFileLexer_SetFileName(lexer, 0, 0); return 0; } } diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt new file mode 100644 index 000000000..b3f1e47d1 --- /dev/null +++ b/Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at CMakeLists.txt:3 \(include\): + File + + .*/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake + + starts with a Byte-Order-Mark that is not UTF-8. diff --git a/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake b/Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake new file mode 100644 index 0000000000000000000000000000000000000000..c51f6e6027f1659583ba801fad26614fa4f6257b GIT binary patch literal 54 qcmezOpCOkam7y326B*KhEDeTWh7blvAPxnx6d07yM{(5lE*)#Wa9)Fc60Tu_KfYg^DQvX(b@WrynG*3B+7L3;@EM B3TprW literal 0 HcmV?d00001 diff --git a/Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt b/Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt new file mode 100644 index 000000000..5776d6e81 --- /dev/null +++ b/Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt @@ -0,0 +1 @@ +-- message diff --git a/Tests/RunCMake/Syntax/BOM-UTF-8.cmake b/Tests/RunCMake/Syntax/BOM-UTF-8.cmake new file mode 100644 index 000000000..bdff83be8 --- /dev/null +++ b/Tests/RunCMake/Syntax/BOM-UTF-8.cmake @@ -0,0 +1 @@ +message(STATUS "message") diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake index 2d87328e8..d1a15c8bb 100644 --- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake +++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake @@ -1,5 +1,10 @@ include(RunCMake) +run_cmake(BOM-UTF-8) +run_cmake(BOM-UTF-16-LE) +run_cmake(BOM-UTF-16-BE) +run_cmake(BOM-UTF-32-LE) +run_cmake(BOM-UTF-32-BE) run_cmake(CommandSpaces) run_cmake(CommandTabs) run_cmake(CommandNewlines) From a8c652342f0e4dcaf933ecb0ce164b44d4997ae4 Mon Sep 17 00:00:00 2001 From: Brad King Date: Mon, 14 Oct 2013 13:54:19 -0400 Subject: [PATCH 3/4] cmListFileLexer: Convert CRLF -> LF newlines explicitly Read input files in binary mode instead of text mode and convert CRLF newlines to LF newlines explicitly in our own buffer. This is necessary to read CMake source files with CRLF newlines on platforms whose C runtime libraries do not transform newlines in text mode. For example, a Cygwin or Linux binary may not transform CRLF -> LF in files read from a Windows filesystem. Perform the conversion ourselves to ensure that multi-line string literals in CMake source files have LF newlines everywhere. --- Source/cmListFileLexer.c | 82 ++++++++++++++------- Source/cmListFileLexer.in.l | 36 ++++++++- Tests/RunCMake/Syntax/.gitattributes | 1 + Tests/RunCMake/Syntax/RunCMakeTest.cmake | 1 + Tests/RunCMake/Syntax/StringCRLF-stderr.txt | 1 + Tests/RunCMake/Syntax/StringCRLF.cmake | 6 ++ 6 files changed, 100 insertions(+), 27 deletions(-) create mode 100644 Tests/RunCMake/Syntax/StringCRLF-stderr.txt create mode 100644 Tests/RunCMake/Syntax/StringCRLF.cmake diff --git a/Source/cmListFileLexer.c b/Source/cmListFileLexer.c index 394bd172a..cbd2b5dfb 100644 --- a/Source/cmListFileLexer.c +++ b/Source/cmListFileLexer.c @@ -542,6 +542,7 @@ struct cmListFileLexer_s int column; int size; FILE* file; + size_t cr; char* string_buffer; char* string_position; int string_left; @@ -564,7 +565,7 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); /*--------------------------------------------------------------------------*/ -#line 570 "cmListFileLexer.c" +#line 571 "cmListFileLexer.c" #define INITIAL 0 #define STRING 1 @@ -793,10 +794,10 @@ YY_DECL int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 82 "cmListFileLexer.in.l" +#line 83 "cmListFileLexer.in.l" -#line 804 "cmListFileLexer.c" +#line 805 "cmListFileLexer.c" if ( !yyg->yy_init ) { @@ -894,7 +895,7 @@ do_action: /* This label is used only to access EOF actions. */ case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 84 "cmListFileLexer.in.l" +#line 85 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Newline; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -904,14 +905,14 @@ YY_RULE_SETUP } case 2: YY_RULE_SETUP -#line 92 "cmListFileLexer.in.l" +#line 93 "cmListFileLexer.in.l" { lexer->column += yyleng; } YY_BREAK case 3: YY_RULE_SETUP -#line 96 "cmListFileLexer.in.l" +#line 97 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ParenLeft; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -920,7 +921,7 @@ YY_RULE_SETUP } case 4: YY_RULE_SETUP -#line 103 "cmListFileLexer.in.l" +#line 104 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ParenRight; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -929,7 +930,7 @@ YY_RULE_SETUP } case 5: YY_RULE_SETUP -#line 110 "cmListFileLexer.in.l" +#line 111 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Identifier; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -938,7 +939,7 @@ YY_RULE_SETUP } case 6: YY_RULE_SETUP -#line 117 "cmListFileLexer.in.l" +#line 118 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -947,7 +948,7 @@ YY_RULE_SETUP } case 7: YY_RULE_SETUP -#line 124 "cmListFileLexer.in.l" +#line 125 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -956,7 +957,7 @@ YY_RULE_SETUP } case 8: YY_RULE_SETUP -#line 131 "cmListFileLexer.in.l" +#line 132 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ArgumentQuoted; cmListFileLexerSetToken(lexer, "", 0); @@ -966,7 +967,7 @@ YY_RULE_SETUP YY_BREAK case 9: YY_RULE_SETUP -#line 138 "cmListFileLexer.in.l" +#line 139 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; @@ -975,7 +976,7 @@ YY_RULE_SETUP case 10: /* rule 10 can match eol */ YY_RULE_SETUP -#line 143 "cmListFileLexer.in.l" +#line 144 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); ++lexer->line; @@ -985,7 +986,7 @@ YY_RULE_SETUP case 11: /* rule 11 can match eol */ YY_RULE_SETUP -#line 149 "cmListFileLexer.in.l" +#line 150 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); ++lexer->line; @@ -994,7 +995,7 @@ YY_RULE_SETUP YY_BREAK case 12: YY_RULE_SETUP -#line 155 "cmListFileLexer.in.l" +#line 156 "cmListFileLexer.in.l" { lexer->column += yyleng; BEGIN(INITIAL); @@ -1002,14 +1003,14 @@ YY_RULE_SETUP } case 13: YY_RULE_SETUP -#line 161 "cmListFileLexer.in.l" +#line 162 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; } YY_BREAK case YY_STATE_EOF(STRING): -#line 166 "cmListFileLexer.in.l" +#line 167 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_BadString; BEGIN(INITIAL); @@ -1017,7 +1018,7 @@ case YY_STATE_EOF(STRING): } case 14: YY_RULE_SETUP -#line 172 "cmListFileLexer.in.l" +#line 173 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Space; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -1026,7 +1027,7 @@ YY_RULE_SETUP } case 15: YY_RULE_SETUP -#line 179 "cmListFileLexer.in.l" +#line 180 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_BadCharacter; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -1034,7 +1035,7 @@ YY_RULE_SETUP return 1; } case YY_STATE_EOF(INITIAL): -#line 186 "cmListFileLexer.in.l" +#line 187 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_None; cmListFileLexerSetToken(lexer, 0, 0); @@ -1042,10 +1043,10 @@ case YY_STATE_EOF(INITIAL): } case 16: YY_RULE_SETUP -#line 192 "cmListFileLexer.in.l" +#line 193 "cmListFileLexer.in.l" ECHO; YY_BREAK -#line 1064 "cmListFileLexer.c" +#line 1065 "cmListFileLexer.c" case YY_END_OF_BUFFER: { @@ -2166,7 +2167,7 @@ void cmListFileLexer_yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 192 "cmListFileLexer.in.l" +#line 193 "cmListFileLexer.in.l" @@ -2243,7 +2244,38 @@ static int cmListFileLexerInput(cmListFileLexer* lexer, char* buffer, { if(lexer->file) { - return (int)fread(buffer, 1, bufferSize, lexer->file); + /* Convert CRLF -> LF explicitly. The C FILE "t"ext mode + does not convert newlines on all platforms. Move any + trailing CR to the start of the buffer for the next read. */ + size_t cr = lexer->cr; + size_t n; + buffer[0] = '\r'; + n = fread(buffer+cr, 1, bufferSize-cr, lexer->file); + if(n) + { + char* o = buffer; + const char* i = buffer; + const char* e; + n += cr; + cr = (buffer[n-1] == '\r')? 1:0; + e = buffer + n - cr; + while(i != e) + { + if(i[0] == '\r' && i[1] == '\n') + { + ++i; + } + *o++ = *i++; + } + n = o - buffer; + } + else + { + n = cr; + cr = 0; + } + lexer->cr = cr; + return n; } else if(lexer->string_left) { @@ -2360,7 +2392,7 @@ int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name, cmListFileLexerDestroy(lexer); if(name) { - lexer->file = fopen(name, "r"); + lexer->file = fopen(name, "rb"); if(lexer->file) { if(bom) diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l index a660d3772..e2ad0f5f7 100644 --- a/Source/cmListFileLexer.in.l +++ b/Source/cmListFileLexer.in.l @@ -46,6 +46,7 @@ struct cmListFileLexer_s int column; int size; FILE* file; + size_t cr; char* string_buffer; char* string_position; int string_left; @@ -264,7 +265,38 @@ static int cmListFileLexerInput(cmListFileLexer* lexer, char* buffer, { if(lexer->file) { - return (int)fread(buffer, 1, bufferSize, lexer->file); + /* Convert CRLF -> LF explicitly. The C FILE "t"ext mode + does not convert newlines on all platforms. Move any + trailing CR to the start of the buffer for the next read. */ + size_t cr = lexer->cr; + size_t n; + buffer[0] = '\r'; + n = fread(buffer+cr, 1, bufferSize-cr, lexer->file); + if(n) + { + char* o = buffer; + const char* i = buffer; + const char* e; + n += cr; + cr = (buffer[n-1] == '\r')? 1:0; + e = buffer + n - cr; + while(i != e) + { + if(i[0] == '\r' && i[1] == '\n') + { + ++i; + } + *o++ = *i++; + } + n = o - buffer; + } + else + { + n = cr; + cr = 0; + } + lexer->cr = cr; + return n; } else if(lexer->string_left) { @@ -381,7 +413,7 @@ int cmListFileLexer_SetFileName(cmListFileLexer* lexer, const char* name, cmListFileLexerDestroy(lexer); if(name) { - lexer->file = fopen(name, "r"); + lexer->file = fopen(name, "rb"); if(lexer->file) { if(bom) diff --git a/Tests/RunCMake/Syntax/.gitattributes b/Tests/RunCMake/Syntax/.gitattributes index fc9ebff69..567121ff9 100644 --- a/Tests/RunCMake/Syntax/.gitattributes +++ b/Tests/RunCMake/Syntax/.gitattributes @@ -1 +1,2 @@ CommandTabs.cmake whitespace=-tab-in-indent +StringCRLF.cmake whitespace=cr-at-eol -crlf diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake index d1a15c8bb..1399d8ba2 100644 --- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake +++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake @@ -13,6 +13,7 @@ run_cmake(CommandError0) run_cmake(CommandError1) run_cmake(String0) run_cmake(String1) +run_cmake(StringCRLF) run_cmake(StringNoSpace) run_cmake(OneLetter) run_cmake(Unquoted0) diff --git a/Tests/RunCMake/Syntax/StringCRLF-stderr.txt b/Tests/RunCMake/Syntax/StringCRLF-stderr.txt new file mode 100644 index 000000000..7aef26eca --- /dev/null +++ b/Tests/RunCMake/Syntax/StringCRLF-stderr.txt @@ -0,0 +1 @@ +CRLF->LF worked diff --git a/Tests/RunCMake/Syntax/StringCRLF.cmake b/Tests/RunCMake/Syntax/StringCRLF.cmake new file mode 100644 index 000000000..d20cfea7e --- /dev/null +++ b/Tests/RunCMake/Syntax/StringCRLF.cmake @@ -0,0 +1,6 @@ +if("a +b" STREQUAL "a\nb") + message("CRLF->LF worked") +else() + message(FATAL_ERROR "CRLF->LF failed") +endif() From daa0f6f98df6e944a46a8dff13bb247cf7e301b1 Mon Sep 17 00:00:00 2001 From: Brad King Date: Tue, 6 Aug 2013 15:58:22 -0400 Subject: [PATCH 4/4] Add Lua-style long brackets and long comments to CMake language Teach the CMake language parser to recognize Lua-style "long bracket" arguments. These start with two '[' separated by zero or more '=' characters e.g. "[[" or "[=[" or "[==[". They end with two ']' separated by the same number of '=' as the opening bracket. There is no nesting of brackets of the same level (number of '='). No escapes, variable expansion, or other processing is performed on the content between such brackets so they always represent exactly one argument. Also teach CMake to parse and ignore "long comment" syntax. A long comment starts with "#" immediately followed by an opening long bracket. It ends at the matching close long bracket. Teach the RunCMake.Syntax test to cover long bracket and long comment cases. --- Source/cmListFileCache.cxx | 80 ++-- Source/cmListFileCache.h | 3 +- Source/cmListFileLexer.c | 389 ++++++++++++------ Source/cmListFileLexer.h | 3 + Source/cmListFileLexer.in.l | 95 ++++- Source/cmMakefile.cxx | 6 + Tests/RunCMake/Syntax/.gitattributes | 1 + Tests/RunCMake/Syntax/Bracket0-stderr.txt | 1 + Tests/RunCMake/Syntax/Bracket0.cmake | 1 + Tests/RunCMake/Syntax/Bracket1-stderr.txt | 1 + Tests/RunCMake/Syntax/Bracket1.cmake | 2 + Tests/RunCMake/Syntax/Bracket2-stdout.txt | 2 + Tests/RunCMake/Syntax/Bracket2.cmake | 2 + .../Syntax/BracketBackslash-result.txt | 1 + .../Syntax/BracketBackslash-stderr.txt | 6 + Tests/RunCMake/Syntax/BracketBackslash.cmake | 2 + Tests/RunCMake/Syntax/BracketCRLF-stderr.txt | 1 + Tests/RunCMake/Syntax/BracketCRLF.cmake | 8 + .../Syntax/BracketComment0-stdout.txt | 1 + Tests/RunCMake/Syntax/BracketComment0.cmake | 5 + .../Syntax/BracketComment1-result.txt | 1 + .../Syntax/BracketComment1-stderr.txt | 4 + Tests/RunCMake/Syntax/BracketComment1.cmake | 3 + .../Syntax/BracketComment2-result.txt | 1 + .../Syntax/BracketComment2-stderr.txt | 4 + Tests/RunCMake/Syntax/BracketComment2.cmake | 3 + .../Syntax/BracketComment3-stdout.txt | 1 + Tests/RunCMake/Syntax/BracketComment3.cmake | 4 + .../Syntax/BracketComment4-result.txt | 1 + .../Syntax/BracketComment4-stderr.txt | 7 + Tests/RunCMake/Syntax/BracketComment4.cmake | 3 + .../Syntax/BracketComment5-stdout.txt | 1 + Tests/RunCMake/Syntax/BracketComment5.cmake | 6 + .../Syntax/BracketNoSpace0-result.txt | 1 + .../Syntax/BracketNoSpace0-stderr.txt | 6 + Tests/RunCMake/Syntax/BracketNoSpace0.cmake | 1 + .../Syntax/BracketNoSpace1-result.txt | 1 + .../Syntax/BracketNoSpace1-stderr.txt | 6 + Tests/RunCMake/Syntax/BracketNoSpace1.cmake | 1 + .../Syntax/BracketNoSpace2-result.txt | 1 + .../Syntax/BracketNoSpace2-stderr.txt | 6 + Tests/RunCMake/Syntax/BracketNoSpace2.cmake | 1 + .../Syntax/BracketNoSpace3-result.txt | 1 + .../Syntax/BracketNoSpace3-stderr.txt | 6 + Tests/RunCMake/Syntax/BracketNoSpace3.cmake | 1 + .../Syntax/BracketNoSpace4-result.txt | 1 + .../Syntax/BracketNoSpace4-stderr.txt | 6 + Tests/RunCMake/Syntax/BracketNoSpace4.cmake | 1 + .../Syntax/BracketNoSpace5-result.txt | 1 + .../Syntax/BracketNoSpace5-stderr.txt | 6 + Tests/RunCMake/Syntax/BracketNoSpace5.cmake | 1 + Tests/RunCMake/Syntax/BracketWarn-stderr.txt | 35 -- Tests/RunCMake/Syntax/BracketWarn-stdout.txt | 1 - Tests/RunCMake/Syntax/BracketWarn.cmake | 1 - .../RunCMake/Syntax/CommandError2-result.txt | 1 + .../RunCMake/Syntax/CommandError2-stderr.txt | 7 + Tests/RunCMake/Syntax/CommandError2.cmake | 1 + .../RunCMake/Syntax/ParenNoSpace0-stdout.txt | 3 + Tests/RunCMake/Syntax/ParenNoSpace0.cmake | 3 + .../RunCMake/Syntax/ParenNoSpace1-result.txt | 1 + .../RunCMake/Syntax/ParenNoSpace1-stderr.txt | 22 + Tests/RunCMake/Syntax/ParenNoSpace1.cmake | 3 + ...ce-stderr.txt => ParenNoSpace2-stderr.txt} | 0 ...ce-stdout.txt => ParenNoSpace2-stdout.txt} | 1 + ...ParenNoSpace.cmake => ParenNoSpace2.cmake} | 1 + Tests/RunCMake/Syntax/RunCMakeTest.cmake | 26 +- .../Syntax/UnterminatedBracket0-result.txt | 1 + .../Syntax/UnterminatedBracket0-stderr.txt | 8 + .../Syntax/UnterminatedBracket0.cmake | 1 + .../Syntax/UnterminatedBracket1-result.txt | 1 + .../Syntax/UnterminatedBracket1-stderr.txt | 8 + .../Syntax/UnterminatedBracket1.cmake | 1 + .../UnterminatedBracketComment-result.txt | 1 + .../UnterminatedBracketComment-stderr.txt | 8 + .../Syntax/UnterminatedBracketComment.cmake | 2 + 75 files changed, 639 insertions(+), 195 deletions(-) create mode 100644 Tests/RunCMake/Syntax/Bracket0-stderr.txt create mode 100644 Tests/RunCMake/Syntax/Bracket0.cmake create mode 100644 Tests/RunCMake/Syntax/Bracket1-stderr.txt create mode 100644 Tests/RunCMake/Syntax/Bracket1.cmake create mode 100644 Tests/RunCMake/Syntax/Bracket2-stdout.txt create mode 100644 Tests/RunCMake/Syntax/Bracket2.cmake create mode 100644 Tests/RunCMake/Syntax/BracketBackslash-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketBackslash-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketBackslash.cmake create mode 100644 Tests/RunCMake/Syntax/BracketCRLF-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketCRLF.cmake create mode 100644 Tests/RunCMake/Syntax/BracketComment0-stdout.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment0.cmake create mode 100644 Tests/RunCMake/Syntax/BracketComment1-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment1-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment1.cmake create mode 100644 Tests/RunCMake/Syntax/BracketComment2-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment2-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment2.cmake create mode 100644 Tests/RunCMake/Syntax/BracketComment3-stdout.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment3.cmake create mode 100644 Tests/RunCMake/Syntax/BracketComment4-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment4-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment4.cmake create mode 100644 Tests/RunCMake/Syntax/BracketComment5-stdout.txt create mode 100644 Tests/RunCMake/Syntax/BracketComment5.cmake create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace0-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace0.cmake create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace1-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace1.cmake create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace2-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace2.cmake create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace3-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace3.cmake create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace4-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace4.cmake create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace5-result.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt create mode 100644 Tests/RunCMake/Syntax/BracketNoSpace5.cmake delete mode 100644 Tests/RunCMake/Syntax/BracketWarn-stderr.txt delete mode 100644 Tests/RunCMake/Syntax/BracketWarn-stdout.txt delete mode 100644 Tests/RunCMake/Syntax/BracketWarn.cmake create mode 100644 Tests/RunCMake/Syntax/CommandError2-result.txt create mode 100644 Tests/RunCMake/Syntax/CommandError2-stderr.txt create mode 100644 Tests/RunCMake/Syntax/CommandError2.cmake create mode 100644 Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt create mode 100644 Tests/RunCMake/Syntax/ParenNoSpace0.cmake create mode 100644 Tests/RunCMake/Syntax/ParenNoSpace1-result.txt create mode 100644 Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt create mode 100644 Tests/RunCMake/Syntax/ParenNoSpace1.cmake rename Tests/RunCMake/Syntax/{ParenNoSpace-stderr.txt => ParenNoSpace2-stderr.txt} (100%) rename Tests/RunCMake/Syntax/{ParenNoSpace-stdout.txt => ParenNoSpace2-stdout.txt} (66%) rename Tests/RunCMake/Syntax/{ParenNoSpace.cmake => ParenNoSpace2.cmake} (63%) create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracket0.cmake create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracket1.cmake create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt create mode 100644 Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx index f6ea4b128..7461d375a 100644 --- a/Source/cmListFileCache.cxx +++ b/Source/cmListFileCache.cxx @@ -29,14 +29,14 @@ struct cmListFileParser ~cmListFileParser(); bool ParseFile(); bool ParseFunction(const char* name, long line); - void AddArgument(cmListFileLexer_Token* token, + bool AddArgument(cmListFileLexer_Token* token, cmListFileArgument::Delimiter delim); cmListFile* ListFile; cmMakefile* Makefile; const char* FileName; cmListFileLexer* Lexer; cmListFileFunction Function; - enum { SeparationOkay, SeparationWarning } Separation; + enum { SeparationOkay, SeparationWarning, SeparationError} Separation; }; //---------------------------------------------------------------------------- @@ -90,6 +90,10 @@ bool cmListFileParser::ParseFile() { haveNewline = true; } + else if(token->type == cmListFileLexer_Token_CommentBracket) + { + haveNewline = false; + } else if(token->type == cmListFileLexer_Token_Identifier) { if(haveNewline) @@ -301,7 +305,10 @@ bool cmListFileParser::ParseFunction(const char* name, long line) { parenDepth++; this->Separation = SeparationOkay; - this->AddArgument(token, cmListFileArgument::Unquoted); + if(!this->AddArgument(token, cmListFileArgument::Unquoted)) + { + return false; + } } else if(token->type == cmListFileLexer_Token_ParenRight) { @@ -311,20 +318,41 @@ bool cmListFileParser::ParseFunction(const char* name, long line) } parenDepth--; this->Separation = SeparationOkay; - this->AddArgument(token, cmListFileArgument::Unquoted); + if(!this->AddArgument(token, cmListFileArgument::Unquoted)) + { + return false; + } this->Separation = SeparationWarning; } else if(token->type == cmListFileLexer_Token_Identifier || token->type == cmListFileLexer_Token_ArgumentUnquoted) { - this->AddArgument(token, cmListFileArgument::Unquoted); + if(!this->AddArgument(token, cmListFileArgument::Unquoted)) + { + return false; + } this->Separation = SeparationWarning; } else if(token->type == cmListFileLexer_Token_ArgumentQuoted) { - this->AddArgument(token, cmListFileArgument::Quoted); + if(!this->AddArgument(token, cmListFileArgument::Quoted)) + { + return false; + } this->Separation = SeparationWarning; } + else if(token->type == cmListFileLexer_Token_ArgumentBracket) + { + if(!this->AddArgument(token, cmListFileArgument::Bracket)) + { + return false; + } + this->Separation = SeparationError; + } + else if(token->type == cmListFileLexer_Token_CommentBracket) + { + this->Separation = SeparationError; + } else { // Error. @@ -351,42 +379,32 @@ bool cmListFileParser::ParseFunction(const char* name, long line) } //---------------------------------------------------------------------------- -void cmListFileParser::AddArgument(cmListFileLexer_Token* token, +bool cmListFileParser::AddArgument(cmListFileLexer_Token* token, cmListFileArgument::Delimiter delim) { cmListFileArgument a(token->text, delim, this->FileName, token->line); this->Function.Arguments.push_back(a); - if(delim == cmListFileArgument::Unquoted) - { - // Warn about a future behavior change. - const char* c = a.Value.c_str(); - if(*c++ == '[') - { - while(*c == '=') - { ++c; } - if(*c == '[') - { - cmOStringStream m; - m << "Syntax Warning in cmake code at\n" - << " " << this->FileName << ":" << token->line << ":" - << token->column << "\n" - << "A future version of CMake may treat unquoted argument:\n" - << " " << a.Value << "\n" - << "as an opening long bracket. Double-quote the argument."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str().c_str()); - } - } - } if(this->Separation == SeparationOkay) { - return; + return true; } + bool isError = (this->Separation == SeparationError || + delim == cmListFileArgument::Bracket); cmOStringStream m; - m << "Syntax Warning in cmake code at\n" + m << "Syntax " << (isError? "Error":"Warning") << " in cmake code at\n" << " " << this->FileName << ":" << token->line << ":" << token->column << "\n" << "Argument not separated from preceding token by whitespace."; - this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str().c_str()); + if(isError) + { + this->Makefile->IssueMessage(cmake::FATAL_ERROR, m.str().c_str()); + return false; + } + else + { + this->Makefile->IssueMessage(cmake::AUTHOR_WARNING, m.str().c_str()); + return true; + } } //---------------------------------------------------------------------------- diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 7bb3b346c..bede25e65 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -28,7 +28,8 @@ struct cmListFileArgument enum Delimiter { Unquoted, - Quoted + Quoted, + Bracket }; cmListFileArgument(): Value(), Delim(Unquoted), FilePath(0), Line(0) {} cmListFileArgument(const cmListFileArgument& r): diff --git a/Source/cmListFileLexer.c b/Source/cmListFileLexer.c index cbd2b5dfb..3b08b03c1 100644 --- a/Source/cmListFileLexer.c +++ b/Source/cmListFileLexer.c @@ -369,8 +369,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner ); *yy_cp = '\0'; \ yyg->yy_c_buf_p = yy_cp; -#define YY_NUM_RULES 16 -#define YY_END_OF_BUFFER 17 +#define YY_NUM_RULES 23 +#define YY_END_OF_BUFFER 24 /* This struct is not used in this scanner, but its presence is necessary. */ struct yy_trans_info @@ -378,13 +378,16 @@ struct yy_trans_info flex_int32_t yy_verify; flex_int32_t yy_nxt; }; -static yyconst flex_int16_t yy_accept[45] = +static yyconst flex_int16_t yy_accept[77] = { 0, - 0, 0, 0, 0, 17, 6, 14, 1, 8, 2, - 6, 3, 4, 5, 15, 9, 11, 12, 13, 6, - 0, 6, 0, 14, 2, 0, 5, 6, 9, 0, - 10, 0, 7, 0, 0, 0, 7, 0, 7, 0, - 0, 0, 0, 0 + 0, 0, 0, 0, 0, 0, 0, 0, 4, 4, + 24, 13, 21, 1, 15, 3, 13, 5, 6, 7, + 22, 22, 16, 18, 19, 20, 10, 11, 8, 12, + 9, 4, 13, 0, 13, 0, 21, 0, 0, 7, + 13, 0, 13, 0, 2, 0, 13, 16, 0, 17, + 10, 8, 4, 0, 14, 0, 0, 0, 0, 14, + 0, 0, 14, 0, 0, 0, 2, 14, 0, 0, + 0, 0, 0, 0, 0, 0 } ; static yyconst flex_int32_t yy_ec[256] = @@ -395,14 +398,14 @@ static yyconst flex_int32_t yy_ec[256] = 1, 2, 1, 5, 6, 7, 1, 1, 1, 8, 9, 1, 1, 1, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 1, 1, 1, - 1, 1, 1, 1, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 1, 12, 1, 1, 11, 1, 11, 11, 11, 11, + 11, 1, 1, 1, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 13, 14, 15, 1, 12, 1, 12, 12, 12, 12, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 11, 11, 11, 11, 11, 11, 11, 11, - 11, 11, 1, 1, 1, 1, 1, 1, 1, 1, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 12, 12, 12, 12, 12, 12, 12, 12, + 12, 12, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, @@ -419,72 +422,111 @@ static yyconst flex_int32_t yy_ec[256] = 1, 1, 1, 1, 1 } ; -static yyconst flex_int32_t yy_meta[13] = +static yyconst flex_int32_t yy_meta[16] = { 0, - 1, 2, 3, 2, 4, 1, 1, 1, 5, 5, - 5, 1 + 1, 1, 2, 3, 4, 3, 1, 3, 5, 6, + 1, 6, 1, 1, 7 } ; -static yyconst flex_int16_t yy_base[56] = +static yyconst flex_int16_t yy_base[95] = { 0, - 0, 0, 10, 20, 38, 32, 0, 109, 109, 0, - 28, 109, 109, 35, 0, 23, 109, 109, 44, 0, - 49, 26, 0, 0, 0, 22, 0, 0, 18, 24, - 109, 0, 61, 20, 0, 18, 0, 17, 16, 0, - 12, 11, 10, 109, 73, 16, 78, 83, 88, 93, - 12, 98, 11, 103, 9 + 0, 0, 13, 25, 14, 16, 17, 18, 90, 88, + 88, 39, 20, 237, 237, 74, 78, 237, 237, 13, + 54, 0, 71, 237, 237, 31, 0, 237, 73, 237, + 237, 0, 0, 65, 75, 0, 33, 30, 72, 0, + 0, 75, 70, 0, 74, 0, 0, 62, 70, 237, + 0, 63, 0, 85, 99, 65, 111, 62, 34, 0, + 54, 116, 0, 54, 127, 51, 237, 50, 0, 48, + 47, 39, 33, 29, 17, 237, 136, 143, 150, 157, + 164, 171, 178, 184, 191, 198, 201, 207, 214, 217, + 219, 225, 228, 230 + } ; -static yyconst flex_int16_t yy_def[56] = +static yyconst flex_int16_t yy_def[95] = { 0, - 44, 1, 45, 45, 44, 44, 46, 44, 44, 47, - 6, 44, 44, 6, 48, 49, 44, 44, 49, 6, - 44, 6, 50, 46, 47, 51, 14, 6, 49, 49, - 44, 21, 44, 21, 52, 53, 33, 51, 33, 54, - 55, 53, 55, 0, 44, 44, 44, 44, 44, 44, - 44, 44, 44, 44, 44 + 76, 1, 77, 77, 78, 78, 79, 79, 80, 80, + 76, 76, 76, 76, 76, 76, 12, 76, 76, 12, + 76, 81, 82, 76, 76, 82, 83, 76, 76, 76, + 76, 84, 12, 85, 12, 86, 76, 76, 87, 20, + 12, 88, 12, 21, 76, 89, 12, 82, 82, 76, + 83, 76, 84, 85, 76, 54, 85, 90, 76, 55, + 87, 88, 55, 62, 88, 91, 76, 55, 92, 93, + 90, 94, 91, 93, 94, 0, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 76, 76, 76 + } ; -static yyconst flex_int16_t yy_nxt[122] = +static yyconst flex_int16_t yy_nxt[253] = { 0, - 6, 7, 8, 7, 9, 10, 11, 12, 13, 6, - 14, 15, 17, 43, 18, 42, 38, 24, 32, 33, - 32, 19, 17, 36, 18, 37, 33, 41, 29, 30, - 37, 19, 20, 36, 30, 26, 21, 44, 22, 44, - 44, 20, 20, 23, 27, 27, 31, 44, 29, 32, - 32, 44, 44, 33, 44, 34, 44, 44, 32, 32, - 35, 33, 44, 44, 44, 21, 44, 39, 44, 44, - 33, 33, 40, 16, 16, 16, 16, 16, 25, 25, - 44, 25, 25, 28, 28, 44, 28, 28, 29, 29, - 44, 44, 29, 20, 20, 44, 20, 20, 32, 32, + 12, 13, 14, 13, 15, 16, 17, 18, 19, 12, + 12, 20, 21, 22, 12, 24, 28, 25, 28, 28, + 28, 37, 40, 37, 40, 62, 26, 24, 29, 25, + 29, 31, 31, 50, 37, 48, 37, 54, 26, 33, + 59, 63, 45, 34, 59, 35, 45, 62, 33, 33, + 33, 33, 36, 33, 41, 55, 54, 58, 42, 63, + 43, 72, 60, 41, 44, 41, 45, 46, 41, 55, + 55, 56, 70, 52, 48, 49, 67, 66, 57, 63, + 60, 64, 58, 52, 49, 39, 38, 76, 65, 55, + 14, 56, 14, 76, 76, 76, 76, 76, 57, 55, - 44, 32, 32, 33, 33, 44, 33, 33, 5, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44 + 76, 76, 76, 34, 76, 68, 76, 76, 55, 55, + 55, 55, 69, 55, 54, 76, 54, 76, 54, 54, + 63, 76, 64, 76, 76, 76, 76, 76, 76, 65, + 62, 76, 62, 76, 62, 62, 23, 23, 23, 23, + 23, 23, 23, 27, 27, 27, 27, 27, 27, 27, + 30, 30, 30, 30, 30, 30, 30, 32, 32, 32, + 32, 32, 32, 32, 47, 76, 47, 47, 47, 47, + 47, 48, 76, 48, 76, 48, 48, 48, 51, 76, + 51, 51, 51, 51, 53, 76, 53, 53, 53, 53, + 53, 54, 76, 76, 54, 76, 54, 54, 33, 76, + + 33, 33, 33, 33, 33, 61, 61, 62, 76, 76, + 62, 76, 62, 62, 41, 76, 41, 41, 41, 41, + 41, 71, 71, 73, 73, 55, 76, 55, 55, 55, + 55, 55, 74, 74, 75, 75, 11, 76, 76, 76, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 76 } ; -static yyconst flex_int16_t yy_chk[122] = +static yyconst flex_int16_t yy_chk[253] = { 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, - 1, 1, 3, 55, 3, 53, 51, 46, 43, 42, - 41, 3, 4, 39, 4, 38, 36, 34, 30, 29, - 26, 4, 6, 22, 16, 11, 6, 5, 6, 0, - 0, 6, 6, 6, 14, 14, 19, 0, 19, 21, - 21, 0, 0, 21, 0, 21, 0, 0, 21, 21, - 21, 33, 0, 0, 0, 33, 0, 33, 0, 0, - 33, 33, 33, 45, 45, 45, 45, 45, 47, 47, - 0, 47, 47, 48, 48, 0, 48, 48, 49, 49, - 0, 0, 49, 50, 50, 0, 50, 50, 52, 52, + 1, 1, 1, 1, 1, 3, 5, 3, 6, 7, + 8, 13, 20, 13, 20, 75, 3, 4, 5, 4, + 6, 7, 8, 26, 37, 26, 37, 74, 4, 12, + 38, 73, 38, 12, 59, 12, 59, 72, 12, 12, + 12, 12, 12, 12, 21, 71, 70, 68, 21, 66, + 21, 64, 61, 21, 21, 21, 21, 21, 21, 34, + 58, 34, 56, 52, 49, 48, 45, 43, 34, 42, + 39, 42, 35, 29, 23, 17, 16, 11, 42, 54, + 10, 54, 9, 0, 0, 0, 0, 0, 54, 55, - 0, 52, 52, 54, 54, 0, 54, 54, 44, 44, - 44, 44, 44, 44, 44, 44, 44, 44, 44, 44, - 44 + 0, 0, 0, 55, 0, 55, 0, 0, 55, 55, + 55, 55, 55, 55, 57, 0, 57, 0, 57, 57, + 62, 0, 62, 0, 0, 0, 0, 0, 0, 62, + 65, 0, 65, 0, 65, 65, 77, 77, 77, 77, + 77, 77, 77, 78, 78, 78, 78, 78, 78, 78, + 79, 79, 79, 79, 79, 79, 79, 80, 80, 80, + 80, 80, 80, 80, 81, 0, 81, 81, 81, 81, + 81, 82, 0, 82, 0, 82, 82, 82, 83, 0, + 83, 83, 83, 83, 84, 0, 84, 84, 84, 84, + 84, 85, 0, 0, 85, 0, 85, 85, 86, 0, + + 86, 86, 86, 86, 86, 87, 87, 88, 0, 0, + 88, 0, 88, 88, 89, 0, 89, 89, 89, 89, + 89, 90, 90, 91, 91, 92, 0, 92, 92, 92, + 92, 92, 93, 93, 94, 94, 76, 76, 76, 76, + 76, 76, 76, 76, 76, 76, 76, 76, 76, 76, + 76, 76 } ; /* Table of booleans, true if rule could match eol. */ -static yyconst flex_int32_t yy_rule_can_match_eol[17] = +static yyconst flex_int32_t yy_rule_can_match_eol[24] = { 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 0, 0, 0, 0, }; +1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 1, 0, + 0, 0, 0, 0, }; /* The intent behind this definition is that it'll catch * any uses of REJECT which flex missed. @@ -538,6 +580,8 @@ Modify cmListFileLexer.c: struct cmListFileLexer_s { cmListFileLexer_Token token; + int bracket; + int comment; int line; int column; int size; @@ -565,10 +609,16 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); /*--------------------------------------------------------------------------*/ -#line 571 "cmListFileLexer.c" + + + +#line 618 "cmListFileLexer.c" #define INITIAL 0 #define STRING 1 +#define BRACKET 2 +#define BRACKETEND 3 +#define COMMENT 4 #ifndef YY_NO_UNISTD_H /* Special case for "unistd.h", since it is non-ANSI. We include it way @@ -794,10 +844,10 @@ YY_DECL int yy_act; struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; -#line 83 "cmListFileLexer.in.l" +#line 88 "cmListFileLexer.in.l" -#line 805 "cmListFileLexer.c" +#line 855 "cmListFileLexer.c" if ( !yyg->yy_init ) { @@ -850,13 +900,13 @@ yy_match: while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 45 ) + if ( yy_current_state >= 77 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; ++yy_cp; } - while ( yy_base[yy_current_state] != 109 ); + while ( yy_base[yy_current_state] != 237 ); yy_find_action: yy_act = yy_accept[yy_current_state]; @@ -895,69 +945,168 @@ do_action: /* This label is used only to access EOF actions. */ case 1: /* rule 1 can match eol */ YY_RULE_SETUP -#line 85 "cmListFileLexer.in.l" +#line 90 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Newline; cmListFileLexerSetToken(lexer, yytext, yyleng); ++lexer->line; lexer->column = 1; + BEGIN(INITIAL); return 1; } case 2: +/* rule 2 can match eol */ YY_RULE_SETUP -#line 93 "cmListFileLexer.in.l" +#line 99 "cmListFileLexer.in.l" { - lexer->column += yyleng; + const char* bracket = yytext; + lexer->comment = yytext[0] == '#'; + if(lexer->comment) + { + lexer->token.type = cmListFileLexer_Token_CommentBracket; + bracket += 1; + } + else + { + lexer->token.type = cmListFileLexer_Token_ArgumentBracket; + } + cmListFileLexerSetToken(lexer, "", 0); + lexer->bracket = (int)(strchr(bracket+1, '[') - bracket); + if(yytext[yyleng-1] == '\n') + { + ++lexer->line; + lexer->column = 1; + } + else + { + lexer->column += yyleng; + } + BEGIN(BRACKET); } YY_BREAK case 3: YY_RULE_SETUP -#line 97 "cmListFileLexer.in.l" +#line 125 "cmListFileLexer.in.l" +{ + lexer->column += yyleng; + BEGIN(COMMENT); +} + YY_BREAK +case 4: +YY_RULE_SETUP +#line 130 "cmListFileLexer.in.l" +{ + lexer->column += yyleng; +} + YY_BREAK +case 5: +YY_RULE_SETUP +#line 134 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ParenLeft; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; return 1; } -case 4: +case 6: YY_RULE_SETUP -#line 104 "cmListFileLexer.in.l" +#line 141 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ParenRight; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; return 1; } -case 5: +case 7: YY_RULE_SETUP -#line 111 "cmListFileLexer.in.l" +#line 148 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Identifier; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; return 1; } -case 6: -YY_RULE_SETUP -#line 118 "cmListFileLexer.in.l" -{ - lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; - cmListFileLexerSetToken(lexer, yytext, yyleng); - lexer->column += yyleng; - return 1; -} -case 7: -YY_RULE_SETUP -#line 125 "cmListFileLexer.in.l" -{ - lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; - cmListFileLexerSetToken(lexer, yytext, yyleng); - lexer->column += yyleng; - return 1; -} case 8: YY_RULE_SETUP -#line 132 "cmListFileLexer.in.l" +#line 155 "cmListFileLexer.in.l" +{ + /* Handle ]]====]=======]*/ + cmListFileLexerAppend(lexer, yytext, yyleng); + lexer->column += yyleng; + if(yyleng == lexer->bracket) + { + BEGIN(BRACKETEND); + } +} + YY_BREAK +case 9: +YY_RULE_SETUP +#line 165 "cmListFileLexer.in.l" +{ + lexer->column += yyleng; + /* Erase the partial bracket from the token. */ + lexer->token.length -= lexer->bracket; + lexer->token.text[lexer->token.length] = 0; + BEGIN(INITIAL); + return 1; +} +case 10: +YY_RULE_SETUP +#line 174 "cmListFileLexer.in.l" +{ + cmListFileLexerAppend(lexer, yytext, yyleng); + lexer->column += yyleng; +} + YY_BREAK +case 11: +/* rule 11 can match eol */ +YY_RULE_SETUP +#line 179 "cmListFileLexer.in.l" +{ + cmListFileLexerAppend(lexer, yytext, yyleng); + ++lexer->line; + lexer->column = 1; + BEGIN(BRACKET); +} + YY_BREAK +case 12: +YY_RULE_SETUP +#line 186 "cmListFileLexer.in.l" +{ + cmListFileLexerAppend(lexer, yytext, yyleng); + lexer->column += yyleng; + BEGIN(BRACKET); +} + YY_BREAK +case YY_STATE_EOF(BRACKET): +case YY_STATE_EOF(BRACKETEND): +#line 192 "cmListFileLexer.in.l" +{ + lexer->token.type = cmListFileLexer_Token_BadBracket; + BEGIN(INITIAL); + return 1; +} +case 13: +YY_RULE_SETUP +#line 198 "cmListFileLexer.in.l" +{ + lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; + cmListFileLexerSetToken(lexer, yytext, yyleng); + lexer->column += yyleng; + return 1; +} +case 14: +YY_RULE_SETUP +#line 205 "cmListFileLexer.in.l" +{ + lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; + cmListFileLexerSetToken(lexer, yytext, yyleng); + lexer->column += yyleng; + return 1; +} +case 15: +YY_RULE_SETUP +#line 212 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_ArgumentQuoted; cmListFileLexerSetToken(lexer, "", 0); @@ -965,69 +1114,69 @@ YY_RULE_SETUP BEGIN(STRING); } YY_BREAK -case 9: +case 16: YY_RULE_SETUP -#line 139 "cmListFileLexer.in.l" +#line 219 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; } YY_BREAK -case 10: -/* rule 10 can match eol */ +case 17: +/* rule 17 can match eol */ YY_RULE_SETUP -#line 144 "cmListFileLexer.in.l" +#line 224 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); ++lexer->line; lexer->column = 1; } YY_BREAK -case 11: -/* rule 11 can match eol */ +case 18: +/* rule 18 can match eol */ YY_RULE_SETUP -#line 150 "cmListFileLexer.in.l" +#line 230 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); ++lexer->line; lexer->column = 1; } YY_BREAK -case 12: +case 19: YY_RULE_SETUP -#line 156 "cmListFileLexer.in.l" +#line 236 "cmListFileLexer.in.l" { lexer->column += yyleng; BEGIN(INITIAL); return 1; } -case 13: +case 20: YY_RULE_SETUP -#line 162 "cmListFileLexer.in.l" +#line 242 "cmListFileLexer.in.l" { cmListFileLexerAppend(lexer, yytext, yyleng); lexer->column += yyleng; } YY_BREAK case YY_STATE_EOF(STRING): -#line 167 "cmListFileLexer.in.l" +#line 247 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_BadString; BEGIN(INITIAL); return 1; } -case 14: +case 21: YY_RULE_SETUP -#line 173 "cmListFileLexer.in.l" +#line 253 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_Space; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; return 1; } -case 15: +case 22: YY_RULE_SETUP -#line 180 "cmListFileLexer.in.l" +#line 260 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_BadCharacter; cmListFileLexerSetToken(lexer, yytext, yyleng); @@ -1035,18 +1184,19 @@ YY_RULE_SETUP return 1; } case YY_STATE_EOF(INITIAL): -#line 187 "cmListFileLexer.in.l" +case YY_STATE_EOF(COMMENT): +#line 267 "cmListFileLexer.in.l" { lexer->token.type = cmListFileLexer_Token_None; cmListFileLexerSetToken(lexer, 0, 0); return 0; } -case 16: +case 23: YY_RULE_SETUP -#line 193 "cmListFileLexer.in.l" +#line 273 "cmListFileLexer.in.l" ECHO; YY_BREAK -#line 1065 "cmListFileLexer.c" +#line 1217 "cmListFileLexer.c" case YY_END_OF_BUFFER: { @@ -1338,7 +1488,7 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 45 ) + if ( yy_current_state >= 77 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; @@ -1367,11 +1517,11 @@ static int yy_get_next_buffer (yyscan_t yyscanner) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) { yy_current_state = (int) yy_def[yy_current_state]; - if ( yy_current_state >= 45 ) + if ( yy_current_state >= 77 ) yy_c = yy_meta[(unsigned int) yy_c]; } yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; - yy_is_jam = (yy_current_state == 44); + yy_is_jam = (yy_current_state == 76); return yy_is_jam ? 0 : yy_current_state; } @@ -2167,7 +2317,7 @@ void cmListFileLexer_yyfree (void * ptr , yyscan_t yyscanner) #define YYTABLES_NAME "yytables" -#line 193 "cmListFileLexer.in.l" +#line 273 "cmListFileLexer.in.l" @@ -2492,7 +2642,10 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer, case cmListFileLexer_Token_ParenRight: return "right paren"; case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument"; case cmListFileLexer_Token_ArgumentQuoted: return "quoted argument"; + case cmListFileLexer_Token_ArgumentBracket: return "bracket argument"; + case cmListFileLexer_Token_CommentBracket: return "bracket comment"; case cmListFileLexer_Token_BadCharacter: return "bad character"; + case cmListFileLexer_Token_BadBracket: return "unterminated bracket"; case cmListFileLexer_Token_BadString: return "unterminated string"; } return "unknown token"; diff --git a/Source/cmListFileLexer.h b/Source/cmListFileLexer.h index 719347c1a..bd2868ab6 100644 --- a/Source/cmListFileLexer.h +++ b/Source/cmListFileLexer.h @@ -22,7 +22,10 @@ typedef enum cmListFileLexer_Type_e cmListFileLexer_Token_ParenRight, cmListFileLexer_Token_ArgumentUnquoted, cmListFileLexer_Token_ArgumentQuoted, + cmListFileLexer_Token_ArgumentBracket, + cmListFileLexer_Token_CommentBracket, cmListFileLexer_Token_BadCharacter, + cmListFileLexer_Token_BadBracket, cmListFileLexer_Token_BadString } cmListFileLexer_Type; diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l index e2ad0f5f7..ecaf156e9 100644 --- a/Source/cmListFileLexer.in.l +++ b/Source/cmListFileLexer.in.l @@ -42,6 +42,8 @@ Modify cmListFileLexer.c: struct cmListFileLexer_s { cmListFileLexer_Token token; + int bracket; + int comment; int line; int column; int size; @@ -75,22 +77,57 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer); %option noyywrap %pointer %x STRING +%x BRACKET +%x BRACKETEND +%x COMMENT MAKEVAR \$\([A-Za-z0-9_]*\) -UNQUOTED ([^ \t\r\n\(\)#\\\"]|\\.) -LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t])*\" +UNQUOTED ([^ \t\r\n\(\)#\\\"[=]|\\.) +LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\" %% -\n { +\n { lexer->token.type = cmListFileLexer_Token_Newline; cmListFileLexerSetToken(lexer, yytext, yyleng); ++lexer->line; lexer->column = 1; + BEGIN(INITIAL); return 1; } -#.* { +#?\[=*\[\n? { + const char* bracket = yytext; + lexer->comment = yytext[0] == '#'; + if(lexer->comment) + { + lexer->token.type = cmListFileLexer_Token_CommentBracket; + bracket += 1; + } + else + { + lexer->token.type = cmListFileLexer_Token_ArgumentBracket; + } + cmListFileLexerSetToken(lexer, "", 0); + lexer->bracket = (int)(strchr(bracket+1, '[') - bracket); + if(yytext[yyleng-1] == '\n') + { + ++lexer->line; + lexer->column = 1; + } + else + { + lexer->column += yyleng; + } + BEGIN(BRACKET); +} + +# { + lexer->column += yyleng; + BEGIN(COMMENT); +} + +.* { lexer->column += yyleng; } @@ -115,14 +152,57 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t])*\" return 1; } -({UNQUOTED})({UNQUOTED})* { +\]=* { + /* Handle ]]====]=======]*/ + cmListFileLexerAppend(lexer, yytext, yyleng); + lexer->column += yyleng; + if(yyleng == lexer->bracket) + { + BEGIN(BRACKETEND); + } +} + +\] { + lexer->column += yyleng; + /* Erase the partial bracket from the token. */ + lexer->token.length -= lexer->bracket; + lexer->token.text[lexer->token.length] = 0; + BEGIN(INITIAL); + return 1; +} + +([^]\n])+ { + cmListFileLexerAppend(lexer, yytext, yyleng); + lexer->column += yyleng; +} + +\n { + cmListFileLexerAppend(lexer, yytext, yyleng); + ++lexer->line; + lexer->column = 1; + BEGIN(BRACKET); +} + +. { + cmListFileLexerAppend(lexer, yytext, yyleng); + lexer->column += yyleng; + BEGIN(BRACKET); +} + +<> { + lexer->token.type = cmListFileLexer_Token_BadBracket; + BEGIN(INITIAL); + return 1; +} + +({UNQUOTED}|=|\[=*{UNQUOTED})({UNQUOTED}|[[=])* { lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; return 1; } -({MAKEVAR}|{UNQUOTED})({LEGACY})* { +({MAKEVAR}|{UNQUOTED}|=|\[=*{LEGACY})({LEGACY}|[[=])* { lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; cmListFileLexerSetToken(lexer, yytext, yyleng); lexer->column += yyleng; @@ -513,7 +593,10 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer, case cmListFileLexer_Token_ParenRight: return "right paren"; case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument"; case cmListFileLexer_Token_ArgumentQuoted: return "quoted argument"; + case cmListFileLexer_Token_ArgumentBracket: return "bracket argument"; + case cmListFileLexer_Token_CommentBracket: return "bracket comment"; case cmListFileLexer_Token_BadCharacter: return "bad character"; + case cmListFileLexer_Token_BadBracket: return "unterminated bracket"; case cmListFileLexer_Token_BadString: return "unterminated string"; } return "unknown token"; diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index a390e069c..13c43faf5 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -2867,6 +2867,12 @@ bool cmMakefile::ExpandArguments( outArgs.reserve(inArgs.size()); for(i = inArgs.begin(); i != inArgs.end(); ++i) { + // No expansion in a bracket argument. + if(i->Delim == cmListFileArgument::Bracket) + { + outArgs.push_back(i->Value); + continue; + } // Expand the variables in the argument. value = i->Value; this->ExpandVariablesInString(value, false, false, false, diff --git a/Tests/RunCMake/Syntax/.gitattributes b/Tests/RunCMake/Syntax/.gitattributes index 567121ff9..35a9eaf2b 100644 --- a/Tests/RunCMake/Syntax/.gitattributes +++ b/Tests/RunCMake/Syntax/.gitattributes @@ -1,2 +1,3 @@ CommandTabs.cmake whitespace=-tab-in-indent StringCRLF.cmake whitespace=cr-at-eol -crlf +BracketCRLF.cmake whitespace=cr-at-eol -crlf diff --git a/Tests/RunCMake/Syntax/Bracket0-stderr.txt b/Tests/RunCMake/Syntax/Bracket0-stderr.txt new file mode 100644 index 000000000..39cc2bc81 --- /dev/null +++ b/Tests/RunCMake/Syntax/Bracket0-stderr.txt @@ -0,0 +1 @@ +^1 \${var} \\n 4$ diff --git a/Tests/RunCMake/Syntax/Bracket0.cmake b/Tests/RunCMake/Syntax/Bracket0.cmake new file mode 100644 index 000000000..4bc017212 --- /dev/null +++ b/Tests/RunCMake/Syntax/Bracket0.cmake @@ -0,0 +1 @@ +message([[1 ${var} \n 4]]) diff --git a/Tests/RunCMake/Syntax/Bracket1-stderr.txt b/Tests/RunCMake/Syntax/Bracket1-stderr.txt new file mode 100644 index 000000000..e1e13c194 --- /dev/null +++ b/Tests/RunCMake/Syntax/Bracket1-stderr.txt @@ -0,0 +1 @@ +^1 \${var} \\n 4\]==$ diff --git a/Tests/RunCMake/Syntax/Bracket1.cmake b/Tests/RunCMake/Syntax/Bracket1.cmake new file mode 100644 index 000000000..587a57525 --- /dev/null +++ b/Tests/RunCMake/Syntax/Bracket1.cmake @@ -0,0 +1,2 @@ +message([==[1 ]==] [=[ +${var} \n 4]==]=]) diff --git a/Tests/RunCMake/Syntax/Bracket2-stdout.txt b/Tests/RunCMake/Syntax/Bracket2-stdout.txt new file mode 100644 index 000000000..0f8aa2fbb --- /dev/null +++ b/Tests/RunCMake/Syntax/Bracket2-stdout.txt @@ -0,0 +1,2 @@ +-- Bracket Argument 1 +-- Bracket Argument 2 diff --git a/Tests/RunCMake/Syntax/Bracket2.cmake b/Tests/RunCMake/Syntax/Bracket2.cmake new file mode 100644 index 000000000..5c5feed1a --- /dev/null +++ b/Tests/RunCMake/Syntax/Bracket2.cmake @@ -0,0 +1,2 @@ +message(STATUS [[Bracket Argument 1]] #[[Bracket Comment 1]]) +message(STATUS #[[Bracket Comment 2]] [[Bracket Argument 2]]) diff --git a/Tests/RunCMake/Syntax/BracketBackslash-result.txt b/Tests/RunCMake/Syntax/BracketBackslash-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketBackslash-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketBackslash-stderr.txt b/Tests/RunCMake/Syntax/BracketBackslash-stderr.txt new file mode 100644 index 000000000..b746953fc --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketBackslash-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at BracketBackslash.cmake:1 \(message\): + a\\ + + b +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\)$ diff --git a/Tests/RunCMake/Syntax/BracketBackslash.cmake b/Tests/RunCMake/Syntax/BracketBackslash.cmake new file mode 100644 index 000000000..5478e5d76 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketBackslash.cmake @@ -0,0 +1,2 @@ +message(FATAL_ERROR [==[a\ +b]==]) diff --git a/Tests/RunCMake/Syntax/BracketCRLF-stderr.txt b/Tests/RunCMake/Syntax/BracketCRLF-stderr.txt new file mode 100644 index 000000000..7aef26eca --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketCRLF-stderr.txt @@ -0,0 +1 @@ +CRLF->LF worked diff --git a/Tests/RunCMake/Syntax/BracketCRLF.cmake b/Tests/RunCMake/Syntax/BracketCRLF.cmake new file mode 100644 index 000000000..bda0e17ef --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketCRLF.cmake @@ -0,0 +1,8 @@ +if([[ +]] STREQUAL "" AND +[[a +b]] STREQUAL "a\nb") + message("CRLF->LF worked") +else() + message(FATAL_ERROR "CRLF->LF failed") +endif() diff --git a/Tests/RunCMake/Syntax/BracketComment0-stdout.txt b/Tests/RunCMake/Syntax/BracketComment0-stdout.txt new file mode 100644 index 000000000..c9c0be43b --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment0-stdout.txt @@ -0,0 +1 @@ +-- The above FATAL_ERROR did not occur. diff --git a/Tests/RunCMake/Syntax/BracketComment0.cmake b/Tests/RunCMake/Syntax/BracketComment0.cmake new file mode 100644 index 000000000..0ee95de88 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment0.cmake @@ -0,0 +1,5 @@ +#[=[ +#]] +message(FATAL_ERROR "This is commented out.") +#]==]=] +message(STATUS "The above FATAL_ERROR did not occur.") diff --git a/Tests/RunCMake/Syntax/BracketComment1-result.txt b/Tests/RunCMake/Syntax/BracketComment1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketComment1-stderr.txt b/Tests/RunCMake/Syntax/BracketComment1-stderr.txt new file mode 100644 index 000000000..a9373decc --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment1-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at BracketComment1.cmake:2 \(message\): + This is not commented out. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketComment1.cmake b/Tests/RunCMake/Syntax/BracketComment1.cmake new file mode 100644 index 000000000..2ec9d2016 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment1.cmake @@ -0,0 +1,3 @@ +##[[ +message(FATAL_ERROR "This is not commented out.") +#]] diff --git a/Tests/RunCMake/Syntax/BracketComment2-result.txt b/Tests/RunCMake/Syntax/BracketComment2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketComment2-stderr.txt b/Tests/RunCMake/Syntax/BracketComment2-stderr.txt new file mode 100644 index 000000000..7e982229a --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment2-stderr.txt @@ -0,0 +1,4 @@ +CMake Error at BracketComment2.cmake:2 \(message\): + This is not commented out. +Call Stack \(most recent call first\): + CMakeLists.txt:3 \(include\) diff --git a/Tests/RunCMake/Syntax/BracketComment2.cmake b/Tests/RunCMake/Syntax/BracketComment2.cmake new file mode 100644 index 000000000..3eda32d34 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment2.cmake @@ -0,0 +1,3 @@ +# [[ +message(FATAL_ERROR "This is not commented out.") +#]] diff --git a/Tests/RunCMake/Syntax/BracketComment3-stdout.txt b/Tests/RunCMake/Syntax/BracketComment3-stdout.txt new file mode 100644 index 000000000..c9c0be43b --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment3-stdout.txt @@ -0,0 +1 @@ +-- The above FATAL_ERROR did not occur. diff --git a/Tests/RunCMake/Syntax/BracketComment3.cmake b/Tests/RunCMake/Syntax/BracketComment3.cmake new file mode 100644 index 000000000..ffd03a931 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment3.cmake @@ -0,0 +1,4 @@ +#[[Text on opening line +message(FATAL_ERROR "This is commented out.") +#]=]] +message(STATUS "The above FATAL_ERROR did not occur.") diff --git a/Tests/RunCMake/Syntax/BracketComment4-result.txt b/Tests/RunCMake/Syntax/BracketComment4-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment4-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketComment4-stderr.txt b/Tests/RunCMake/Syntax/BracketComment4-stderr.txt new file mode 100644 index 000000000..8ba32c22c --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment4-stderr.txt @@ -0,0 +1,7 @@ +CMake Error: Error in cmake code at +.*/Tests/RunCMake/Syntax/BracketComment4.cmake:3: +Parse error. Expected a newline, got identifier with text "message". +CMake Error at CMakeLists.txt:3 \(include\): + include could not find load file: + + BracketComment4.cmake diff --git a/Tests/RunCMake/Syntax/BracketComment4.cmake b/Tests/RunCMake/Syntax/BracketComment4.cmake new file mode 100644 index 000000000..9d586f114 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment4.cmake @@ -0,0 +1,3 @@ +#[[ +message(FATAL_ERROR "This is commented out.") +#]] message(STATUS "This command not allowed here") diff --git a/Tests/RunCMake/Syntax/BracketComment5-stdout.txt b/Tests/RunCMake/Syntax/BracketComment5-stdout.txt new file mode 100644 index 000000000..c9c0be43b --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment5-stdout.txt @@ -0,0 +1 @@ +-- The above FATAL_ERROR did not occur. diff --git a/Tests/RunCMake/Syntax/BracketComment5.cmake b/Tests/RunCMake/Syntax/BracketComment5.cmake new file mode 100644 index 000000000..bb6d9f318 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketComment5.cmake @@ -0,0 +1,6 @@ +#[[ +message(FATAL_ERROR "This is commented out.") +#]] #[[ +message(FATAL_ERROR "This is commented out.") +#]] #message(FATAL_ERROR "This is commented out.") +message(STATUS "The above FATAL_ERROR did not occur.") diff --git a/Tests/RunCMake/Syntax/BracketNoSpace0-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace0-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace0-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt new file mode 100644 index 000000000..afd91f9f2 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at CMakeLists.txt:3 \(include\): + Syntax Error in cmake code at + + .*/Tests/RunCMake/Syntax/BracketNoSpace0.cmake:1:27 + + Argument not separated from preceding token by whitespace. diff --git a/Tests/RunCMake/Syntax/BracketNoSpace0.cmake b/Tests/RunCMake/Syntax/BracketNoSpace0.cmake new file mode 100644 index 000000000..1de145055 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace0.cmake @@ -0,0 +1 @@ +message(STATUS [[bracket]]unquoted) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace1-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt new file mode 100644 index 000000000..826e51125 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at CMakeLists.txt:3 \(include\): + Syntax Error in cmake code at + + .*/Tests/RunCMake/Syntax/BracketNoSpace1.cmake:1:24 + + Argument not separated from preceding token by whitespace. diff --git a/Tests/RunCMake/Syntax/BracketNoSpace1.cmake b/Tests/RunCMake/Syntax/BracketNoSpace1.cmake new file mode 100644 index 000000000..7982bf3c6 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace1.cmake @@ -0,0 +1 @@ +message(STATUS "string"[[bracket]]) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace2-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt new file mode 100644 index 000000000..23ecdcddc --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at CMakeLists.txt:3 \(include\): + Syntax Error in cmake code at + + .*/Tests/RunCMake/Syntax/BracketNoSpace2.cmake:1:44 + + Argument not separated from preceding token by whitespace. diff --git a/Tests/RunCMake/Syntax/BracketNoSpace2.cmake b/Tests/RunCMake/Syntax/BracketNoSpace2.cmake new file mode 100644 index 000000000..f1507f3ac --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace2.cmake @@ -0,0 +1 @@ +message(STATUS "string"#[[bracket comment]][[bracket]]) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace3-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace3-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace3-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt new file mode 100644 index 000000000..906d6fc3e --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at CMakeLists.txt:3 \(include\): + Syntax Error in cmake code at + + .*/Tests/RunCMake/Syntax/BracketNoSpace3.cmake:1:45 + + Argument not separated from preceding token by whitespace. diff --git a/Tests/RunCMake/Syntax/BracketNoSpace3.cmake b/Tests/RunCMake/Syntax/BracketNoSpace3.cmake new file mode 100644 index 000000000..45dc900ea --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace3.cmake @@ -0,0 +1 @@ +message(STATUS "string" #[[bracket comment]][[bracket]]) diff --git a/Tests/RunCMake/Syntax/BracketNoSpace4-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace4-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace4-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt new file mode 100644 index 000000000..a461e93f7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at CMakeLists.txt:3 \(include\): + Syntax Error in cmake code at + + .*/Tests/RunCMake/Syntax/BracketNoSpace4.cmake:1:44 + + Argument not separated from preceding token by whitespace. diff --git a/Tests/RunCMake/Syntax/BracketNoSpace4.cmake b/Tests/RunCMake/Syntax/BracketNoSpace4.cmake new file mode 100644 index 000000000..cb4ddbec8 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace4.cmake @@ -0,0 +1 @@ +message(STATUS "string"#[[bracket comment]]"string") diff --git a/Tests/RunCMake/Syntax/BracketNoSpace5-result.txt b/Tests/RunCMake/Syntax/BracketNoSpace5-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace5-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt b/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt new file mode 100644 index 000000000..ff8bf1c40 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt @@ -0,0 +1,6 @@ +CMake Error at CMakeLists.txt:3 \(include\): + Syntax Error in cmake code at + + .*/Tests/RunCMake/Syntax/BracketNoSpace5.cmake:1:45 + + Argument not separated from preceding token by whitespace. diff --git a/Tests/RunCMake/Syntax/BracketNoSpace5.cmake b/Tests/RunCMake/Syntax/BracketNoSpace5.cmake new file mode 100644 index 000000000..c68452322 --- /dev/null +++ b/Tests/RunCMake/Syntax/BracketNoSpace5.cmake @@ -0,0 +1 @@ +message(STATUS "string" #[[bracket comment]]"string") diff --git a/Tests/RunCMake/Syntax/BracketWarn-stderr.txt b/Tests/RunCMake/Syntax/BracketWarn-stderr.txt deleted file mode 100644 index 4a9cca641..000000000 --- a/Tests/RunCMake/Syntax/BracketWarn-stderr.txt +++ /dev/null @@ -1,35 +0,0 @@ -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): - Syntax Warning in cmake code at - - .*/Tests/RunCMake/Syntax/BracketWarn.cmake:1:16 - - A future version of CMake may treat unquoted argument: - - \[\[ - - as an opening long bracket. Double-quote the argument. -This warning is for project developers. Use -Wno-dev to suppress it. - -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): - Syntax Warning in cmake code at - - .*/Tests/RunCMake/Syntax/BracketWarn.cmake:1:19 - - A future version of CMake may treat unquoted argument: - - \[=\[ - - as an opening long bracket. Double-quote the argument. -This warning is for project developers. Use -Wno-dev to suppress it. - -CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): - Syntax Warning in cmake code at - - .*/Tests/RunCMake/Syntax/BracketWarn.cmake:1:27 - - A future version of CMake may treat unquoted argument: - - \[==\[x - - as an opening long bracket. Double-quote the argument. -This warning is for project developers. Use -Wno-dev to suppress it. diff --git a/Tests/RunCMake/Syntax/BracketWarn-stdout.txt b/Tests/RunCMake/Syntax/BracketWarn-stdout.txt deleted file mode 100644 index 01b2caaa4..000000000 --- a/Tests/RunCMake/Syntax/BracketWarn-stdout.txt +++ /dev/null @@ -1 +0,0 @@ --- \[\[\[=\[\[=x\[==\[x diff --git a/Tests/RunCMake/Syntax/BracketWarn.cmake b/Tests/RunCMake/Syntax/BracketWarn.cmake deleted file mode 100644 index 8f33946f0..000000000 --- a/Tests/RunCMake/Syntax/BracketWarn.cmake +++ /dev/null @@ -1 +0,0 @@ -message(STATUS [[ [=[ [=x [==[x) diff --git a/Tests/RunCMake/Syntax/CommandError2-result.txt b/Tests/RunCMake/Syntax/CommandError2-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/CommandError2-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/CommandError2-stderr.txt b/Tests/RunCMake/Syntax/CommandError2-stderr.txt new file mode 100644 index 000000000..f4dfc7749 --- /dev/null +++ b/Tests/RunCMake/Syntax/CommandError2-stderr.txt @@ -0,0 +1,7 @@ +CMake Error: Error in cmake code at +.*/Tests/RunCMake/Syntax/CommandError2.cmake:1: +Parse error. Expected a command name, got bracket argument with text "oops-not-a-comment". +CMake Error at CMakeLists.txt:3 \(include\): + include could not find load file: + + CommandError2.cmake diff --git a/Tests/RunCMake/Syntax/CommandError2.cmake b/Tests/RunCMake/Syntax/CommandError2.cmake new file mode 100644 index 000000000..a269682a0 --- /dev/null +++ b/Tests/RunCMake/Syntax/CommandError2.cmake @@ -0,0 +1 @@ +message("Example Message") [[oops-not-a-comment]] diff --git a/Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt b/Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt new file mode 100644 index 000000000..5c4076f67 --- /dev/null +++ b/Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt @@ -0,0 +1,3 @@ +-- \(unquoted\) +-- \(quoted\) +-- \(bracket\) diff --git a/Tests/RunCMake/Syntax/ParenNoSpace0.cmake b/Tests/RunCMake/Syntax/ParenNoSpace0.cmake new file mode 100644 index 000000000..175fe4a80 --- /dev/null +++ b/Tests/RunCMake/Syntax/ParenNoSpace0.cmake @@ -0,0 +1,3 @@ +message(STATUS (unquoted)) +message(STATUS ("quoted")) +message(STATUS ([[bracket]])) diff --git a/Tests/RunCMake/Syntax/ParenNoSpace1-result.txt b/Tests/RunCMake/Syntax/ParenNoSpace1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/ParenNoSpace1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt b/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt new file mode 100644 index 000000000..64ef8b131 --- /dev/null +++ b/Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt @@ -0,0 +1,22 @@ +CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): + Syntax Warning in cmake code at + + .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:1:26 + + Argument not separated from preceding token by whitespace. +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Warning \(dev\) at CMakeLists.txt:3 \(include\): + Syntax Warning in cmake code at + + .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:2:26 + + Argument not separated from preceding token by whitespace. +This warning is for project developers. Use -Wno-dev to suppress it. + +CMake Error at CMakeLists.txt:3 \(include\): + Syntax Error in cmake code at + + .*/Tests/RunCMake/Syntax/ParenNoSpace1.cmake:3:29 + + Argument not separated from preceding token by whitespace. diff --git a/Tests/RunCMake/Syntax/ParenNoSpace1.cmake b/Tests/RunCMake/Syntax/ParenNoSpace1.cmake new file mode 100644 index 000000000..550339a2f --- /dev/null +++ b/Tests/RunCMake/Syntax/ParenNoSpace1.cmake @@ -0,0 +1,3 @@ +message(STATUS (unquoted)unquoted) +message(STATUS ("quoted")"quoted") +message(STATUS ([[bracket]])[[bracket]]) diff --git a/Tests/RunCMake/Syntax/ParenNoSpace-stderr.txt b/Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt similarity index 100% rename from Tests/RunCMake/Syntax/ParenNoSpace-stderr.txt rename to Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt diff --git a/Tests/RunCMake/Syntax/ParenNoSpace-stdout.txt b/Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt similarity index 66% rename from Tests/RunCMake/Syntax/ParenNoSpace-stdout.txt rename to Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt index 72addd794..0e657b92f 100644 --- a/Tests/RunCMake/Syntax/ParenNoSpace-stdout.txt +++ b/Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt @@ -1,2 +1,3 @@ -- unquoted\(unquoted\) -- quoted\(quoted\) +-- bracket\(bracket\) diff --git a/Tests/RunCMake/Syntax/ParenNoSpace.cmake b/Tests/RunCMake/Syntax/ParenNoSpace2.cmake similarity index 63% rename from Tests/RunCMake/Syntax/ParenNoSpace.cmake rename to Tests/RunCMake/Syntax/ParenNoSpace2.cmake index c690d964e..c46a88747 100644 --- a/Tests/RunCMake/Syntax/ParenNoSpace.cmake +++ b/Tests/RunCMake/Syntax/ParenNoSpace2.cmake @@ -1,2 +1,3 @@ message(STATUS unquoted(unquoted)) message(STATUS "quoted"("quoted")) +message(STATUS [[bracket]]([[bracket]])) diff --git a/Tests/RunCMake/Syntax/RunCMakeTest.cmake b/Tests/RunCMake/Syntax/RunCMakeTest.cmake index 1399d8ba2..f5e0d11e0 100644 --- a/Tests/RunCMake/Syntax/RunCMakeTest.cmake +++ b/Tests/RunCMake/Syntax/RunCMakeTest.cmake @@ -11,6 +11,7 @@ run_cmake(CommandNewlines) run_cmake(CommandComments) run_cmake(CommandError0) run_cmake(CommandError1) +run_cmake(CommandError2) run_cmake(String0) run_cmake(String1) run_cmake(StringCRLF) @@ -18,8 +19,29 @@ run_cmake(StringNoSpace) run_cmake(OneLetter) run_cmake(Unquoted0) run_cmake(Unquoted1) -run_cmake(ParenNoSpace) +run_cmake(Bracket0) +run_cmake(Bracket1) +run_cmake(Bracket2) +run_cmake(BracketBackslash) +run_cmake(BracketCRLF) +run_cmake(BracketComment0) +run_cmake(BracketComment1) +run_cmake(BracketComment2) +run_cmake(BracketComment3) +run_cmake(BracketComment4) +run_cmake(BracketComment5) +run_cmake(BracketNoSpace0) +run_cmake(BracketNoSpace1) +run_cmake(BracketNoSpace2) +run_cmake(BracketNoSpace3) +run_cmake(BracketNoSpace4) +run_cmake(BracketNoSpace5) +run_cmake(ParenNoSpace0) +run_cmake(ParenNoSpace1) +run_cmake(ParenNoSpace2) run_cmake(UnterminatedCall1) run_cmake(UnterminatedCall2) run_cmake(UnterminatedString) -run_cmake(BracketWarn) +run_cmake(UnterminatedBracket0) +run_cmake(UnterminatedBracket1) +run_cmake(UnterminatedBracketComment) diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt b/Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt new file mode 100644 index 000000000..3559c1893 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt @@ -0,0 +1,8 @@ +CMake Error: Error in cmake code at +.*/Syntax/UnterminatedBracket0.cmake:2: +Parse error. Function missing ending "\)". Instead found unterminated bracket with text "\) +". +CMake Error at CMakeLists.txt:3 \(include\): + include could not find load file: + + UnterminatedBracket0.cmake$ diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket0.cmake b/Tests/RunCMake/Syntax/UnterminatedBracket0.cmake new file mode 100644 index 000000000..98cd906e0 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracket0.cmake @@ -0,0 +1 @@ +set(var [[) diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt b/Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt new file mode 100644 index 000000000..55d458ba2 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt @@ -0,0 +1,8 @@ +CMake Error: Error in cmake code at +.*/Syntax/UnterminatedBracket1.cmake:2: +Parse error. Function missing ending "\)". Instead found unterminated bracket with text "\]\]\) +". +CMake Error at CMakeLists.txt:3 \(include\): + include could not find load file: + + UnterminatedBracket1.cmake$ diff --git a/Tests/RunCMake/Syntax/UnterminatedBracket1.cmake b/Tests/RunCMake/Syntax/UnterminatedBracket1.cmake new file mode 100644 index 000000000..706f7a321 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracket1.cmake @@ -0,0 +1 @@ +set(var [=[]]) diff --git a/Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt b/Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt new file mode 100644 index 000000000..d00491fd7 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt @@ -0,0 +1 @@ +1 diff --git a/Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt b/Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt new file mode 100644 index 000000000..0a799eb5a --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt @@ -0,0 +1,8 @@ +CMake Error: Error in cmake code at +.*/Syntax/UnterminatedBracketComment.cmake:1: +Parse error. Expected a command name, got unterminated bracket with text "#\]\] +". +CMake Error at CMakeLists.txt:3 \(include\): + include could not find load file: + + UnterminatedBracketComment.cmake diff --git a/Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake b/Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake new file mode 100644 index 000000000..ad71f3c51 --- /dev/null +++ b/Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake @@ -0,0 +1,2 @@ +#[=[ +#]]