From 10c1203c8718b823bece663761f9662d2f6fdd5a Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sun, 24 Jul 2011 13:41:04 -0400 Subject: [PATCH] Expression reboot - Implemented A3::is_subst. --- src/A3.cpp | 74 +++++++++++++++++++++++++++++++++--------------------- src/A3.h | 2 +- 2 files changed, 46 insertions(+), 30 deletions(-) diff --git a/src/A3.cpp b/src/A3.cpp index db857002b..c1026cec3 100644 --- a/src/A3.cpp +++ b/src/A3.cpp @@ -637,6 +637,12 @@ const A3 A3::tokenize (const A3& input) const output.push_back (Arg (s, "string")); } + else if (is_subst (n, s)) + { + std::cout << "# subst '" << s << "'\n"; + output.push_back (Arg (s, "subst")); + } + else if (is_pattern (n, s)) { std::cout << "# pattern '" << s << "'\n"; @@ -965,6 +971,7 @@ bool A3::is_duration (Nibbler& n, std::string& result) // // bool A3::is_pattern (Nibbler& n, std::string& result) { + n.save (); std::string pattern; if (n.getQuoted ('/', pattern) && pattern.length () > 0) @@ -973,6 +980,44 @@ bool A3::is_pattern (Nibbler& n, std::string& result) return true; } + n.restore (); + return false; +} + +//////////////////////////////////////////////////////////////////////////////// +// ///[g] +// +// Note: one problem with this is that substitutions start with a /, and so any +// two-directory absolute path, (or three-level, if the third directory is +// named 'g') can be misinterpreted. To help (but not solve) this, if a +// substition exists on the local disk, it is not considered a subst. +// This needs to be changed to a better solution. +bool A3::is_subst (Nibbler& n, std::string& result) +{ + n.save (); + + std::string from; + std::string to; + bool global = false; + if (n.skip ('/') && + n.getUntil ('/', from) && + from.length () && + n.skip ('/') && + n.getUntil ('/', to) && + n.skip ('/')) + { + if (n.skip ('g')) + global = true; + + result = '/' + from + '/' + to + '/'; + if (global) + result += 'g'; + + if (! Directory (result).exists ()) // Ouch - expensive call. + return true; + } + + n.restore (); return false; } @@ -990,35 +1035,6 @@ bool A3::is_pattern (Nibbler& n, std::string& result) #ifdef NOPE -//////////////////////////////////////////////////////////////////////////////// -// ///[g] -// -// Note: one problem with this is that substitutions start with a /, and so any -// two-directory absolute path, (or three-level, if the third directory is -// named 'g') can be misinterpreted. To help (but not solve) this, if a -// substition exists on the local disk, it is not considered a subst. -// This needs to be changed to a better solution. -bool A3::is_subst (const std::string& input) -{ - std::string from; - std::string to; - Nibbler n (input); - if (n.skip ('/') && - n.getUntil ('/', from) && - from.length () && - n.skip ('/') && - n.getUntil ('/', to) && - n.skip ('/')) - { - n.skip ('g'); - if (n.depleted () && - ! Directory (input).exists ()) // Ouch - expensive call. - return true; - } - - return false; -} - //////////////////////////////////////////////////////////////////////////////// // [-][,[-]] bool A3::is_id (const std::string& input) diff --git a/src/A3.h b/src/A3.h index 48d25a32a..004a413eb 100644 --- a/src/A3.h +++ b/src/A3.h @@ -112,9 +112,9 @@ public: static bool is_dom (Nibbler&, std::string&); static bool is_duration (Nibbler&, std::string&); static bool is_pattern (Nibbler&, std::string&); + static bool is_subst (Nibbler&, std::string&); /* - static bool is_subst (const std::string&); static bool is_id (const std::string&); static bool is_uuid (const std::string&); static bool is_tag (const std::string&);