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