From b3a73f2da1657f3149e9ae14d872911b14446169 Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 Jul 2011 14:27:10 -0400 Subject: [PATCH] Expression reboot - Implemented A3::is_id and A3::is_uuid. - Obsolted old is_operator. - Obsolted old is_modifier. - Obsolted old is_expression. --- src/A3.cpp | 204 +++++++++++++++++++++-------------------------------- src/A3.h | 7 +- 2 files changed, 84 insertions(+), 127 deletions(-) diff --git a/src/A3.cpp b/src/A3.cpp index c1026cec3..886ef682d 100644 --- a/src/A3.cpp +++ b/src/A3.cpp @@ -691,6 +691,18 @@ const A3 A3::tokenize (const A3& input) const output.push_back (Arg (s, "duration")); } + else if (is_id (n, s)) + { + std::cout << "# id '" << s << "'\n"; + output.push_back (Arg (s, "id")); + } + + else if (is_uuid (n, s)) + { + std::cout << "# uuid '" << s << "'\n"; + output.push_back (Arg (s, "uuid")); + } + else if (n.getNumber (d)) { std::cout << "# num '" << d << "'\n"; @@ -1021,6 +1033,76 @@ bool A3::is_subst (Nibbler& n, std::string& result) return false; } +//////////////////////////////////////////////////////////////////////////////// +// [,...] +bool A3::is_uuid (Nibbler& n, std::string& result) +{ + n.save (); + result = ""; + std::string uuid; + if (n.getUUID (uuid)) + { + result += uuid; + while (n.skip (',') && + n.getUUID (uuid)) + { + result += ',' + uuid; + } + + return true; + } + + n.restore (); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// [-][,[-]] +bool A3::is_id (Nibbler& n, std::string& result) +{ + n.save (); + std::string::size_type start = n.cursor (); + int id; + + if (n.getUnsignedInt (id)) + { + if (n.skip ('-') && + !n.getUnsignedInt (id)) + { + n.restore (); + return false; + } + + while (n.skip (',')) + { + if (n.getUnsignedInt (id)) + { + if (n.skip ('-')) + { + if (!n.getUnsignedInt (id)) + { + n.restore (); + return false; + } + } + } + else + { + n.restore (); + return false; + } + } + + std::string::size_type end = n.cursor (); + n.restore (); + if (n.getN (end - start, result)) + return true; + } + + n.restore (); + return false; +} + @@ -1035,62 +1117,6 @@ bool A3::is_subst (Nibbler& n, std::string& result) #ifdef NOPE -//////////////////////////////////////////////////////////////////////////////// -// [-][,[-]] -bool A3::is_id (const std::string& input) -{ - Nibbler n (input); - int id; - - if (n.getUnsignedInt (id)) - { - if (n.skip ('-')) - { - if (!n.getUnsignedInt (id)) - return false; - } - - while (n.skip (',')) - { - if (n.getUnsignedInt (id)) - { - if (n.skip ('-')) - { - if (!n.getUnsignedInt (id)) - return false; - } - } - else - return false; - } - } - else - return false; - - return n.depleted (); -} - -//////////////////////////////////////////////////////////////////////////////// -// [,...] -bool A3::is_uuid (const std::string& input) -{ - Nibbler n (input); - std::string uuid; - - if (n.getUUID (uuid)) - { - while (n.skip (',')) - { - if (!n.getUUID (uuid)) - return false; - } - } - else - return false; - - return n.depleted (); -} - //////////////////////////////////////////////////////////////////////////////// // [+-] bool A3::is_tag (const std::string& input) @@ -1108,16 +1134,6 @@ bool A3::is_tag (const std::string& input) return false; } -//////////////////////////////////////////////////////////////////////////////// -bool A3::is_operator (const std::string& input) -{ - for (unsigned int i = 0; i < NUM_OPERATORS; ++i) - if (operators[i].op == input) - return true; - - return false; -} - //////////////////////////////////////////////////////////////////////////////// bool A3::is_operator ( const std::string& input, @@ -1148,62 +1164,6 @@ bool A3::is_symbol_operator (const std::string& input) return false; } -//////////////////////////////////////////////////////////////////////////////// -bool A3::is_modifier (const std::string& input) -{ - // Guess at the full attribute name. - std::vector candidates; - for (unsigned i = 0; i < NUM_MODIFIER_NAMES; ++i) - { - // Short-circuit: exact matches cause immediate return. - if (modifierNames[i] == input) - return true; - - candidates.push_back (modifierNames[i]); - } - - std::vector matches; - autoComplete (input, - candidates, - matches, - context.config.getInteger ("abbreviation.minimum")); - - if (matches.size () == 1) - return true; - - return false; -} - -//////////////////////////////////////////////////////////////////////////////// -bool A3::is_expression (const std::string& input) -{ - std::string unquoted = unquoteText (input); - - // Look for space-separated operators. - std::vector tokens; - split (tokens, unquoted, ' '); - std::vector ::iterator token; - for (token = tokens.begin (); token != tokens.end (); ++token) - if (is_operator (*token)) - return true; - - // Look for bare or cuddled operators. - Lexer lexer (unquoted); - lexer.skipWhitespace (true); - lexer.coalesceAlpha (true); - lexer.coalesceDigits (true); - lexer.coalesceQuoted (true); - - tokens.clear (); - lexer.tokenize (tokens); - - for (token = tokens.begin (); token != tokens.end (); ++token) - if (is_operator (*token)) - return true; - - return false; -} - //////////////////////////////////////////////////////////////////////////////// // :['"]['"] bool A3::extract_attr ( diff --git a/src/A3.h b/src/A3.h index 004a413eb..2ced58ad3 100644 --- a/src/A3.h +++ b/src/A3.h @@ -113,16 +113,13 @@ public: static bool is_duration (Nibbler&, std::string&); static bool is_pattern (Nibbler&, std::string&); static bool is_subst (Nibbler&, std::string&); + static bool is_id (Nibbler&, std::string&); + static bool is_uuid (Nibbler&, std::string&); /* - static bool is_id (const std::string&); - static bool is_uuid (const std::string&); static bool is_tag (const std::string&); - static bool is_operator (const std::string&); static bool is_operator (const std::string&, char&, int&, char&); static bool is_symbol_operator (const std::string&); - static bool is_modifier (const std::string&); - static bool is_expression (const std::string&); static bool extract_attr (const std::string&, std::string&, std::string&); static bool extract_attmod (const std::string&, std::string&, std::string&, std::string&, std::string&);