From 272450ff9b63ef13b9f96d9e0dbf3c61039d72cd Mon Sep 17 00:00:00 2001 From: Paul Beckingham Date: Sat, 31 Aug 2013 16:05:14 -0400 Subject: [PATCH] A3t::findSubstitution - Added support for standard and escaped '/from/to/g' constructs, which is an additional feature. --- src/parser/A3t.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++--- src/parser/A3t.h | 1 + src/parser/run | 4 ++-- 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/src/parser/A3t.cpp b/src/parser/A3t.cpp index ba15df8c0..c0065a9ae 100644 --- a/src/parser/A3t.cpp +++ b/src/parser/A3t.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include @@ -61,6 +62,7 @@ Tree* A3t::parse () findCommand (); findFileOverride (); findConfigOverride (); + findSubstitution (); findPattern (); validate (); @@ -200,7 +202,7 @@ void A3t::findFileOverride () if (arg.find ("rc:") == 0) { (*i)->tag ("RC"); - Tree* b = (*i)->addBranch (new Tree ("data")); + Tree* b = (*i)->addBranch (new Tree ("metadata")); b->attribute ("file", arg.substr (3)); } } @@ -227,7 +229,7 @@ void A3t::findConfigOverride () if (sep != std::string::npos) { (*i)->tag ("CONFIG"); - Tree* b = (*i)->addBranch (new Tree ("data")); + Tree* b = (*i)->addBranch (new Tree ("metadata")); b->attribute ("name", arg.substr (3, sep - 3)); b->attribute ("value", arg.substr (sep + 1)); } @@ -253,12 +255,49 @@ void A3t::findPattern () pattern.length () > 0) { (*i)->tag ("PATTERN"); - Tree* b = (*i)->addBranch (new Tree ("data")); + Tree* b = (*i)->addBranch (new Tree ("metadata")); b->attribute ("pattern", pattern); } } } +//////////////////////////////////////////////////////////////////////////////// +// /from/to/[g] +void A3t::findSubstitution () +{ + std::vector ::iterator i; + for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i) + { + // Parser override operator. + if ((*i)->attribute ("raw") == "--") + break; + + std::string raw = (*i)->attribute ("raw"); + Nibbler n (raw); + + std::string from; + std::string to; + bool global = false; + if (n.getQuoted ('/', from) && + n.backN () && + n.getQuoted ('/', to)) + { + if (n.skip ('g')) + global = true; + + if (n.depleted () && + !Directory (raw).exists ()) + { + (*i)->tag ("SUBSTITUTION"); + Tree* b = (*i)->addBranch (new Tree ("metadata")); + b->attribute ("from", from); + b->attribute ("to", to); + b->attribute ("global", global ? 1 : 0); + } + } + } +} + //////////////////////////////////////////////////////////////////////////////// // Validate the parse tree. void A3t::validate () diff --git a/src/parser/A3t.h b/src/parser/A3t.h index c6a1bba35..254017476 100644 --- a/src/parser/A3t.h +++ b/src/parser/A3t.h @@ -47,6 +47,7 @@ private: void findFileOverride (); void findConfigOverride (); void findPattern (); + void findSubstitution (); void validate (); private: diff --git a/src/parser/run b/src/parser/run index 6f02ad98a..dbb7f2200 100755 --- a/src/parser/run +++ b/src/parser/run @@ -8,7 +8,7 @@ #echo; ./args rc:x rc.debug:1 1234 done pri:H #echo; ./args rc:x rc.debug:1 a.b\