Explorar o código

Merge topic 'cmake-syntax-updates'

daa0f6f Add Lua-style long brackets and long comments to CMake language
a8c6523 cmListFileLexer: Convert CRLF -> LF newlines explicitly
dbd9333 cmListFileLexer: Allow a leading UTF-8 Byte-Order-Mark (#11137)
5645783 cmListFileLexer: Allow command names with one letter (#14181)
Brad King %!s(int64=12) %!d(string=hai) anos
pai
achega
9fb65d7090
Modificáronse 93 ficheiros con 884 adicións e 200 borrados
  1. 63 32
      Source/cmListFileCache.cxx
  2. 2 1
      Source/cmListFileCache.h
  3. 348 114
      Source/cmListFileLexer.c
  4. 16 1
      Source/cmListFileLexer.h
  5. 177 13
      Source/cmListFileLexer.in.l
  6. 6 0
      Source/cmMakefile.cxx
  7. 2 0
      Tests/RunCMake/Syntax/.gitattributes
  8. 1 0
      Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt
  9. 6 0
      Tests/RunCMake/Syntax/BOM-UTF-16-BE-stderr.txt
  10. BIN=BIN
      Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake
  11. 1 0
      Tests/RunCMake/Syntax/BOM-UTF-16-LE-result.txt
  12. 6 0
      Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt
  13. BIN=BIN
      Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake
  14. 1 0
      Tests/RunCMake/Syntax/BOM-UTF-32-BE-result.txt
  15. 6 0
      Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt
  16. BIN=BIN
      Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake
  17. 1 0
      Tests/RunCMake/Syntax/BOM-UTF-32-LE-result.txt
  18. 6 0
      Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt
  19. BIN=BIN
      Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake
  20. 1 0
      Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt
  21. 1 0
      Tests/RunCMake/Syntax/BOM-UTF-8.cmake
  22. 1 0
      Tests/RunCMake/Syntax/Bracket0-stderr.txt
  23. 1 0
      Tests/RunCMake/Syntax/Bracket0.cmake
  24. 1 0
      Tests/RunCMake/Syntax/Bracket1-stderr.txt
  25. 2 0
      Tests/RunCMake/Syntax/Bracket1.cmake
  26. 2 0
      Tests/RunCMake/Syntax/Bracket2-stdout.txt
  27. 2 0
      Tests/RunCMake/Syntax/Bracket2.cmake
  28. 1 0
      Tests/RunCMake/Syntax/BracketBackslash-result.txt
  29. 6 0
      Tests/RunCMake/Syntax/BracketBackslash-stderr.txt
  30. 2 0
      Tests/RunCMake/Syntax/BracketBackslash.cmake
  31. 1 0
      Tests/RunCMake/Syntax/BracketCRLF-stderr.txt
  32. 8 0
      Tests/RunCMake/Syntax/BracketCRLF.cmake
  33. 1 0
      Tests/RunCMake/Syntax/BracketComment0-stdout.txt
  34. 5 0
      Tests/RunCMake/Syntax/BracketComment0.cmake
  35. 1 0
      Tests/RunCMake/Syntax/BracketComment1-result.txt
  36. 4 0
      Tests/RunCMake/Syntax/BracketComment1-stderr.txt
  37. 3 0
      Tests/RunCMake/Syntax/BracketComment1.cmake
  38. 1 0
      Tests/RunCMake/Syntax/BracketComment2-result.txt
  39. 4 0
      Tests/RunCMake/Syntax/BracketComment2-stderr.txt
  40. 3 0
      Tests/RunCMake/Syntax/BracketComment2.cmake
  41. 1 0
      Tests/RunCMake/Syntax/BracketComment3-stdout.txt
  42. 4 0
      Tests/RunCMake/Syntax/BracketComment3.cmake
  43. 1 0
      Tests/RunCMake/Syntax/BracketComment4-result.txt
  44. 7 0
      Tests/RunCMake/Syntax/BracketComment4-stderr.txt
  45. 3 0
      Tests/RunCMake/Syntax/BracketComment4.cmake
  46. 1 0
      Tests/RunCMake/Syntax/BracketComment5-stdout.txt
  47. 6 0
      Tests/RunCMake/Syntax/BracketComment5.cmake
  48. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace0-result.txt
  49. 6 0
      Tests/RunCMake/Syntax/BracketNoSpace0-stderr.txt
  50. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace0.cmake
  51. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace1-result.txt
  52. 6 0
      Tests/RunCMake/Syntax/BracketNoSpace1-stderr.txt
  53. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace1.cmake
  54. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace2-result.txt
  55. 6 0
      Tests/RunCMake/Syntax/BracketNoSpace2-stderr.txt
  56. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace2.cmake
  57. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace3-result.txt
  58. 6 0
      Tests/RunCMake/Syntax/BracketNoSpace3-stderr.txt
  59. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace3.cmake
  60. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace4-result.txt
  61. 6 0
      Tests/RunCMake/Syntax/BracketNoSpace4-stderr.txt
  62. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace4.cmake
  63. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace5-result.txt
  64. 6 0
      Tests/RunCMake/Syntax/BracketNoSpace5-stderr.txt
  65. 1 0
      Tests/RunCMake/Syntax/BracketNoSpace5.cmake
  66. 0 35
      Tests/RunCMake/Syntax/BracketWarn-stderr.txt
  67. 0 1
      Tests/RunCMake/Syntax/BracketWarn-stdout.txt
  68. 0 1
      Tests/RunCMake/Syntax/BracketWarn.cmake
  69. 1 0
      Tests/RunCMake/Syntax/CommandError2-result.txt
  70. 7 0
      Tests/RunCMake/Syntax/CommandError2-stderr.txt
  71. 1 0
      Tests/RunCMake/Syntax/CommandError2.cmake
  72. 1 0
      Tests/RunCMake/Syntax/OneLetter-stderr.txt
  73. 7 0
      Tests/RunCMake/Syntax/OneLetter.cmake
  74. 3 0
      Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt
  75. 3 0
      Tests/RunCMake/Syntax/ParenNoSpace0.cmake
  76. 1 0
      Tests/RunCMake/Syntax/ParenNoSpace1-result.txt
  77. 22 0
      Tests/RunCMake/Syntax/ParenNoSpace1-stderr.txt
  78. 3 0
      Tests/RunCMake/Syntax/ParenNoSpace1.cmake
  79. 0 0
      Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt
  80. 1 0
      Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt
  81. 1 0
      Tests/RunCMake/Syntax/ParenNoSpace2.cmake
  82. 31 2
      Tests/RunCMake/Syntax/RunCMakeTest.cmake
  83. 1 0
      Tests/RunCMake/Syntax/StringCRLF-stderr.txt
  84. 6 0
      Tests/RunCMake/Syntax/StringCRLF.cmake
  85. 1 0
      Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt
  86. 8 0
      Tests/RunCMake/Syntax/UnterminatedBracket0-stderr.txt
  87. 1 0
      Tests/RunCMake/Syntax/UnterminatedBracket0.cmake
  88. 1 0
      Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt
  89. 8 0
      Tests/RunCMake/Syntax/UnterminatedBracket1-stderr.txt
  90. 1 0
      Tests/RunCMake/Syntax/UnterminatedBracket1.cmake
  91. 1 0
      Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt
  92. 8 0
      Tests/RunCMake/Syntax/UnterminatedBracketComment-stderr.txt
  93. 2 0
      Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake

+ 63 - 32
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;
 };
 
 //----------------------------------------------------------------------------
@@ -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;
@@ -77,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)
@@ -288,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)
       {
@@ -298,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.
@@ -338,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;
+    }
 }
 
 //----------------------------------------------------------------------------

+ 2 - 1
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):

+ 348 - 114
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,    6,   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,   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,
+       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,
+
+       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,
-
-       44,   32,   32,   33,   33,   44,   33,   33,    5,   44,
-       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
-       44
+       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,
+
+       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,
-
-        0,   52,   52,   54,   54,    0,   54,   54,   44,   44,
-       44,   44,   44,   44,   44,   44,   44,   44,   44,   44,
-       44
+        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,    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,10 +580,13 @@ Modify cmListFileLexer.c:
 struct cmListFileLexer_s
 {
   cmListFileLexer_Token token;
+  int bracket;
+  int comment;
   int line;
   int column;
   int size;
   FILE* file;
+  size_t cr;
   char* string_buffer;
   char* string_position;
   int string_left;
@@ -564,10 +609,16 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer);
 
 /*--------------------------------------------------------------------------*/
 
-#line 570 "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
@@ -793,10 +844,10 @@ YY_DECL
         int yy_act;
     struct yyguts_t * yyg = (struct yyguts_t*)yyscanner;
 
-#line 82 "cmListFileLexer.in.l"
+#line 88 "cmListFileLexer.in.l"
 
 
-#line 804 "cmListFileLexer.c"
+#line 855 "cmListFileLexer.c"
 
         if ( !yyg->yy_init )
                 {
@@ -849,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];
@@ -894,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 84 "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 92 "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 96 "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 103 "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 110 "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:
+case 8:
+YY_RULE_SETUP
+#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 117 "cmListFileLexer.in.l"
+#line 198 "cmListFileLexer.in.l"
 {
   lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
   cmListFileLexerSetToken(lexer, yytext, yyleng);
   lexer->column += yyleng;
   return 1;
 }
-case 7:
+case 14:
 YY_RULE_SETUP
-#line 124 "cmListFileLexer.in.l"
+#line 205 "cmListFileLexer.in.l"
 {
   lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
   cmListFileLexerSetToken(lexer, yytext, yyleng);
   lexer->column += yyleng;
   return 1;
 }
-case 8:
+case 15:
 YY_RULE_SETUP
-#line 131 "cmListFileLexer.in.l"
+#line 212 "cmListFileLexer.in.l"
 {
   lexer->token.type = cmListFileLexer_Token_ArgumentQuoted;
   cmListFileLexerSetToken(lexer, "", 0);
@@ -964,69 +1114,69 @@ YY_RULE_SETUP
   BEGIN(STRING);
 }
         YY_BREAK
-case 9:
+case 16:
 YY_RULE_SETUP
-#line 138 "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 143 "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 149 "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 155 "cmListFileLexer.in.l"
+#line 236 "cmListFileLexer.in.l"
 {
   lexer->column += yyleng;
   BEGIN(INITIAL);
   return 1;
 }
-case 13:
+case 20:
 YY_RULE_SETUP
-#line 161 "cmListFileLexer.in.l"
+#line 242 "cmListFileLexer.in.l"
 {
   cmListFileLexerAppend(lexer, yytext, yyleng);
   lexer->column += yyleng;
 }
         YY_BREAK
 case YY_STATE_EOF(STRING):
-#line 166 "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 172 "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 179 "cmListFileLexer.in.l"
+#line 260 "cmListFileLexer.in.l"
 {
   lexer->token.type = cmListFileLexer_Token_BadCharacter;
   cmListFileLexerSetToken(lexer, yytext, yyleng);
@@ -1034,18 +1184,19 @@ YY_RULE_SETUP
   return 1;
 }
 case YY_STATE_EOF(INITIAL):
-#line 186 "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 192 "cmListFileLexer.in.l"
+#line 273 "cmListFileLexer.in.l"
 ECHO;
         YY_BREAK
-#line 1064 "cmListFileLexer.c"
+#line 1217 "cmListFileLexer.c"
 
         case YY_END_OF_BUFFER:
                 {
@@ -1337,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];
@@ -1366,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;
 }
@@ -2166,7 +2317,7 @@ void cmListFileLexer_yyfree (void * ptr , yyscan_t yyscanner)
 
 #define YYTABLES_NAME "yytables"
 
-#line 192 "cmListFileLexer.in.l"
+#line 273 "cmListFileLexer.in.l"
 
 
 
@@ -2243,7 +2394,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)
       {
@@ -2307,19 +2489,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)
+    lexer->file = fopen(name, "rb");
+    if(lexer->file)
+      {
+      if(bom)
+        {
+        *bom = cmListFileLexer_ReadBOM(lexer->file);
+        }
+      }
+    else
       {
       result = 0;
       }
@@ -2365,7 +2596,7 @@ cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer)
     }
   else
     {
-    cmListFileLexer_SetFileName(lexer, 0);
+    cmListFileLexer_SetFileName(lexer, 0, 0);
     return 0;
     }
 }
@@ -2411,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";

+ 16 - 1
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;
 
@@ -36,6 +39,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 +58,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*);

+ 177 - 13
Source/cmListFileLexer.in.l

@@ -42,10 +42,13 @@ Modify cmListFileLexer.c:
 struct cmListFileLexer_s
 {
   cmListFileLexer_Token token;
+  int bracket;
+  int comment;
   int line;
   int column;
   int size;
   FILE* file;
+  size_t cr;
   char* string_buffer;
   char* string_position;
   int string_left;
@@ -74,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 {
+<INITIAL,COMMENT>\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);
+}
+
+<COMMENT>.* {
   lexer->column += yyleng;
 }
 
@@ -107,21 +145,64 @@ 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;
   return 1;
 }
 
-({UNQUOTED})({UNQUOTED})* {
+<BRACKET>\]=* {
+  /* Handle ]]====]=======]*/
+  cmListFileLexerAppend(lexer, yytext, yyleng);
+  lexer->column += yyleng;
+  if(yyleng == lexer->bracket)
+    {
+    BEGIN(BRACKETEND);
+    }
+}
+
+<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;
+}
+
+<BRACKET>([^]\n])+ {
+  cmListFileLexerAppend(lexer, yytext, yyleng);
+  lexer->column += yyleng;
+}
+
+<BRACKET,BRACKETEND>\n {
+  cmListFileLexerAppend(lexer, yytext, yyleng);
+  ++lexer->line;
+  lexer->column = 1;
+  BEGIN(BRACKET);
+}
+
+<BRACKET,BRACKETEND>. {
+  cmListFileLexerAppend(lexer, yytext, yyleng);
+  lexer->column += yyleng;
+  BEGIN(BRACKET);
+}
+
+<BRACKET,BRACKETEND><<EOF>> {
+  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;
@@ -264,7 +345,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)
       {
@@ -328,19 +440,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)
+    lexer->file = fopen(name, "rb");
+    if(lexer->file)
+      {
+      if(bom)
+        {
+        *bom = cmListFileLexer_ReadBOM(lexer->file);
+        }
+      }
+    else
       {
       result = 0;
       }
@@ -386,7 +547,7 @@ cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer)
     }
   else
     {
-    cmListFileLexer_SetFileName(lexer, 0);
+    cmListFileLexer_SetFileName(lexer, 0, 0);
     return 0;
     }
 }
@@ -432,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";

+ 6 - 0
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,

+ 2 - 0
Tests/RunCMake/Syntax/.gitattributes

@@ -1 +1,3 @@
 CommandTabs.cmake   whitespace=-tab-in-indent
+StringCRLF.cmake    whitespace=cr-at-eol      -crlf
+BracketCRLF.cmake   whitespace=cr-at-eol      -crlf

+ 1 - 0
Tests/RunCMake/Syntax/BOM-UTF-16-BE-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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.

BIN=BIN
Tests/RunCMake/Syntax/BOM-UTF-16-BE.cmake


+ 1 - 0
Tests/RunCMake/Syntax/BOM-UTF-16-LE-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/Syntax/BOM-UTF-16-LE-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+  File
+
+    .*/Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake
+
+  starts with a Byte-Order-Mark that is not UTF-8.

BIN=BIN
Tests/RunCMake/Syntax/BOM-UTF-16-LE.cmake


+ 1 - 0
Tests/RunCMake/Syntax/BOM-UTF-32-BE-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/Syntax/BOM-UTF-32-BE-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+  File
+
+    .*/Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake
+
+  starts with a Byte-Order-Mark that is not UTF-8.

BIN=BIN
Tests/RunCMake/Syntax/BOM-UTF-32-BE.cmake


+ 1 - 0
Tests/RunCMake/Syntax/BOM-UTF-32-LE-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
Tests/RunCMake/Syntax/BOM-UTF-32-LE-stderr.txt

@@ -0,0 +1,6 @@
+CMake Error at CMakeLists.txt:3 \(include\):
+  File
+
+    .*/Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake
+
+  starts with a Byte-Order-Mark that is not UTF-8.

BIN=BIN
Tests/RunCMake/Syntax/BOM-UTF-32-LE.cmake


+ 1 - 0
Tests/RunCMake/Syntax/BOM-UTF-8-stdout.txt

@@ -0,0 +1 @@
+-- message

+ 1 - 0
Tests/RunCMake/Syntax/BOM-UTF-8.cmake

@@ -0,0 +1 @@
+message(STATUS "message")

+ 1 - 0
Tests/RunCMake/Syntax/Bracket0-stderr.txt

@@ -0,0 +1 @@
+^1 \${var} \\n 4$

+ 1 - 0
Tests/RunCMake/Syntax/Bracket0.cmake

@@ -0,0 +1 @@
+message([[1 ${var} \n 4]])

+ 1 - 0
Tests/RunCMake/Syntax/Bracket1-stderr.txt

@@ -0,0 +1 @@
+^1 \${var} \\n 4\]==$

+ 2 - 0
Tests/RunCMake/Syntax/Bracket1.cmake

@@ -0,0 +1,2 @@
+message([==[1 ]==] [=[
+${var} \n 4]==]=])

+ 2 - 0
Tests/RunCMake/Syntax/Bracket2-stdout.txt

@@ -0,0 +1,2 @@
+-- Bracket Argument 1
+-- Bracket Argument 2

+ 2 - 0
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]])

+ 1 - 0
Tests/RunCMake/Syntax/BracketBackslash-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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\)$

+ 2 - 0
Tests/RunCMake/Syntax/BracketBackslash.cmake

@@ -0,0 +1,2 @@
+message(FATAL_ERROR [==[a\
+b]==])

+ 1 - 0
Tests/RunCMake/Syntax/BracketCRLF-stderr.txt

@@ -0,0 +1 @@
+CRLF->LF worked

+ 8 - 0
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()

+ 1 - 0
Tests/RunCMake/Syntax/BracketComment0-stdout.txt

@@ -0,0 +1 @@
+-- The above FATAL_ERROR did not occur.

+ 5 - 0
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.")

+ 1 - 0
Tests/RunCMake/Syntax/BracketComment1-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
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\)

+ 3 - 0
Tests/RunCMake/Syntax/BracketComment1.cmake

@@ -0,0 +1,3 @@
+##[[
+message(FATAL_ERROR "This is not commented out.")
+#]]

+ 1 - 0
Tests/RunCMake/Syntax/BracketComment2-result.txt

@@ -0,0 +1 @@
+1

+ 4 - 0
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\)

+ 3 - 0
Tests/RunCMake/Syntax/BracketComment2.cmake

@@ -0,0 +1,3 @@
+# [[
+message(FATAL_ERROR "This is not commented out.")
+#]]

+ 1 - 0
Tests/RunCMake/Syntax/BracketComment3-stdout.txt

@@ -0,0 +1 @@
+-- The above FATAL_ERROR did not occur.

+ 4 - 0
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.")

+ 1 - 0
Tests/RunCMake/Syntax/BracketComment4-result.txt

@@ -0,0 +1 @@
+1

+ 7 - 0
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

+ 3 - 0
Tests/RunCMake/Syntax/BracketComment4.cmake

@@ -0,0 +1,3 @@
+#[[
+message(FATAL_ERROR "This is commented out.")
+#]] message(STATUS "This command not allowed here")

+ 1 - 0
Tests/RunCMake/Syntax/BracketComment5-stdout.txt

@@ -0,0 +1 @@
+-- The above FATAL_ERROR did not occur.

+ 6 - 0
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.")

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace0-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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.

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace0.cmake

@@ -0,0 +1 @@
+message(STATUS [[bracket]]unquoted)

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace1-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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.

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace1.cmake

@@ -0,0 +1 @@
+message(STATUS "string"[[bracket]])

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace2-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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.

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace2.cmake

@@ -0,0 +1 @@
+message(STATUS "string"#[[bracket comment]][[bracket]])

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace3-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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.

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace3.cmake

@@ -0,0 +1 @@
+message(STATUS "string" #[[bracket comment]][[bracket]])

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace4-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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.

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace4.cmake

@@ -0,0 +1 @@
+message(STATUS "string"#[[bracket comment]]"string")

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace5-result.txt

@@ -0,0 +1 @@
+1

+ 6 - 0
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.

+ 1 - 0
Tests/RunCMake/Syntax/BracketNoSpace5.cmake

@@ -0,0 +1 @@
+message(STATUS "string" #[[bracket comment]]"string")

+ 0 - 35
Tests/RunCMake/Syntax/BracketWarn-stderr.txt

@@ -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.

+ 0 - 1
Tests/RunCMake/Syntax/BracketWarn-stdout.txt

@@ -1 +0,0 @@
--- \[\[\[=\[\[=x\[==\[x

+ 0 - 1
Tests/RunCMake/Syntax/BracketWarn.cmake

@@ -1 +0,0 @@
-message(STATUS [[ [=[ [=x [==[x)

+ 1 - 0
Tests/RunCMake/Syntax/CommandError2-result.txt

@@ -0,0 +1 @@
+1

+ 7 - 0
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

+ 1 - 0
Tests/RunCMake/Syntax/CommandError2.cmake

@@ -0,0 +1 @@
+message("Example Message") [[oops-not-a-comment]]

+ 1 - 0
Tests/RunCMake/Syntax/OneLetter-stderr.txt

@@ -0,0 +1 @@
+message

+ 7 - 0
Tests/RunCMake/Syntax/OneLetter.cmake

@@ -0,0 +1,7 @@
+function(f)
+  g(${ARGN})
+endfunction()
+macro(g)
+  message(${ARGN})
+endmacro()
+f(message)

+ 3 - 0
Tests/RunCMake/Syntax/ParenNoSpace0-stdout.txt

@@ -0,0 +1,3 @@
+-- \(unquoted\)
+-- \(quoted\)
+-- \(bracket\)

+ 3 - 0
Tests/RunCMake/Syntax/ParenNoSpace0.cmake

@@ -0,0 +1,3 @@
+message(STATUS (unquoted))
+message(STATUS ("quoted"))
+message(STATUS ([[bracket]]))

+ 1 - 0
Tests/RunCMake/Syntax/ParenNoSpace1-result.txt

@@ -0,0 +1 @@
+1

+ 22 - 0
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.

+ 3 - 0
Tests/RunCMake/Syntax/ParenNoSpace1.cmake

@@ -0,0 +1,3 @@
+message(STATUS (unquoted)unquoted)
+message(STATUS ("quoted")"quoted")
+message(STATUS ([[bracket]])[[bracket]])

+ 0 - 0
Tests/RunCMake/Syntax/ParenNoSpace-stderr.txt → Tests/RunCMake/Syntax/ParenNoSpace2-stderr.txt


+ 1 - 0
Tests/RunCMake/Syntax/ParenNoSpace-stdout.txt → Tests/RunCMake/Syntax/ParenNoSpace2-stdout.txt

@@ -1,2 +1,3 @@
 -- unquoted\(unquoted\)
 -- quoted\(quoted\)
+-- bracket\(bracket\)

+ 1 - 0
Tests/RunCMake/Syntax/ParenNoSpace.cmake → Tests/RunCMake/Syntax/ParenNoSpace2.cmake

@@ -1,2 +1,3 @@
 message(STATUS unquoted(unquoted))
 message(STATUS "quoted"("quoted"))
+message(STATUS [[bracket]]([[bracket]]))

+ 31 - 2
Tests/RunCMake/Syntax/RunCMakeTest.cmake

@@ -1,18 +1,47 @@
 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)
 run_cmake(CommandComments)
 run_cmake(CommandError0)
 run_cmake(CommandError1)
+run_cmake(CommandError2)
 run_cmake(String0)
 run_cmake(String1)
+run_cmake(StringCRLF)
 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)

+ 1 - 0
Tests/RunCMake/Syntax/StringCRLF-stderr.txt

@@ -0,0 +1 @@
+CRLF->LF worked

+ 6 - 0
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()

+ 1 - 0
Tests/RunCMake/Syntax/UnterminatedBracket0-result.txt

@@ -0,0 +1 @@
+1

+ 8 - 0
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$

+ 1 - 0
Tests/RunCMake/Syntax/UnterminatedBracket0.cmake

@@ -0,0 +1 @@
+set(var [[)

+ 1 - 0
Tests/RunCMake/Syntax/UnterminatedBracket1-result.txt

@@ -0,0 +1 @@
+1

+ 8 - 0
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$

+ 1 - 0
Tests/RunCMake/Syntax/UnterminatedBracket1.cmake

@@ -0,0 +1 @@
+set(var [=[]])

+ 1 - 0
Tests/RunCMake/Syntax/UnterminatedBracketComment-result.txt

@@ -0,0 +1 @@
+1

+ 8 - 0
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

+ 2 - 0
Tests/RunCMake/Syntax/UnterminatedBracketComment.cmake

@@ -0,0 +1,2 @@
+#[=[
+#]]