ENH: Handle more cases

This commit is contained in:
Andy Cedilnik 2005-06-08 14:18:31 -04:00
parent 859b517518
commit bbf1c3a0e8
4 changed files with 80 additions and 19 deletions

View File

@ -85,31 +85,61 @@ Modify cmCommandArgumentLexer.h:
%% %%
"$[A-Za-z0-9_]+{" { \$[A-Za-z0-9_]+\{ {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2); yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
return cal_NCURLY; return cal_NCURLY;
} }
@[A-Za-z0-9_]+@ {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext+1, strlen(yytext)-2);
return cal_ATNAME;
}
"${" { "${" {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return cal_DCURLY; return cal_DCURLY;
} }
"}" { "}" {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return cal_RCURLY; return cal_RCURLY;
} }
"@" { "@" {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return cal_AT; return cal_AT;
} }
[A-Za-z0-9_]+ { [A-Za-z0-9_]+ {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return cal_NAME; return cal_NAME;
} }
([^A-Za-z0-9_$}\\@]+|\.) { [^A-Za-z0-9_${}\\@]+|\\. {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext)); yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return cal_SYMBOL; return cal_SYMBOL;
} }
"$" {
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return cal_DOLLAR;
}
"{" {
yyextra->AllocateParserType(yylvalp, yytext, strlen(yytext));
return cal_LCURLY;
}
.|\n {
//std::cerr << __LINE__ << " here: [" << yytext << "]" << std::endl;
return cal_ERROR;
}
%% %%

View File

@ -49,7 +49,7 @@ YY_DECL;
static void cmCommandArgumentError(yyscan_t yyscanner, const char* message); static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
#define YYDEBUG 1 #define YYDEBUG 1
#define YYMAXDEPTH 1000000 #define YYMAXDEPTH 10000000
#define calCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp); #define calCheckEmpty(cnt) yyGetParser->CheckEmpty(__LINE__, cnt, yyvsp);
@ -77,11 +77,14 @@ static void cmCommandArgumentError(yyscan_t yyscanner, const char* message);
/* Tokens */ /* Tokens */
%token cal_NCURLY %token cal_NCURLY
%token cal_DCURLY %token cal_DCURLY
%token cal_DOLLAR
%token cal_LCURLY
%token cal_RCURLY %token cal_RCURLY
%token cal_NAME %token cal_NAME
%token cal_SYMBOL %token cal_SYMBOL
%token cal_AT %token cal_AT
%token cal_ERROR %token cal_ERROR
%token cal_ATNAME
/*-------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------*/
/* grammar */ /* grammar */
@ -98,11 +101,10 @@ Goal
} }
Goal: Goal:
String
{ {
calElementStart(1); calElementStart(0);
calCheckEmpty(1); calCheckEmpty(0);
$<str>$ = $<str>1; $<str>$ = 0;
} }
| |
String Goal String Goal
@ -178,6 +180,27 @@ Text
$<str>$ = $<str>1; $<str>$ = $<str>1;
} }
| |
cal_AT
{
calElementStart(1);
calCheckEmpty(1);
$<str>$ = $<str>1;
}
|
cal_DOLLAR
{
calElementStart(1);
calCheckEmpty(1);
$<str>$ = $<str>1;
}
|
cal_LCURLY
{
calElementStart(1);
calCheckEmpty(1);
$<str>$ = $<str>1;
}
|
cal_RCURLY cal_RCURLY
{ {
calElementStart(1); calElementStart(1);
@ -191,7 +214,7 @@ cal_NCURLY MultipleIds cal_RCURLY
calElementStart(3); calElementStart(3);
calCheckEmpty(3); calCheckEmpty(3);
$<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2); $<str>$ = yyGetParser->ExpandSpecialVariable($<str>1,$<str>2);
std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl; //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
} }
| |
cal_DCURLY MultipleIds cal_RCURLY cal_DCURLY MultipleIds cal_RCURLY
@ -199,14 +222,14 @@ cal_DCURLY MultipleIds cal_RCURLY
calElementStart(3); calElementStart(3);
calCheckEmpty(3); calCheckEmpty(3);
$<str>$ = yyGetParser->ExpandVariable($<str>2); $<str>$ = yyGetParser->ExpandVariable($<str>2);
std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl; //std::cerr << __LINE__ << " here: [" << $<str>1 << "] [" << $<str>2 << "] [" << $<str>3 << "]" << std::endl;
} }
| |
cal_AT cal_NAME cal_AT cal_ATNAME
{ {
calElementStart(3); calElementStart(1);
calCheckEmpty(3); calCheckEmpty(1);
$<str>$ = yyGetParser->ExpandVariable($<str>2); $<str>$ = yyGetParser->ExpandVariable($<str>1);
} }
%% %%

View File

@ -26,6 +26,8 @@ int cmCommandArgument_yyparse( yyscan_t yyscanner );
cmCommandArgumentParserHelper::cmCommandArgumentParserHelper() cmCommandArgumentParserHelper::cmCommandArgumentParserHelper()
{ {
m_FileLine = -1; m_FileLine = -1;
m_FileName = 0;
m_EmptyVariable[0] = 0;
} }
@ -79,17 +81,21 @@ char* cmCommandArgumentParserHelper::ExpandSpecialVariable(const char* key, cons
char* cmCommandArgumentParserHelper::ExpandVariable(const char* var) char* cmCommandArgumentParserHelper::ExpandVariable(const char* var)
{ {
if(var == "CMAKE_CURRENT_LIST_FILE") if(m_FileName && strcmp(var, "CMAKE_CURRENT_LIST_FILE") == 0)
{ {
return this->AddString(m_FileName.c_str()); return this->AddString(m_FileName);
} }
else if(m_FileLine >= 0 && (var == "CMAKE_CURRENT_LIST_LINE")) else if(m_FileLine >= 0 && strcmp(var, "CMAKE_CURRENT_LIST_LINE") == 0)
{ {
cmOStringStream ostr; cmOStringStream ostr;
ostr << m_FileLine; ostr << m_FileLine;
return this->AddString(ostr.str().c_str()); return this->AddString(ostr.str().c_str());
} }
const char* value = m_Makefile->GetDefinition(var); const char* value = m_Makefile->GetDefinition(var);
if (m_EscapeQuotes)
{
return this->AddString(cmSystemTools::EscapeQuotes(value).c_str());
}
return this->AddString(value); return this->AddString(value);
} }
@ -228,7 +234,8 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
cmCommandArgument_yylex_destroy(yyscanner); cmCommandArgument_yylex_destroy(yyscanner);
if ( res != 0 ) if ( res != 0 )
{ {
std::cout << "JP_Parse returned: " << res << std::endl; std::cerr << "CAL_Parser returned: " << res << std::endl;
std::cerr << "When parsing: [" << str << "]" << std::endl;
return 0; return 0;
} }
@ -289,7 +296,7 @@ int cmCommandArgumentParserHelper::LexInput(char* buf, int maxlen)
void cmCommandArgumentParserHelper::Error(const char* str) void cmCommandArgumentParserHelper::Error(const char* str)
{ {
unsigned long pos = static_cast<unsigned long>(this->InputBufferPos); unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
fprintf(stderr, "JPError: %s (%lu / Line: %d)\n", str, pos, this->CurrentLine); fprintf(stderr, "Argument Parser Error: %s (%lu / Line: %d)\n", str, pos, this->CurrentLine);
int cc; int cc;
std::cerr << "String: ["; std::cerr << "String: [";
for ( cc = 0; cc < 30 && *(this->InputBuffer.c_str() + this->InputBufferPos + cc); for ( cc = 0; cc < 30 && *(this->InputBuffer.c_str() + this->InputBufferPos + cc);
@ -345,6 +352,7 @@ void cmCommandArgumentParserHelper::SetResult(const char* value)
{ {
if ( !value ) if ( !value )
{ {
m_Result = "";
return; return;
} }
m_Result = value; m_Result = value;

View File

@ -101,7 +101,7 @@ private:
char m_EmptyVariable[1]; char m_EmptyVariable[1];
const cmMakefile* m_Makefile; const cmMakefile* m_Makefile;
std::string m_Result; std::string m_Result;
std::string m_FileName; const char* m_FileName;
long m_FileLine; long m_FileLine;
bool m_EscapeQuotes; bool m_EscapeQuotes;