From 4a063843b13c3f673362ac61b769e28222830034 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Thu, 3 Jul 2014 22:37:05 -0400 Subject: [PATCH] Parser - 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. --- src/Parser.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/Parser.cpp b/src/Parser.cpp index fd9b9b7dd..fbc34f645 100644 --- a/src/Parser.cpp +++ b/src/Parser.cpp @@ -83,19 +83,30 @@ 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 > lexemes; while (lex.token (lexeme, type)) + lexemes.push_back (std::pair (lexeme, type)); + + if (lexemes.size () > 1) { - Tree* sub = branch->addBranch (new Tree ("argSub")); - sub->attribute ("raw", lexeme); + std::vector >::iterator l; + for (l = lexemes.begin (); l != lexemes.end (); ++l) + { + Tree* sub = branch->addBranch (new Tree ("argSub")); + sub->attribute ("raw", l->first); - if (type == Lexer::typeOperator) - sub->tag ("OP"); + if (l->second == Lexer::typeOperator) + sub->tag ("OP"); - // TODO More types needed. + // TODO More types needed. + } } } }