A3t::findOperator
- Added support for operator identification. - Extended test script.
This commit is contained in:
@@ -71,6 +71,7 @@ Tree* A3t::parse ()
|
|||||||
findAttributeModifier ();
|
findAttributeModifier ();
|
||||||
findUUIDList (); // Before findIdSequence
|
findUUIDList (); // Before findIdSequence
|
||||||
findIdSequence ();
|
findIdSequence ();
|
||||||
|
findOperator ();
|
||||||
|
|
||||||
validate ();
|
validate ();
|
||||||
|
|
||||||
@@ -611,6 +612,45 @@ void A3t::findUUIDList ()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
void A3t::findOperator ()
|
||||||
|
{
|
||||||
|
// Find the category.
|
||||||
|
std::pair <std::multimap <std::string, std::string>::const_iterator, std::multimap <std::string, std::string>::const_iterator> c;
|
||||||
|
c = _entities.equal_range ("operator");
|
||||||
|
|
||||||
|
// Extract a list of entities for category.
|
||||||
|
std::vector <std::string> options;
|
||||||
|
std::multimap <std::string, std::string>::const_iterator e;
|
||||||
|
for (e = c.first; e != c.second; ++e)
|
||||||
|
options.push_back (e->second);
|
||||||
|
|
||||||
|
std::vector <Tree*>::iterator i;
|
||||||
|
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
|
||||||
|
{
|
||||||
|
// Parser override operator.
|
||||||
|
if ((*i)->attribute ("raw") == "--")
|
||||||
|
break;
|
||||||
|
|
||||||
|
// Skip known args.
|
||||||
|
if (! (*i)->hasTag ("?"))
|
||||||
|
continue;
|
||||||
|
|
||||||
|
std::string raw = (*i)->attribute ("raw");
|
||||||
|
|
||||||
|
std::vector <std::string>::iterator opt;
|
||||||
|
for (opt = options.begin (); opt != options.end (); ++opt)
|
||||||
|
{
|
||||||
|
if (*opt == raw)
|
||||||
|
{
|
||||||
|
(*i)->unTag ("?");
|
||||||
|
(*i)->tag ("OP");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Validate the parse tree.
|
// Validate the parse tree.
|
||||||
void A3t::validate ()
|
void A3t::validate ()
|
||||||
|
|||||||
@@ -53,6 +53,7 @@ private:
|
|||||||
void findAttributeModifier ();
|
void findAttributeModifier ();
|
||||||
void findIdSequence ();
|
void findIdSequence ();
|
||||||
void findUUIDList ();
|
void findUUIDList ();
|
||||||
|
void findOperator ();
|
||||||
void validate ();
|
void validate ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -108,6 +108,29 @@ int main (int argc, char** argv)
|
|||||||
a3t.identity ("modifier", "word");
|
a3t.identity ("modifier", "word");
|
||||||
a3t.identity ("modifier", "noword");
|
a3t.identity ("modifier", "noword");
|
||||||
|
|
||||||
|
// Operators.
|
||||||
|
a3t.identity ("operator", "and");
|
||||||
|
a3t.identity ("operator", "or");
|
||||||
|
a3t.identity ("operator", "xor");
|
||||||
|
a3t.identity ("operator", "<=");
|
||||||
|
a3t.identity ("operator", ">=");
|
||||||
|
a3t.identity ("operator", "!~");
|
||||||
|
a3t.identity ("operator", "!=");
|
||||||
|
a3t.identity ("operator", "=");
|
||||||
|
a3t.identity ("operator", ">");
|
||||||
|
a3t.identity ("operator", "~");
|
||||||
|
a3t.identity ("operator", "!");
|
||||||
|
a3t.identity ("operator", "_hastag_");
|
||||||
|
a3t.identity ("operator", "_notag_");
|
||||||
|
a3t.identity ("operator", "-");
|
||||||
|
a3t.identity ("operator", "*");
|
||||||
|
a3t.identity ("operator", "/");
|
||||||
|
a3t.identity ("operator", "+");
|
||||||
|
a3t.identity ("operator", "-");
|
||||||
|
a3t.identity ("operator", "<");
|
||||||
|
a3t.identity ("operator", "(");
|
||||||
|
a3t.identity ("operator", ")");
|
||||||
|
|
||||||
Tree* tree = a3t.parse ();
|
Tree* tree = a3t.parse ();
|
||||||
if (tree)
|
if (tree)
|
||||||
tree->dump ();
|
tree->dump ();
|
||||||
|
|||||||
Reference in New Issue
Block a user