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)
This commit is contained in:
Brad King 2013-10-21 09:02:00 -04:00 committed by CMake Topic Stage
commit 9fb65d7090
93 changed files with 894 additions and 210 deletions

View File

@ -29,14 +29,14 @@ struct cmListFileParser
~cmListFileParser(); ~cmListFileParser();
bool ParseFile(); bool ParseFile();
bool ParseFunction(const char* name, long line); bool ParseFunction(const char* name, long line);
void AddArgument(cmListFileLexer_Token* token, bool AddArgument(cmListFileLexer_Token* token,
cmListFileArgument::Delimiter delim); cmListFileArgument::Delimiter delim);
cmListFile* ListFile; cmListFile* ListFile;
cmMakefile* Makefile; cmMakefile* Makefile;
const char* FileName; const char* FileName;
cmListFileLexer* Lexer; cmListFileLexer* Lexer;
cmListFileFunction Function; cmListFileFunction Function;
enum { SeparationOkay, SeparationWarning } Separation; enum { SeparationOkay, SeparationWarning, SeparationError} Separation;
}; };
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
@ -57,13 +57,26 @@ cmListFileParser::~cmListFileParser()
bool cmListFileParser::ParseFile() bool cmListFileParser::ParseFile()
{ {
// Open the file. // 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 ", cmSystemTools::Error("cmListFileCache: error can not open file ",
this->FileName); this->FileName);
return false; 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 // Use a simple recursive-descent parser to process the token
// stream. // stream.
bool haveNewline = true; bool haveNewline = true;
@ -77,6 +90,10 @@ bool cmListFileParser::ParseFile()
{ {
haveNewline = true; haveNewline = true;
} }
else if(token->type == cmListFileLexer_Token_CommentBracket)
{
haveNewline = false;
}
else if(token->type == cmListFileLexer_Token_Identifier) else if(token->type == cmListFileLexer_Token_Identifier)
{ {
if(haveNewline) if(haveNewline)
@ -288,7 +305,10 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
{ {
parenDepth++; parenDepth++;
this->Separation = SeparationOkay; this->Separation = SeparationOkay;
this->AddArgument(token, cmListFileArgument::Unquoted); if(!this->AddArgument(token, cmListFileArgument::Unquoted))
{
return false;
}
} }
else if(token->type == cmListFileLexer_Token_ParenRight) else if(token->type == cmListFileLexer_Token_ParenRight)
{ {
@ -298,20 +318,41 @@ bool cmListFileParser::ParseFunction(const char* name, long line)
} }
parenDepth--; parenDepth--;
this->Separation = SeparationOkay; this->Separation = SeparationOkay;
this->AddArgument(token, cmListFileArgument::Unquoted); if(!this->AddArgument(token, cmListFileArgument::Unquoted))
{
return false;
}
this->Separation = SeparationWarning; this->Separation = SeparationWarning;
} }
else if(token->type == cmListFileLexer_Token_Identifier || else if(token->type == cmListFileLexer_Token_Identifier ||
token->type == cmListFileLexer_Token_ArgumentUnquoted) token->type == cmListFileLexer_Token_ArgumentUnquoted)
{ {
this->AddArgument(token, cmListFileArgument::Unquoted); if(!this->AddArgument(token, cmListFileArgument::Unquoted))
{
return false;
}
this->Separation = SeparationWarning; this->Separation = SeparationWarning;
} }
else if(token->type == cmListFileLexer_Token_ArgumentQuoted) else if(token->type == cmListFileLexer_Token_ArgumentQuoted)
{ {
this->AddArgument(token, cmListFileArgument::Quoted); if(!this->AddArgument(token, cmListFileArgument::Quoted))
{
return false;
}
this->Separation = SeparationWarning; 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 else
{ {
// Error. // 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::Delimiter delim)
{ {
cmListFileArgument a(token->text, delim, this->FileName, token->line); cmListFileArgument a(token->text, delim, this->FileName, token->line);
this->Function.Arguments.push_back(a); 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) if(this->Separation == SeparationOkay)
{ {
return; return true;
} }
bool isError = (this->Separation == SeparationError ||
delim == cmListFileArgument::Bracket);
cmOStringStream m; cmOStringStream m;
m << "Syntax Warning in cmake code at\n" m << "Syntax " << (isError? "Error":"Warning") << " in cmake code at\n"
<< " " << this->FileName << ":" << token->line << ":" << " " << this->FileName << ":" << token->line << ":"
<< token->column << "\n" << token->column << "\n"
<< "Argument not separated from preceding token by whitespace."; << "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;
}
} }
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------

View File

@ -28,7 +28,8 @@ struct cmListFileArgument
enum Delimiter enum Delimiter
{ {
Unquoted, Unquoted,
Quoted Quoted,
Bracket
}; };
cmListFileArgument(): Value(), Delim(Unquoted), FilePath(0), Line(0) {} cmListFileArgument(): Value(), Delim(Unquoted), FilePath(0), Line(0) {}
cmListFileArgument(const cmListFileArgument& r): cmListFileArgument(const cmListFileArgument& r):

View File

@ -369,8 +369,8 @@ static void yy_fatal_error (yyconst char msg[] ,yyscan_t yyscanner );
*yy_cp = '\0'; \ *yy_cp = '\0'; \
yyg->yy_c_buf_p = yy_cp; yyg->yy_c_buf_p = yy_cp;
#define YY_NUM_RULES 16 #define YY_NUM_RULES 23
#define YY_END_OF_BUFFER 17 #define YY_END_OF_BUFFER 24
/* This struct is not used in this scanner, /* This struct is not used in this scanner,
but its presence is necessary. */ but its presence is necessary. */
struct yy_trans_info struct yy_trans_info
@ -378,13 +378,16 @@ struct yy_trans_info
flex_int32_t yy_verify; flex_int32_t yy_verify;
flex_int32_t yy_nxt; 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, 0, 17, 6, 14, 1, 8, 2, 0, 0, 0, 0, 0, 0, 0, 0, 4, 4,
6, 3, 4, 6, 15, 9, 11, 12, 13, 6, 24, 13, 21, 1, 15, 3, 13, 5, 6, 7,
0, 6, 0, 14, 2, 0, 5, 6, 9, 0, 22, 22, 16, 18, 19, 20, 10, 11, 8, 12,
10, 0, 7, 0, 0, 0, 7, 0, 7, 0, 9, 4, 13, 0, 13, 0, 21, 0, 0, 7,
0, 0, 0, 0 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] = 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, 1, 2, 1, 5, 6, 7, 1, 1, 1, 8,
9, 1, 1, 1, 1, 1, 1, 10, 10, 10, 9, 1, 1, 1, 1, 1, 1, 10, 10, 10,
10, 10, 10, 10, 10, 10, 10, 1, 1, 1, 10, 10, 10, 10, 10, 10, 10, 1, 1, 1,
1, 1, 1, 1, 11, 11, 11, 11, 11, 11, 11, 1, 1, 1, 12, 12, 12, 12, 12, 12,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
1, 12, 1, 1, 11, 1, 11, 11, 11, 11, 13, 14, 15, 1, 12, 1, 12, 12, 12, 12,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
11, 11, 11, 11, 11, 11, 11, 11, 11, 11, 12, 12, 12, 12, 12, 12, 12, 12, 12, 12,
11, 11, 1, 1, 1, 1, 1, 1, 1, 1, 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, 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 1, 1, 1, 1, 1
} ; } ;
static yyconst flex_int32_t yy_meta[13] = static yyconst flex_int32_t yy_meta[16] =
{ 0, { 0,
1, 2, 3, 2, 4, 1, 1, 1, 5, 5, 1, 1, 2, 3, 4, 3, 1, 3, 5, 6,
5, 1 1, 6, 1, 1, 7
} ; } ;
static yyconst flex_int16_t yy_base[56] = static yyconst flex_int16_t yy_base[95] =
{ 0, { 0,
0, 0, 10, 20, 38, 32, 0, 109, 109, 0, 0, 0, 13, 25, 14, 16, 17, 18, 90, 88,
28, 109, 109, 35, 0, 23, 109, 109, 44, 0, 88, 39, 20, 237, 237, 74, 78, 237, 237, 13,
49, 26, 0, 0, 0, 22, 0, 0, 18, 24, 54, 0, 71, 237, 237, 31, 0, 237, 73, 237,
109, 0, 61, 20, 0, 18, 0, 17, 16, 0, 237, 0, 0, 65, 75, 0, 33, 30, 72, 0,
12, 11, 10, 109, 73, 16, 78, 83, 88, 93, 0, 75, 70, 0, 74, 0, 0, 62, 70, 237,
12, 98, 11, 103, 9 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, { 0,
44, 1, 45, 45, 44, 44, 46, 44, 44, 47, 76, 1, 77, 77, 78, 78, 79, 79, 80, 80,
6, 44, 44, 6, 48, 49, 44, 44, 49, 6, 76, 76, 76, 76, 76, 76, 12, 76, 76, 12,
44, 6, 50, 46, 47, 51, 14, 6, 49, 49, 76, 81, 82, 76, 76, 82, 83, 76, 76, 76,
44, 21, 44, 21, 52, 53, 33, 51, 33, 54, 76, 84, 12, 85, 12, 86, 76, 76, 87, 20,
55, 53, 55, 0, 44, 44, 44, 44, 44, 44, 12, 88, 12, 21, 76, 89, 12, 82, 82, 76,
44, 44, 44, 44, 44 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, { 0,
6, 7, 8, 7, 9, 10, 11, 12, 13, 6, 12, 13, 14, 13, 15, 16, 17, 18, 19, 12,
14, 15, 17, 43, 18, 42, 38, 24, 32, 33, 12, 20, 21, 22, 12, 24, 28, 25, 28, 28,
32, 19, 17, 36, 18, 37, 33, 41, 29, 30, 28, 37, 40, 37, 40, 62, 26, 24, 29, 25,
37, 19, 20, 36, 30, 26, 21, 44, 22, 44, 29, 31, 31, 50, 37, 48, 37, 54, 26, 33,
44, 20, 20, 23, 27, 27, 31, 44, 29, 32, 59, 63, 45, 34, 59, 35, 45, 62, 33, 33,
32, 44, 44, 33, 44, 34, 44, 44, 32, 32, 33, 33, 36, 33, 41, 55, 54, 58, 42, 63,
35, 33, 44, 44, 44, 21, 44, 39, 44, 44, 43, 72, 60, 41, 44, 41, 45, 46, 41, 55,
33, 33, 40, 16, 16, 16, 16, 16, 25, 25, 55, 56, 70, 52, 48, 49, 67, 66, 57, 63,
44, 25, 25, 28, 28, 44, 28, 28, 29, 29, 60, 64, 58, 52, 49, 39, 38, 76, 65, 55,
44, 44, 29, 20, 20, 44, 20, 20, 32, 32, 14, 56, 14, 76, 76, 76, 76, 76, 57, 55,
44, 32, 32, 33, 33, 44, 33, 33, 5, 44, 76, 76, 76, 34, 76, 68, 76, 76, 55, 55,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 69, 55, 54, 76, 54, 76, 54, 54,
44 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, { 0,
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 3, 55, 3, 53, 51, 46, 43, 42, 1, 1, 1, 1, 1, 3, 5, 3, 6, 7,
41, 3, 4, 39, 4, 38, 36, 34, 30, 29, 8, 13, 20, 13, 20, 75, 3, 4, 5, 4,
26, 4, 6, 22, 16, 11, 6, 5, 6, 0, 6, 7, 8, 26, 37, 26, 37, 74, 4, 12,
0, 6, 6, 6, 14, 14, 19, 0, 19, 21, 38, 73, 38, 12, 59, 12, 59, 72, 12, 12,
21, 0, 0, 21, 0, 21, 0, 0, 21, 21, 12, 12, 12, 12, 21, 71, 70, 68, 21, 66,
21, 33, 0, 0, 0, 33, 0, 33, 0, 0, 21, 64, 61, 21, 21, 21, 21, 21, 21, 34,
33, 33, 33, 45, 45, 45, 45, 45, 47, 47, 58, 34, 56, 52, 49, 48, 45, 43, 34, 42,
0, 47, 47, 48, 48, 0, 48, 48, 49, 49, 39, 42, 35, 29, 23, 17, 16, 11, 42, 54,
0, 0, 49, 50, 50, 0, 50, 50, 52, 52, 10, 54, 9, 0, 0, 0, 0, 0, 54, 55,
0, 52, 52, 54, 54, 0, 54, 54, 44, 44, 0, 0, 0, 55, 0, 55, 0, 0, 55, 55,
44, 44, 44, 44, 44, 44, 44, 44, 44, 44, 55, 55, 55, 55, 57, 0, 57, 0, 57, 57,
44 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. */ /* 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, { 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 /* The intent behind this definition is that it'll catch
* any uses of REJECT which flex missed. * any uses of REJECT which flex missed.
@ -538,10 +580,13 @@ Modify cmListFileLexer.c:
struct cmListFileLexer_s struct cmListFileLexer_s
{ {
cmListFileLexer_Token token; cmListFileLexer_Token token;
int bracket;
int comment;
int line; int line;
int column; int column;
int size; int size;
FILE* file; FILE* file;
size_t cr;
char* string_buffer; char* string_buffer;
char* string_position; char* string_position;
int string_left; int string_left;
@ -564,10 +609,16 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer);
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
#line 570 "cmListFileLexer.c"
#line 618 "cmListFileLexer.c"
#define INITIAL 0 #define INITIAL 0
#define STRING 1 #define STRING 1
#define BRACKET 2
#define BRACKETEND 3
#define COMMENT 4
#ifndef YY_NO_UNISTD_H #ifndef YY_NO_UNISTD_H
/* Special case for "unistd.h", since it is non-ANSI. We include it way /* Special case for "unistd.h", since it is non-ANSI. We include it way
@ -793,10 +844,10 @@ YY_DECL
int yy_act; int yy_act;
struct yyguts_t * yyg = (struct yyguts_t*)yyscanner; 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 ) if ( !yyg->yy_init )
{ {
@ -849,13 +900,13 @@ yy_match:
while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[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_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c]; yy_current_state = yy_nxt[yy_base[yy_current_state] + (unsigned int) yy_c];
++yy_cp; ++yy_cp;
} }
while ( yy_base[yy_current_state] != 109 ); while ( yy_base[yy_current_state] != 237 );
yy_find_action: yy_find_action:
yy_act = yy_accept[yy_current_state]; yy_act = yy_accept[yy_current_state];
@ -894,69 +945,168 @@ do_action: /* This label is used only to access EOF actions. */
case 1: case 1:
/* rule 1 can match eol */ /* rule 1 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 84 "cmListFileLexer.in.l" #line 90 "cmListFileLexer.in.l"
{ {
lexer->token.type = cmListFileLexer_Token_Newline; lexer->token.type = cmListFileLexer_Token_Newline;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
++lexer->line; ++lexer->line;
lexer->column = 1; lexer->column = 1;
BEGIN(INITIAL);
return 1; return 1;
} }
case 2: case 2:
/* rule 2 can match eol */
YY_RULE_SETUP 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 YY_BREAK
case 3: case 3:
YY_RULE_SETUP 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; lexer->token.type = cmListFileLexer_Token_ParenLeft;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1; return 1;
} }
case 4: case 6:
YY_RULE_SETUP YY_RULE_SETUP
#line 103 "cmListFileLexer.in.l" #line 141 "cmListFileLexer.in.l"
{ {
lexer->token.type = cmListFileLexer_Token_ParenRight; lexer->token.type = cmListFileLexer_Token_ParenRight;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1; return 1;
} }
case 5: case 7:
YY_RULE_SETUP YY_RULE_SETUP
#line 110 "cmListFileLexer.in.l" #line 148 "cmListFileLexer.in.l"
{ {
lexer->token.type = cmListFileLexer_Token_Identifier; lexer->token.type = cmListFileLexer_Token_Identifier;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1; return 1;
} }
case 6:
YY_RULE_SETUP
#line 117 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng;
return 1;
}
case 7:
YY_RULE_SETUP
#line 124 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng;
return 1;
}
case 8: case 8:
YY_RULE_SETUP YY_RULE_SETUP
#line 131 "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; lexer->token.type = cmListFileLexer_Token_ArgumentQuoted;
cmListFileLexerSetToken(lexer, "", 0); cmListFileLexerSetToken(lexer, "", 0);
@ -964,69 +1114,69 @@ YY_RULE_SETUP
BEGIN(STRING); BEGIN(STRING);
} }
YY_BREAK YY_BREAK
case 9: case 16:
YY_RULE_SETUP YY_RULE_SETUP
#line 138 "cmListFileLexer.in.l" #line 219 "cmListFileLexer.in.l"
{ {
cmListFileLexerAppend(lexer, yytext, yyleng); cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
} }
YY_BREAK YY_BREAK
case 10: case 17:
/* rule 10 can match eol */ /* rule 17 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 143 "cmListFileLexer.in.l" #line 224 "cmListFileLexer.in.l"
{ {
cmListFileLexerAppend(lexer, yytext, yyleng); cmListFileLexerAppend(lexer, yytext, yyleng);
++lexer->line; ++lexer->line;
lexer->column = 1; lexer->column = 1;
} }
YY_BREAK YY_BREAK
case 11: case 18:
/* rule 11 can match eol */ /* rule 18 can match eol */
YY_RULE_SETUP YY_RULE_SETUP
#line 149 "cmListFileLexer.in.l" #line 230 "cmListFileLexer.in.l"
{ {
cmListFileLexerAppend(lexer, yytext, yyleng); cmListFileLexerAppend(lexer, yytext, yyleng);
++lexer->line; ++lexer->line;
lexer->column = 1; lexer->column = 1;
} }
YY_BREAK YY_BREAK
case 12: case 19:
YY_RULE_SETUP YY_RULE_SETUP
#line 155 "cmListFileLexer.in.l" #line 236 "cmListFileLexer.in.l"
{ {
lexer->column += yyleng; lexer->column += yyleng;
BEGIN(INITIAL); BEGIN(INITIAL);
return 1; return 1;
} }
case 13: case 20:
YY_RULE_SETUP YY_RULE_SETUP
#line 161 "cmListFileLexer.in.l" #line 242 "cmListFileLexer.in.l"
{ {
cmListFileLexerAppend(lexer, yytext, yyleng); cmListFileLexerAppend(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
} }
YY_BREAK YY_BREAK
case YY_STATE_EOF(STRING): case YY_STATE_EOF(STRING):
#line 166 "cmListFileLexer.in.l" #line 247 "cmListFileLexer.in.l"
{ {
lexer->token.type = cmListFileLexer_Token_BadString; lexer->token.type = cmListFileLexer_Token_BadString;
BEGIN(INITIAL); BEGIN(INITIAL);
return 1; return 1;
} }
case 14: case 21:
YY_RULE_SETUP YY_RULE_SETUP
#line 172 "cmListFileLexer.in.l" #line 253 "cmListFileLexer.in.l"
{ {
lexer->token.type = cmListFileLexer_Token_Space; lexer->token.type = cmListFileLexer_Token_Space;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1; return 1;
} }
case 15: case 22:
YY_RULE_SETUP YY_RULE_SETUP
#line 179 "cmListFileLexer.in.l" #line 260 "cmListFileLexer.in.l"
{ {
lexer->token.type = cmListFileLexer_Token_BadCharacter; lexer->token.type = cmListFileLexer_Token_BadCharacter;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
@ -1034,18 +1184,19 @@ YY_RULE_SETUP
return 1; return 1;
} }
case YY_STATE_EOF(INITIAL): 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; lexer->token.type = cmListFileLexer_Token_None;
cmListFileLexerSetToken(lexer, 0, 0); cmListFileLexerSetToken(lexer, 0, 0);
return 0; return 0;
} }
case 16: case 23:
YY_RULE_SETUP YY_RULE_SETUP
#line 192 "cmListFileLexer.in.l" #line 273 "cmListFileLexer.in.l"
ECHO; ECHO;
YY_BREAK YY_BREAK
#line 1064 "cmListFileLexer.c" #line 1217 "cmListFileLexer.c"
case YY_END_OF_BUFFER: 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 ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[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_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (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 ) while ( yy_chk[yy_base[yy_current_state] + yy_c] != yy_current_state )
{ {
yy_current_state = (int) yy_def[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_c = yy_meta[(unsigned int) yy_c];
} }
yy_current_state = yy_nxt[yy_base[yy_current_state] + (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; return yy_is_jam ? 0 : yy_current_state;
} }
@ -2166,7 +2317,7 @@ void cmListFileLexer_yyfree (void * ptr , yyscan_t yyscanner)
#define YYTABLES_NAME "yytables" #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) 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) else if(lexer->string_left)
{ {
@ -2307,19 +2489,68 @@ cmListFileLexer* cmListFileLexer_New()
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void cmListFileLexer_Delete(cmListFileLexer* lexer) void cmListFileLexer_Delete(cmListFileLexer* lexer)
{ {
cmListFileLexer_SetFileName(lexer, 0); cmListFileLexer_SetFileName(lexer, 0, 0);
free(lexer); 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; int result = 1;
cmListFileLexerDestroy(lexer); cmListFileLexerDestroy(lexer);
if(name) if(name)
{ {
lexer->file = fopen(name, "r"); lexer->file = fopen(name, "rb");
if(!lexer->file) if(lexer->file)
{
if(bom)
{
*bom = cmListFileLexer_ReadBOM(lexer->file);
}
}
else
{ {
result = 0; result = 0;
} }
@ -2365,7 +2596,7 @@ cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer)
} }
else else
{ {
cmListFileLexer_SetFileName(lexer, 0); cmListFileLexer_SetFileName(lexer, 0, 0);
return 0; return 0;
} }
} }
@ -2411,7 +2642,10 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
case cmListFileLexer_Token_ParenRight: return "right paren"; case cmListFileLexer_Token_ParenRight: return "right paren";
case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument"; case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument";
case cmListFileLexer_Token_ArgumentQuoted: return "quoted 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_BadCharacter: return "bad character";
case cmListFileLexer_Token_BadBracket: return "unterminated bracket";
case cmListFileLexer_Token_BadString: return "unterminated string"; case cmListFileLexer_Token_BadString: return "unterminated string";
} }
return "unknown token"; return "unknown token";

View File

@ -22,7 +22,10 @@ typedef enum cmListFileLexer_Type_e
cmListFileLexer_Token_ParenRight, cmListFileLexer_Token_ParenRight,
cmListFileLexer_Token_ArgumentUnquoted, cmListFileLexer_Token_ArgumentUnquoted,
cmListFileLexer_Token_ArgumentQuoted, cmListFileLexer_Token_ArgumentQuoted,
cmListFileLexer_Token_ArgumentBracket,
cmListFileLexer_Token_CommentBracket,
cmListFileLexer_Token_BadCharacter, cmListFileLexer_Token_BadCharacter,
cmListFileLexer_Token_BadBracket,
cmListFileLexer_Token_BadString cmListFileLexer_Token_BadString
} cmListFileLexer_Type; } cmListFileLexer_Type;
@ -36,6 +39,17 @@ struct cmListFileLexer_Token_s
int column; 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; typedef struct cmListFileLexer_s cmListFileLexer;
#ifdef __cplusplus #ifdef __cplusplus
@ -44,7 +58,8 @@ extern "C"
#endif #endif
cmListFileLexer* cmListFileLexer_New(); cmListFileLexer* cmListFileLexer_New();
int cmListFileLexer_SetFileName(cmListFileLexer*, const char*); int cmListFileLexer_SetFileName(cmListFileLexer*, const char*,
cmListFileLexer_BOM* bom);
int cmListFileLexer_SetString(cmListFileLexer*, const char*); int cmListFileLexer_SetString(cmListFileLexer*, const char*);
cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer*); cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer*);
long cmListFileLexer_GetCurrentLine(cmListFileLexer*); long cmListFileLexer_GetCurrentLine(cmListFileLexer*);

View File

@ -42,10 +42,13 @@ Modify cmListFileLexer.c:
struct cmListFileLexer_s struct cmListFileLexer_s
{ {
cmListFileLexer_Token token; cmListFileLexer_Token token;
int bracket;
int comment;
int line; int line;
int column; int column;
int size; int size;
FILE* file; FILE* file;
size_t cr;
char* string_buffer; char* string_buffer;
char* string_position; char* string_position;
int string_left; int string_left;
@ -74,22 +77,57 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer);
%option noyywrap %option noyywrap
%pointer %pointer
%x STRING %x STRING
%x BRACKET
%x BRACKETEND
%x COMMENT
MAKEVAR \$\([A-Za-z0-9_]*\) MAKEVAR \$\([A-Za-z0-9_]*\)
UNQUOTED ([^ \t\r\n\(\)#\\\"]|\\.) UNQUOTED ([^ \t\r\n\(\)#\\\"[=]|\\.)
LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t])*\" LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t[=])*\"
%% %%
\n { <INITIAL,COMMENT>\n {
lexer->token.type = cmListFileLexer_Token_Newline; lexer->token.type = cmListFileLexer_Token_Newline;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
++lexer->line; ++lexer->line;
lexer->column = 1; lexer->column = 1;
BEGIN(INITIAL);
return 1; 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; lexer->column += yyleng;
} }
@ -107,21 +145,64 @@ LEGACY {MAKEVAR}|{UNQUOTED}|\"({MAKEVAR}|{UNQUOTED}|[ \t])*\"
return 1; return 1;
} }
[A-Za-z_][A-Za-z0-9_]+ { [A-Za-z_][A-Za-z0-9_]* {
lexer->token.type = cmListFileLexer_Token_Identifier; lexer->token.type = cmListFileLexer_Token_Identifier;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1; 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; lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
return 1; return 1;
} }
({MAKEVAR}|{UNQUOTED})({LEGACY})* { ({MAKEVAR}|{UNQUOTED}|=|\[=*{LEGACY})({LEGACY}|[[=])* {
lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted; lexer->token.type = cmListFileLexer_Token_ArgumentUnquoted;
cmListFileLexerSetToken(lexer, yytext, yyleng); cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng; lexer->column += yyleng;
@ -264,7 +345,38 @@ static int cmListFileLexerInput(cmListFileLexer* lexer, char* buffer,
{ {
if(lexer->file) 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) else if(lexer->string_left)
{ {
@ -328,19 +440,68 @@ cmListFileLexer* cmListFileLexer_New()
/*--------------------------------------------------------------------------*/ /*--------------------------------------------------------------------------*/
void cmListFileLexer_Delete(cmListFileLexer* lexer) void cmListFileLexer_Delete(cmListFileLexer* lexer)
{ {
cmListFileLexer_SetFileName(lexer, 0); cmListFileLexer_SetFileName(lexer, 0, 0);
free(lexer); 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; int result = 1;
cmListFileLexerDestroy(lexer); cmListFileLexerDestroy(lexer);
if(name) if(name)
{ {
lexer->file = fopen(name, "r"); lexer->file = fopen(name, "rb");
if(!lexer->file) if(lexer->file)
{
if(bom)
{
*bom = cmListFileLexer_ReadBOM(lexer->file);
}
}
else
{ {
result = 0; result = 0;
} }
@ -386,7 +547,7 @@ cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer* lexer)
} }
else else
{ {
cmListFileLexer_SetFileName(lexer, 0); cmListFileLexer_SetFileName(lexer, 0, 0);
return 0; return 0;
} }
} }
@ -432,7 +593,10 @@ const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
case cmListFileLexer_Token_ParenRight: return "right paren"; case cmListFileLexer_Token_ParenRight: return "right paren";
case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument"; case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument";
case cmListFileLexer_Token_ArgumentQuoted: return "quoted 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_BadCharacter: return "bad character";
case cmListFileLexer_Token_BadBracket: return "unterminated bracket";
case cmListFileLexer_Token_BadString: return "unterminated string"; case cmListFileLexer_Token_BadString: return "unterminated string";
} }
return "unknown token"; return "unknown token";

View File

@ -2867,6 +2867,12 @@ bool cmMakefile::ExpandArguments(
outArgs.reserve(inArgs.size()); outArgs.reserve(inArgs.size());
for(i = inArgs.begin(); i != inArgs.end(); ++i) 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. // Expand the variables in the argument.
value = i->Value; value = i->Value;
this->ExpandVariablesInString(value, false, false, false, this->ExpandVariablesInString(value, false, false, false,

View File

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

View File

@ -0,0 +1 @@
1

View File

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

Binary file not shown.

View File

@ -0,0 +1 @@
1

View File

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

Binary file not shown.

View File

@ -0,0 +1 @@
1

View File

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

Binary file not shown.

View File

@ -0,0 +1 @@
1

View File

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

Binary file not shown.

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,2 @@
message(STATUS [[Bracket Argument 1]] #[[Bracket Comment 1]])
message(STATUS #[[Bracket Comment 2]] [[Bracket Argument 2]])

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

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

View File

@ -0,0 +1,8 @@
if([[
]] STREQUAL "" AND
[[a
b]] STREQUAL "a\nb")
message("CRLF->LF worked")
else()
message(FATAL_ERROR "CRLF->LF failed")
endif()

View File

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

View File

@ -0,0 +1,5 @@
#[=[
#]]
message(FATAL_ERROR "This is commented out.")
#]==]=]
message(STATUS "The above FATAL_ERROR did not occur.")

View File

@ -0,0 +1 @@
1

View File

@ -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\)

View File

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

View File

@ -0,0 +1 @@
1

View File

@ -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\)

View File

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

View File

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

View File

@ -0,0 +1,4 @@
#[[Text on opening line
message(FATAL_ERROR "This is commented out.")
#]=]]
message(STATUS "The above FATAL_ERROR did not occur.")

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
message

View File

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

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

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

View File

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

View File

@ -1,18 +1,47 @@
include(RunCMake) 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(CommandSpaces)
run_cmake(CommandTabs) run_cmake(CommandTabs)
run_cmake(CommandNewlines) run_cmake(CommandNewlines)
run_cmake(CommandComments) run_cmake(CommandComments)
run_cmake(CommandError0) run_cmake(CommandError0)
run_cmake(CommandError1) run_cmake(CommandError1)
run_cmake(CommandError2)
run_cmake(String0) run_cmake(String0)
run_cmake(String1) run_cmake(String1)
run_cmake(StringCRLF)
run_cmake(StringNoSpace) run_cmake(StringNoSpace)
run_cmake(OneLetter)
run_cmake(Unquoted0) run_cmake(Unquoted0)
run_cmake(Unquoted1) 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(UnterminatedCall1)
run_cmake(UnterminatedCall2) run_cmake(UnterminatedCall2)
run_cmake(UnterminatedString) run_cmake(UnterminatedString)
run_cmake(BracketWarn) run_cmake(UnterminatedBracket0)
run_cmake(UnterminatedBracket1)
run_cmake(UnterminatedBracketComment)

View File

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

View File

@ -0,0 +1,6 @@
if("a
b" STREQUAL "a\nb")
message("CRLF->LF worked")
else()
message(FATAL_ERROR "CRLF->LF failed")
endif()

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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

View File

@ -0,0 +1 @@
1

View File

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

View File

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