- Converted ::findAttributeModifier to use the recursive scanner.
This commit is contained in:
Paul Beckingham 2014-08-17 00:49:20 -04:00
parent 24c2c0cbee
commit 3a8d42dae7
2 changed files with 150 additions and 159 deletions

View file

@ -182,7 +182,7 @@ Tree* Parser::parse ()
findPattern ();
findTag ();
findAttribute ();
findAttributeModifier ();
scan (&Parser::findAttributeModifier);
findOperator ();
findCommand ();
findUUIDList ();
@ -998,20 +998,12 @@ void Parser::findAttribute ()
////////////////////////////////////////////////////////////////////////////////
// <name>.<mod>[:=]['"]<value>['"]
void Parser::findAttributeModifier ()
void Parser::findAttributeModifier (Tree* t)
{
std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
break;
context.debug ("findAttributeModifier");
context.debug (t->dump ());
// Skip known args.
if (! (*i)->hasTag ("?"))
continue;
std::string raw = (*i)->attribute ("raw");
std::string raw = t->attribute ("raw");
Nibbler n (raw);
std::string name;
@ -1042,114 +1034,114 @@ void Parser::findAttributeModifier ()
if (value == "")
value = "''";
(*i)->unTag ("?");
(*i)->removeAllBranches ();
(*i)->tag ("ATTMOD");
(*i)->attribute ("name", canonical);
(*i)->attribute ("raw", value);
(*i)->attribute ("modifier", modifier);
(*i)->attribute ("sense", sense);
t->unTag ("?");
t->removeAllBranches ();
t->tag ("ATTMOD");
t->attribute ("name", canonical);
t->attribute ("raw", value);
t->attribute ("modifier", modifier);
t->attribute ("sense", sense);
Tree* branch = (*i)->addBranch (new Tree ("argAttmod"));
Tree* branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", canonical);
if (modifier == "before" || modifier == "under" || modifier == "below")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "<");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", value);
}
else if (modifier == "after" || modifier == "over" || modifier == "above")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", ">");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", value);
}
else if (modifier == "none")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "==");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "''");
}
else if (modifier == "any")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "!=");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "''");
}
else if (modifier == "is" || modifier == "equals")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "==");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", value);
}
else if (modifier == "isnt" || modifier == "not")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "!=");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", value);
}
else if (modifier == "has" || modifier == "contains")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", value);
}
else if (modifier == "hasnt")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "!~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", value);
}
else if (modifier == "startswith" || modifier == "left")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "'^" + value + "'");
}
else if (modifier == "endswith" || modifier == "right")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "'" + value + "$'");
}
else if (modifier == "word")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
#if defined (DARWIN)
branch->attribute ("raw", value);
@ -1161,11 +1153,11 @@ void Parser::findAttributeModifier ()
}
else if (modifier == "noword")
{
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
branch->attribute ("raw", "!~");
branch->tag ("OP");
branch = (*i)->addBranch (new Tree ("argAttmod"));
branch = t->addBranch (new Tree ("argAttmod"));
#if defined (DARWIN)
branch->attribute ("raw", value);
@ -1183,8 +1175,7 @@ void Parser::findAttributeModifier ()
if (col != context.columns.end () &&
col->second->modifiable ())
{
(*i)->tag ("MODIFIABLE");
}
t->tag ("MODIFIABLE");
}
}
}

View file

@ -74,7 +74,7 @@ private:
void findSubstitution ();
void findTag ();
void findAttribute ();
void findAttributeModifier ();
void findAttributeModifier (Tree*);
void findOperator ();
void findFilter ();
void findModifications ();