A3
- Removed obsolete ::sequence method.
This commit is contained in:
88
src/A3.cpp
88
src/A3.cpp
@@ -759,94 +759,6 @@ const A3 A3::tokenize (const A3& input) const
|
|||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
|
||||||
// Convert: 1-3,5 7 92bea814-2e3f-487b-92a1-3286dd1a7eda
|
|
||||||
// To: (id=1 or id=2 or id=3 or id=5 or id=7 or
|
|
||||||
// uuid=92bea814-2e3f-487b-92a1-3286dd1a7eda)
|
|
||||||
const A3 A3::sequence (const A3& input) const
|
|
||||||
{
|
|
||||||
A3 sequenced;
|
|
||||||
|
|
||||||
// Extract all the components of a sequence.
|
|
||||||
std::vector <int> ids;
|
|
||||||
std::vector <std::string> uuids;
|
|
||||||
std::vector <Arg>::const_iterator arg;
|
|
||||||
for (arg = input.begin (); arg != input.end (); ++arg)
|
|
||||||
{
|
|
||||||
if (arg->_category == Arg::cat_id)
|
|
||||||
extract_id (arg->_raw, ids);
|
|
||||||
|
|
||||||
else if (arg->_category == Arg::cat_uuid)
|
|
||||||
extract_uuid (arg->_raw, uuids);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If there is no sequence, we're done.
|
|
||||||
if (ids.size () == 0 && uuids.size () == 0)
|
|
||||||
return input;
|
|
||||||
|
|
||||||
if (ids.size () == 1 && ids[0] < 1)
|
|
||||||
throw format (STRING_A3_ZERO_ID, ids[0]);
|
|
||||||
|
|
||||||
// Copy everything up to the first id/uuid.
|
|
||||||
for (arg = input.begin (); arg != input.end (); ++arg)
|
|
||||||
{
|
|
||||||
if (arg->_category == Arg::cat_id || arg->_category == Arg::cat_uuid)
|
|
||||||
break;
|
|
||||||
|
|
||||||
sequenced.push_back (*arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert the algebraic form.
|
|
||||||
sequenced.push_back (Arg ("(", Arg::cat_op));
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < ids.size (); ++i)
|
|
||||||
{
|
|
||||||
if (i)
|
|
||||||
sequenced.push_back (Arg ("or", Arg::cat_op));
|
|
||||||
|
|
||||||
sequenced.push_back (Arg ("id", Arg::type_number, Arg::cat_dom));
|
|
||||||
sequenced.push_back (Arg ("=", Arg::cat_op));
|
|
||||||
sequenced.push_back (Arg (format(ids[i]), Arg::type_number, Arg::cat_literal));
|
|
||||||
}
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < uuids.size (); ++i)
|
|
||||||
{
|
|
||||||
if (ids.size () + i > 0)
|
|
||||||
sequenced.push_back (Arg ("or", Arg::cat_op));
|
|
||||||
|
|
||||||
// A full-length UUID requires a string comparison.
|
|
||||||
if (uuids[i].length () == 36)
|
|
||||||
{
|
|
||||||
sequenced.push_back (Arg ("uuid", Arg::type_string, Arg::cat_dom));
|
|
||||||
sequenced.push_back (Arg ("=", Arg::cat_op));
|
|
||||||
sequenced.push_back (Arg (uuids[i], Arg::type_string, Arg::cat_literal));
|
|
||||||
}
|
|
||||||
// A UUID fragment is a leftmost comparison.
|
|
||||||
else
|
|
||||||
{
|
|
||||||
sequenced.push_back (Arg ("uuid", Arg::type_string, Arg::cat_dom));
|
|
||||||
sequenced.push_back (Arg ("~", Arg::cat_op));
|
|
||||||
sequenced.push_back (Arg ("^" + uuids[i], Arg::type_string, Arg::cat_rx));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
sequenced.push_back (Arg (")", Arg::cat_op));
|
|
||||||
|
|
||||||
// Now copy everything after the last id/uuid.
|
|
||||||
bool found_id = false;
|
|
||||||
for (arg = input.begin (); arg != input.end (); ++arg)
|
|
||||||
{
|
|
||||||
if (arg->_category == Arg::cat_id || arg->_category == Arg::cat_uuid)
|
|
||||||
found_id = true;
|
|
||||||
|
|
||||||
else if (found_id)
|
|
||||||
sequenced.push_back (*arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
sequenced.dump ("A3::sequence");
|
|
||||||
return sequenced;
|
|
||||||
}
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
// Dijkstra Shunting Algorithm.
|
// Dijkstra Shunting Algorithm.
|
||||||
// http://en.wikipedia.org/wiki/Shunting-yard_algorithm
|
// http://en.wikipedia.org/wiki/Shunting-yard_algorithm
|
||||||
|
|||||||
1
src/A3.h
1
src/A3.h
@@ -62,7 +62,6 @@ public:
|
|||||||
const A3 extract_modifications () const;
|
const A3 extract_modifications () const;
|
||||||
|
|
||||||
const A3 tokenize (const A3&) const;
|
const A3 tokenize (const A3&) const;
|
||||||
const A3 sequence (const A3&) const;
|
|
||||||
const A3 postfix (const A3&) const;
|
const A3 postfix (const A3&) const;
|
||||||
|
|
||||||
static bool is_attr (Nibbler&, Arg&);
|
static bool is_attr (Nibbler&, Arg&);
|
||||||
|
|||||||
Reference in New Issue
Block a user