- ::unsweetenAttributeModifiers no longer clobbers non-FILTER args.
This commit is contained in:
Paul Beckingham 2014-10-19 18:19:09 -04:00
parent 720cc57192
commit f809f2d819

View file

@ -641,162 +641,164 @@ void CLI::unsweetenAttributeModifiers ()
std::vector <A>::iterator a; std::vector <A>::iterator a;
for (a = _args.begin (); a != _args.end (); ++a) for (a = _args.begin (); a != _args.end (); ++a)
{ {
// Look for a valid attribute name. if (a->hasTag ("FILTER"))
bool found = false;
Nibbler n (a->attribute ("raw"));
std::string name;
if (n.getUntil (".", name) &&
name.length ())
{ {
std::string canonical; // Look for a valid attribute name.
if (canonicalize (canonical, "attribute", name) || bool found = false;
canonicalize (canonical, "uda", name)) Nibbler n (a->attribute ("raw"));
std::string name;
if (n.getUntil (".", name) &&
name.length ())
{ {
if (n.skip ('.')) std::string canonical;
if (canonicalize (canonical, "attribute", name) ||
canonicalize (canonical, "uda", name))
{ {
std::string sense = "+"; if (n.skip ('.'))
if (n.skip ('~'))
sense = "-";
std::string modifier;
n.getUntilOneOf (":=", modifier);
if (n.skip (':') ||
n.skip ('='))
{ {
std::string value; std::string sense = "+";
if (n.getQuoted ('"', value) || if (n.skip ('~'))
n.getQuoted ('\'', value) || sense = "-";
n.getUntilEOS (value) ||
n.depleted ()) std::string modifier;
n.getUntilOneOf (":=", modifier);
if (n.skip (':') ||
n.skip ('='))
{ {
if (value == "") std::string value;
value = "''"; if (n.getQuoted ('"', value) ||
n.getQuoted ('\'', value) ||
n.getUntilEOS (value) ||
n.depleted ())
{
if (value == "")
value = "''";
A lhs ("argAttMod", name); A lhs ("argAttMod", name);
lhs.tag ("ATTMOD"); lhs.tag ("ATTMOD");
lhs.tag ("FILTER"); lhs.tag ("FILTER");
lhs.attribute ("name", canonical); lhs.attribute ("name", canonical);
lhs.attribute ("raw", value); lhs.attribute ("raw", value);
lhs.attribute ("modifier", modifier); lhs.attribute ("modifier", modifier);
lhs.attribute ("sense", sense); lhs.attribute ("sense", sense);
std::map <std::string, Column*>::const_iterator col; std::map <std::string, Column*>::const_iterator col;
col = context.columns.find (canonical); col = context.columns.find (canonical);
if (col != context.columns.end () && if (col != context.columns.end () &&
col->second->modifiable ()) col->second->modifiable ())
{ {
lhs.tag ("MODIFIABLE"); lhs.tag ("MODIFIABLE");
} }
A op ("argAttmod", ""); A op ("argAttmod", "");
op.tag ("FILTER"); op.tag ("FILTER");
A rhs ("argAttMod", "");
rhs.tag ("FILTER");
if (modifier == "before" || modifier == "under" || modifier == "below")
{
op.attribute ("raw", "<");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "after" || modifier == "over" || modifier == "above")
{
op.attribute ("raw", ">");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "none")
{
op.attribute ("raw", "==");
op.tag ("OP");
rhs.attribute ("raw", "''");
}
else if (modifier == "any")
{
op.attribute ("raw", "!=");
op.tag ("OP");
rhs.attribute ("raw", "''");
}
else if (modifier == "is" || modifier == "equals")
{
op.attribute ("raw", "==");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "isnt" || modifier == "not")
{
op.attribute ("raw", "!=");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "has" || modifier == "contains")
{
op.attribute ("raw", "~");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "hasnt")
{
op.attribute ("raw", "!~");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "startswith" || modifier == "left")
{
op.attribute ("raw", "~");
op.tag ("OP");
rhs.attribute ("raw", "'^" + value + "'");
}
else if (modifier == "endswith" || modifier == "right")
{
op.attribute ("raw", "~");
op.tag ("OP");
rhs.attribute ("raw", "'" + value + "$'");
}
else if (modifier == "word")
{
op.attribute ("raw", "~");
op.tag ("OP");
A rhs ("argAttMod", "");
rhs.tag ("FILTER");
if (modifier == "before" || modifier == "under" || modifier == "below")
{
op.attribute ("raw", "<");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "after" || modifier == "over" || modifier == "above")
{
op.attribute ("raw", ">");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "none")
{
op.attribute ("raw", "==");
op.tag ("OP");
rhs.attribute ("raw", "''");
}
else if (modifier == "any")
{
op.attribute ("raw", "!=");
op.tag ("OP");
rhs.attribute ("raw", "''");
}
else if (modifier == "is" || modifier == "equals")
{
op.attribute ("raw", "==");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "isnt" || modifier == "not")
{
op.attribute ("raw", "!=");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "has" || modifier == "contains")
{
op.attribute ("raw", "~");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "hasnt")
{
op.attribute ("raw", "!~");
op.tag ("OP");
rhs.attribute ("raw", value);
}
else if (modifier == "startswith" || modifier == "left")
{
op.attribute ("raw", "~");
op.tag ("OP");
rhs.attribute ("raw", "'^" + value + "'");
}
else if (modifier == "endswith" || modifier == "right")
{
op.attribute ("raw", "~");
op.tag ("OP");
rhs.attribute ("raw", "'" + value + "$'");
}
else if (modifier == "word")
{
op.attribute ("raw", "~");
op.tag ("OP");
#if defined (DARWIN) #if defined (DARWIN)
rhs.attribute ("raw", value); rhs.attribute ("raw", value);
#elif defined (SOLARIS) #elif defined (SOLARIS)
rhs.attribute ("raw", "'\\<" + value + "\\>'"); rhs.attribute ("raw", "'\\<" + value + "\\>'");
#else #else
rhs.attribute ("raw", "'\\b" + value + "\\b'"); rhs.attribute ("raw", "'\\b" + value + "\\b'");
#endif #endif
} }
else if (modifier == "noword") else if (modifier == "noword")
{ {
op.attribute ("raw", "!~"); op.attribute ("raw", "!~");
op.tag ("OP"); op.tag ("OP");
#if defined (DARWIN) #if defined (DARWIN)
rhs.attribute ("raw", value); rhs.attribute ("raw", value);
#elif defined (SOLARIS) #elif defined (SOLARIS)
rhs.attribute ("raw", "'\\<" + value + "\\>'"); rhs.attribute ("raw", "'\\<" + value + "\\>'");
#else #else
rhs.attribute ("raw", "'\\b" + value + "\\b'"); rhs.attribute ("raw", "'\\b" + value + "\\b'");
#endif #endif
} }
else else
throw format (STRING_PARSER_UNKNOWN_ATTMOD, modifier); throw format (STRING_PARSER_UNKNOWN_ATTMOD, modifier);
reconstructed.push_back (lhs); reconstructed.push_back (lhs);
reconstructed.push_back (op); reconstructed.push_back (op);
reconstructed.push_back (rhs); reconstructed.push_back (rhs);
found = true; found = true;
}
} }
} }
} }
} }
}
if (!found) if (!found)
reconstructed.push_back (*a);
}
else
reconstructed.push_back (*a); reconstructed.push_back (*a);
} }