CLI2: Added ::decomposeModAttributes
This commit is contained in:
84
src/CLI2.cpp
84
src/CLI2.cpp
@@ -523,8 +523,8 @@ void CLI2::prepareFilter (bool applyContext)
|
|||||||
insertJunctions (); // Deliberately after all desugar calls.
|
insertJunctions (); // Deliberately after all desugar calls.
|
||||||
|
|
||||||
// Decompose the elements for MODIFICATIONs.
|
// Decompose the elements for MODIFICATIONs.
|
||||||
/*
|
|
||||||
decomposeModAttributes ();
|
decomposeModAttributes ();
|
||||||
|
/*
|
||||||
decomposeModAttributeModifiers ();
|
decomposeModAttributeModifiers ();
|
||||||
*/
|
*/
|
||||||
decomposeModTags ();
|
decomposeModTags ();
|
||||||
@@ -1487,71 +1487,59 @@ void CLI2::defaultCommand ()
|
|||||||
context.debug (dump ("CLI2::analyze defaultCommand"));
|
context.debug (dump ("CLI2::analyze defaultCommand"));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void CLI2::decomposeModAttributes ()
|
void CLI2::decomposeModAttributes ()
|
||||||
{
|
{
|
||||||
bool changes = false;
|
bool changes = false;
|
||||||
for (auto& a : _args)
|
for (auto& a : _args)
|
||||||
{
|
{
|
||||||
if (a.hasTag ("TERMINATOR"))
|
if (a._lextype == Lexer::Type::pair &&
|
||||||
break;
|
a.hasTag ("MODIFICATION"))
|
||||||
|
|
||||||
if (a.hasTag ("MODIFICATION"))
|
|
||||||
{
|
{
|
||||||
// Look for a valid attribute name.
|
changes = true;
|
||||||
Nibbler n (a.attribute ("raw"));
|
auto raw = a.attribute ("raw");
|
||||||
std::string name;
|
auto colon = raw.find (':');
|
||||||
if (n.getName (name) &&
|
auto equal = raw.find ('=');
|
||||||
name.length ())
|
|
||||||
|
// Q: Which of ':', '=' is the separator?
|
||||||
|
// A: Whichever comes first. For example:
|
||||||
|
// name:a=b
|
||||||
|
// name=a:b
|
||||||
|
// Both are valid, and 'name' is the attribute name in each case.
|
||||||
|
std::string::size_type separator = std::min (colon, equal);
|
||||||
|
std::string name = raw.substr (0, separator);
|
||||||
|
std::string value = raw.substr (separator + 1);
|
||||||
|
|
||||||
|
a.attribute ("name", name);
|
||||||
|
a.attribute ("value", value);
|
||||||
|
|
||||||
|
std::string canonical;
|
||||||
|
if (canonicalize (canonical, "attribute", name))
|
||||||
{
|
{
|
||||||
if (n.skip (':'))
|
a.attribute ("canonical", canonical);
|
||||||
|
|
||||||
|
auto col = context.columns.find (canonical);
|
||||||
|
if (col != context.columns.end () &&
|
||||||
|
col->second->modifiable ())
|
||||||
{
|
{
|
||||||
std::string value;
|
a.tag ("MODIFIABLE");
|
||||||
if (n.getQuoted ('"', value) ||
|
|
||||||
n.getQuoted ('\'', value) ||
|
|
||||||
n.getUntilEOS (value) ||
|
|
||||||
n.depleted ())
|
|
||||||
{
|
|
||||||
if (value == "")
|
|
||||||
value = "''";
|
|
||||||
|
|
||||||
std::string canonical;
|
|
||||||
if (canonicalize (canonical, "uda", name))
|
|
||||||
{
|
|
||||||
a.attribute ("name", canonical);
|
|
||||||
a.attribute ("value", value);
|
|
||||||
a.tag ("UDA");
|
|
||||||
a.tag ("MODIFIABLE");
|
|
||||||
changes = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (canonicalize (canonical, "attribute", name))
|
|
||||||
{
|
|
||||||
a.attribute ("name", canonical);
|
|
||||||
a.attribute ("value", value);
|
|
||||||
a.tag ("ATTRIBUTE");
|
|
||||||
|
|
||||||
auto col = context.columns.find (canonical);
|
|
||||||
if (col != context.columns.end () &&
|
|
||||||
col->second->modifiable ())
|
|
||||||
{
|
|
||||||
a.tag ("MODIFIABLE");
|
|
||||||
}
|
|
||||||
|
|
||||||
changes = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (canonicalize (canonical, "uda", name))
|
||||||
|
{
|
||||||
|
a.attribute ("canonical", canonical);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO Good place to complain about unrecognized attributes?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (changes &&
|
if (changes &&
|
||||||
context.config.getInteger ("debug.parser") >= 3)
|
context.config.getInteger ("debug.parser") >= 3)
|
||||||
context.debug (dump ("CLI2::analyze decomposeModAttributes"));
|
context.debug (dump ("CLI2::prepareFilter decomposeModAttributes"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
void CLI2::decomposeModAttributeModifiers ()
|
void CLI2::decomposeModAttributeModifiers ()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -103,8 +103,8 @@ private:
|
|||||||
void desugarFilterPlainArgs ();
|
void desugarFilterPlainArgs ();
|
||||||
void insertJunctions ();
|
void insertJunctions ();
|
||||||
void defaultCommand ();
|
void defaultCommand ();
|
||||||
/*
|
|
||||||
void decomposeModAttributes ();
|
void decomposeModAttributes ();
|
||||||
|
/*
|
||||||
void decomposeModAttributeModifiers ();
|
void decomposeModAttributeModifiers ();
|
||||||
*/
|
*/
|
||||||
void decomposeModTags ();
|
void decomposeModTags ();
|
||||||
|
|||||||
Reference in New Issue
Block a user