- Only lex arguments into sub-branches if there is more than one lexeme per
  argument.  Of course, you have to do the lex first, otherwise you don't
  know.
This commit is contained in:
Paul Beckingham 2014-07-03 22:37:05 -04:00
parent 531e490e44
commit 4a063843b1

View file

@ -83,22 +83,33 @@ void Parser::initialize (int argc, const char** argv)
if (! noSpaces (raw))
branch->tag ("QUOTED");
// Lex each argument. If there are multiple lexemes, create sub branches,
// otherwise no change.
std::string lexeme;
Lexer::Type type;
Lexer lex (raw);
lex.ambiguity (false);
std::vector <std::pair <std::string, Lexer::Type> > lexemes;
while (lex.token (lexeme, type))
lexemes.push_back (std::pair <std::string, Lexer::Type> (lexeme, type));
if (lexemes.size () > 1)
{
std::vector <std::pair <std::string, Lexer::Type> >::iterator l;
for (l = lexemes.begin (); l != lexemes.end (); ++l)
{
Tree* sub = branch->addBranch (new Tree ("argSub"));
sub->attribute ("raw", lexeme);
sub->attribute ("raw", l->first);
if (type == Lexer::typeOperator)
if (l->second == Lexer::typeOperator)
sub->tag ("OP");
// TODO More types needed.
}
}
}
}
////////////////////////////////////////////////////////////////////////////////
void Parser::clear ()