summaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2004-08-31 22:39:42 (GMT)
committerBrad King <brad.king@kitware.com>2004-08-31 22:39:42 (GMT)
commit486a26d3db24cf2569310b4b2dad32667cbbcaa1 (patch)
tree323e4da91a75b65df7edb6efa495fead998e0f82 /Source
parent491bebefa2f6da9221c5d40ce1c4d3ff2da1c401 (diff)
downloadCMake-486a26d3db24cf2569310b4b2dad32667cbbcaa1.zip
CMake-486a26d3db24cf2569310b4b2dad32667cbbcaa1.tar.gz
CMake-486a26d3db24cf2569310b4b2dad32667cbbcaa1.tar.bz2
BUG#1049: Added error message when file ends in an unterminated string.
Diffstat (limited to 'Source')
-rw-r--r--Source/cmListFileCache.cxx18
-rw-r--r--Source/cmListFileLexer.c45
-rw-r--r--Source/cmListFileLexer.h5
-rw-r--r--Source/cmListFileLexer.in.l28
4 files changed, 78 insertions, 18 deletions
diff --git a/Source/cmListFileCache.cxx b/Source/cmListFileCache.cxx
index 092d73b..442cd6d 100644
--- a/Source/cmListFileCache.cxx
+++ b/Source/cmListFileCache.cxx
@@ -144,8 +144,9 @@ bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
cmOStringStream error;
error << "Error in cmake code at\n"
<< filename << ":" << token->line << ":\n"
- << "Parse error. Expected a newline, got \""
- << token->text << "\".";
+ << "Parse error. Expected a newline, got "
+ << cmListFileLexer_GetTypeAsString(lexer, token->type)
+ << " with text \"" << token->text << "\".";
cmSystemTools::Error(error.str().c_str());
parseError = true;
}
@@ -155,7 +156,9 @@ bool cmListFileCache::CacheFile(const char* path, bool requireProjectCommand)
cmOStringStream error;
error << "Error in cmake code at\n"
<< filename << ":" << token->line << ":\n"
- << "Parse error. Expected a command name, got \""
+ << "Parse error. Expected a command name, got "
+ << cmListFileLexer_GetTypeAsString(lexer, token->type)
+ << " with text \""
<< token->text << "\".";
cmSystemTools::Error(error.str().c_str());
parseError = true;
@@ -226,8 +229,9 @@ bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
cmOStringStream error;
error << "Error in cmake code at\n"
<< filename << ":" << cmListFileLexer_GetCurrentLine(lexer) << ":\n"
- << "Parse error. Expected \"(\", got \""
- << token->text << "\".";
+ << "Parse error. Expected \"(\", got "
+ << cmListFileLexer_GetTypeAsString(lexer, token->type)
+ << " with text \"" << token->text << "\".";
cmSystemTools::Error(error.str().c_str());
return false;
}
@@ -259,7 +263,9 @@ bool cmListFileCacheParseFunction(cmListFileLexer* lexer,
error << "Error in cmake code at\n"
<< filename << ":" << cmListFileLexer_GetCurrentLine(lexer) << ":\n"
<< "Parse error. Function missing ending \")\". "
- << "Instead found \"" << token->text << "\".";
+ << "Instead found "
+ << cmListFileLexer_GetTypeAsString(lexer, token->type)
+ << " with text \"" << token->text << "\".";
cmSystemTools::Error(error.str().c_str());
return false;
}
diff --git a/Source/cmListFileLexer.c b/Source/cmListFileLexer.c
index f255541..dfb735d 100644
--- a/Source/cmListFileLexer.c
+++ b/Source/cmListFileLexer.c
@@ -192,8 +192,6 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE;
} \
while ( 0 )
-#define unput(c) yyunput( c, yyg->yytext_ptr , yyscanner )
-
/* The following is because we cannot portably get our hands on size_t
* (without autoconf's help, which isn't available because we want
* flex-generated scanners to compile on their own).
@@ -962,25 +960,31 @@ YY_RULE_SETUP
lexer->column += yyleng;
}
YY_BREAK
+case YY_STATE_EOF(STRING):
+#line 168 "cmListFileLexer.in.l"
+{
+ lexer->token.type = cmListFileLexer_Token_BadString;
+ BEGIN(INITIAL);
+ return 1;
+}
case 12:
YY_RULE_SETUP
-#line 168 "cmListFileLexer.in.l"
+#line 174 "cmListFileLexer.in.l"
{
lexer->column += yyleng;
}
YY_BREAK
case 13:
YY_RULE_SETUP
-#line 172 "cmListFileLexer.in.l"
+#line 178 "cmListFileLexer.in.l"
{
- lexer->token.type = cmListFileLexer_Token_Error;
+ lexer->token.type = cmListFileLexer_Token_BadCharacter;
cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng;
return 1;
}
case YY_STATE_EOF(INITIAL):
-case YY_STATE_EOF(STRING):
-#line 179 "cmListFileLexer.in.l"
+#line 185 "cmListFileLexer.in.l"
{
lexer->token.type = cmListFileLexer_Token_None;
cmListFileLexerSetToken(lexer, 0, 0);
@@ -988,10 +992,10 @@ case YY_STATE_EOF(STRING):
}
case 14:
YY_RULE_SETUP
-#line 185 "cmListFileLexer.in.l"
+#line 191 "cmListFileLexer.in.l"
ECHO;
YY_BREAK
-#line 1005 "cmListFileLexer.c"
+#line 1012 "cmListFileLexer.c"
case YY_END_OF_BUFFER:
{
@@ -2075,7 +2079,7 @@ void yyfree (void * ptr , yyscan_t yyscanner)
#undef YY_DECL_IS_OURS
#undef YY_DECL
#endif
-#line 185 "cmListFileLexer.in.l"
+#line 191 "cmListFileLexer.in.l"
@@ -2303,3 +2307,24 @@ long cmListFileLexer_GetCurrentColumn(cmListFileLexer* lexer)
return 0;
}
}
+
+/*--------------------------------------------------------------------------*/
+const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
+ cmListFileLexer_Type type)
+{
+ (void)lexer;
+ switch(type)
+ {
+ case cmListFileLexer_Token_None: return "nothing";
+ case cmListFileLexer_Token_Newline: return "newline";
+ case cmListFileLexer_Token_Identifier: return "identifier";
+ case cmListFileLexer_Token_ParenLeft: return "left paren";
+ case cmListFileLexer_Token_ParenRight: return "right paren";
+ case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument";
+ case cmListFileLexer_Token_ArgumentQuoted: return "quoted argument";
+ case cmListFileLexer_Token_BadCharacter: return "bad character";
+ case cmListFileLexer_Token_BadString: return "unterminated string";
+ }
+ return "unknown token";
+}
+
diff --git a/Source/cmListFileLexer.h b/Source/cmListFileLexer.h
index f40866a..8e32244 100644
--- a/Source/cmListFileLexer.h
+++ b/Source/cmListFileLexer.h
@@ -26,7 +26,8 @@ typedef enum cmListFileLexer_Type_e
cmListFileLexer_Token_ParenRight,
cmListFileLexer_Token_ArgumentUnquoted,
cmListFileLexer_Token_ArgumentQuoted,
- cmListFileLexer_Token_Error
+ cmListFileLexer_Token_BadCharacter,
+ cmListFileLexer_Token_BadString
} cmListFileLexer_Type;
typedef struct cmListFileLexer_Token_s cmListFileLexer_Token;
@@ -52,6 +53,8 @@ int cmListFileLexer_SetString(cmListFileLexer*, const char*);
cmListFileLexer_Token* cmListFileLexer_Scan(cmListFileLexer*);
long cmListFileLexer_GetCurrentLine(cmListFileLexer*);
long cmListFileLexer_GetCurrentColumn(cmListFileLexer*);
+const char* cmListFileLexer_GetTypeAsString(cmListFileLexer*,
+ cmListFileLexer_Type);
void cmListFileLexer_Delete(cmListFileLexer*);
#ifdef __cplusplus
diff --git a/Source/cmListFileLexer.in.l b/Source/cmListFileLexer.in.l
index 5c86c92..e99bc03 100644
--- a/Source/cmListFileLexer.in.l
+++ b/Source/cmListFileLexer.in.l
@@ -165,12 +165,18 @@ static void cmListFileLexerDestroy(cmListFileLexer* lexer);
lexer->column += yyleng;
}
+<STRING><<EOF>> {
+ lexer->token.type = cmListFileLexer_Token_BadString;
+ BEGIN(INITIAL);
+ return 1;
+}
+
[ \t\r] {
lexer->column += yyleng;
}
. {
- lexer->token.type = cmListFileLexer_Token_Error;
+ lexer->token.type = cmListFileLexer_Token_BadCharacter;
cmListFileLexerSetToken(lexer, yytext, yyleng);
lexer->column += yyleng;
return 1;
@@ -408,3 +414,23 @@ long cmListFileLexer_GetCurrentColumn(cmListFileLexer* lexer)
return 0;
}
}
+
+/*--------------------------------------------------------------------------*/
+const char* cmListFileLexer_GetTypeAsString(cmListFileLexer* lexer,
+ cmListFileLexer_Type type)
+{
+ (void)lexer;
+ switch(type)
+ {
+ case cmListFileLexer_Token_None: return "nothing";
+ case cmListFileLexer_Token_Newline: return "newline";
+ case cmListFileLexer_Token_Identifier: return "identifier";
+ case cmListFileLexer_Token_ParenLeft: return "left paren";
+ case cmListFileLexer_Token_ParenRight: return "right paren";
+ case cmListFileLexer_Token_ArgumentUnquoted: return "unquoted argument";
+ case cmListFileLexer_Token_ArgumentQuoted: return "quoted argument";
+ case cmListFileLexer_Token_BadCharacter: return "bad character";
+ case cmListFileLexer_Token_BadString: return "unterminated string";
+ }
+ return "unknown token";
+}