ENH/BUG: Improved function parsing to allow just about anything inside a double-quoted argument. Also fixed parsing of lines with both quoted and non-quoted arguments.

This commit is contained in:
Brad King 2001-02-27 15:41:21 -05:00
parent 5c74b6b90d
commit 41d198ed40

View File

@ -198,10 +198,10 @@ bool cmSystemTools::ParseFunction(std::ifstream& fin,
if(fin.getline(inbuffer, BUFFER_SIZE ) ) if(fin.getline(inbuffer, BUFFER_SIZE ) )
{ {
cmRegularExpression blankLine("^$"); cmRegularExpression blankLine("^$");
cmRegularExpression comment("^#.*"); cmRegularExpression comment("^#.*$");
cmRegularExpression oneLiner("[ \t]*([A-Za-z_0-9]*).*\\((.*)\\)"); cmRegularExpression oneLiner("^[ \t]*([A-Za-z_0-9]*)[ \t]*\\((.*)\\)[ \t]*$");
cmRegularExpression multiLine("[ \t]*([A-Za-z_0-9]*).*\\((.*)"); cmRegularExpression multiLine("^[ \t]*([A-Za-z_0-9]*)[ \t]*\\((.*)$");
cmRegularExpression lastLine("(.*)\\)"); cmRegularExpression lastLine("^(.*)\\)[ \t]*$");
// BEGIN VERBATIM JUNK SHOULD BE REMOVED // BEGIN VERBATIM JUNK SHOULD BE REMOVED
cmRegularExpression verbatim("BEGIN MAKE VERBATIM"); cmRegularExpression verbatim("BEGIN MAKE VERBATIM");
@ -294,25 +294,52 @@ bool cmSystemTools::ParseFunction(std::ifstream& fin,
void cmSystemTools::GetArguments(std::string& line, void cmSystemTools::GetArguments(std::string& line,
std::vector<std::string>& arguments) std::vector<std::string>& arguments)
{ {
cmRegularExpression argument("[\t ]*([-/\\.\\\\{}\\$A-Za-z_0-9]+)[\t ]*"); // Match a normal argument (not quoted, no spaces).
cmRegularExpression argumentWithSpaces("[\t ]*\"([-\\. /\\\\{}\\$A-Za-z_0-9]+)\"[\t ]*"); cmRegularExpression normalArgument("[\t ]*([^\" \t]+)[\t ]*");
std::string arg(" "); // Match a quoted argument (surrounded by double quotes, spaces allowed).
while(arg.length() ) cmRegularExpression quotedArgument("[\t ]*(\"[^\"]*\")[\t ]*");
{
arg = "";
long endpos;
if (argumentWithSpaces.find(line.c_str())) bool done = false;
while(!done)
{
std::string arg;
long endpos;
bool foundQuoted = quotedArgument.find(line.c_str());
bool foundNormal = normalArgument.find(line.c_str());
if(foundQuoted && foundNormal)
{ {
arg = argumentWithSpaces.match(1); // Both matches were found. Take the earlier one.
endpos = argumentWithSpaces.end(1); if(normalArgument.start(1) < quotedArgument.start(1))
} {
else if(argument.find(line.c_str())) arg = normalArgument.match(1);
endpos = normalArgument.end(1);
}
else
{
arg = quotedArgument.match(1);
endpos = quotedArgument.end(1);
// Strip off the double quotes on the ends.
arg = arg.substr(1, arg.length()-2);
}
}
else if (foundQuoted)
{ {
arg = argument.match(1); arg = quotedArgument.match(1);
endpos = argument.end(1); endpos = quotedArgument.end(1);
// Strip off the double quotes on the ends.
arg = arg.substr(1, arg.length()-2);
} }
if(arg.length()) else if(foundNormal)
{
arg = normalArgument.match(1);
endpos = normalArgument.end(1);
}
else
{
done = true;
}
if(!done)
{ {
arguments.push_back(arg); arguments.push_back(arg);
line = line.substr(endpos, line.length() - endpos); line = line.substr(endpos, line.length() - endpos);