mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
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.
This commit is contained in:
parent
531e490e44
commit
4a063843b1
1 changed files with 16 additions and 5 deletions
|
@ -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.
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue