BUG#1049: Added error message when file ends in an unterminated string.

This commit is contained in:
Brad King 2004-08-31 18:39:42 -04:00
parent 491bebefa2
commit 486a26d3db
4 changed files with 78 additions and 18 deletions

View File

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

View File

@ -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";
}

View File

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

View File

@ -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";
}