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

View File

@ -26,6 +26,8 @@ int cmCommandArgument_yyparse( yyscan_t yyscanner );
cmCommandArgumentParserHelper::cmCommandArgumentParserHelper()
{
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)
{
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;
ostr << m_FileLine;
return this->AddString(ostr.str().c_str());
}
const char* value = m_Makefile->GetDefinition(var);
if (m_EscapeQuotes)
{
return this->AddString(cmSystemTools::EscapeQuotes(value).c_str());
}
return this->AddString(value);
}
@ -228,7 +234,8 @@ int cmCommandArgumentParserHelper::ParseString(const char* str, int verb)
cmCommandArgument_yylex_destroy(yyscanner);
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;
}
@ -289,7 +296,7 @@ int cmCommandArgumentParserHelper::LexInput(char* buf, int maxlen)
void cmCommandArgumentParserHelper::Error(const char* str)
{
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;
std::cerr << "String: [";
for ( cc = 0; cc < 30 && *(this->InputBuffer.c_str() + this->InputBufferPos + cc);
@ -345,6 +352,7 @@ void cmCommandArgumentParserHelper::SetResult(const char* value)
{
if ( !value )
{
m_Result = "";
return;
}
m_Result = value;

View File

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