A3t::findSubstitution
- Added support for standard and escaped '/from/to/g' constructs, which is an additional feature.
This commit is contained in:
@@ -28,6 +28,7 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <A3t.h>
|
#include <A3t.h>
|
||||||
#include <Nibbler.h>
|
#include <Nibbler.h>
|
||||||
|
#include <Directory.h>
|
||||||
#include <text.h>
|
#include <text.h>
|
||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
|
||||||
@@ -61,6 +62,7 @@ Tree* A3t::parse ()
|
|||||||
findCommand ();
|
findCommand ();
|
||||||
findFileOverride ();
|
findFileOverride ();
|
||||||
findConfigOverride ();
|
findConfigOverride ();
|
||||||
|
findSubstitution ();
|
||||||
findPattern ();
|
findPattern ();
|
||||||
|
|
||||||
validate ();
|
validate ();
|
||||||
@@ -200,7 +202,7 @@ void A3t::findFileOverride ()
|
|||||||
if (arg.find ("rc:") == 0)
|
if (arg.find ("rc:") == 0)
|
||||||
{
|
{
|
||||||
(*i)->tag ("RC");
|
(*i)->tag ("RC");
|
||||||
Tree* b = (*i)->addBranch (new Tree ("data"));
|
Tree* b = (*i)->addBranch (new Tree ("metadata"));
|
||||||
b->attribute ("file", arg.substr (3));
|
b->attribute ("file", arg.substr (3));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -227,7 +229,7 @@ void A3t::findConfigOverride ()
|
|||||||
if (sep != std::string::npos)
|
if (sep != std::string::npos)
|
||||||
{
|
{
|
||||||
(*i)->tag ("CONFIG");
|
(*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 ("name", arg.substr (3, sep - 3));
|
||||||
b->attribute ("value", arg.substr (sep + 1));
|
b->attribute ("value", arg.substr (sep + 1));
|
||||||
}
|
}
|
||||||
@@ -253,12 +255,49 @@ void A3t::findPattern ()
|
|||||||
pattern.length () > 0)
|
pattern.length () > 0)
|
||||||
{
|
{
|
||||||
(*i)->tag ("PATTERN");
|
(*i)->tag ("PATTERN");
|
||||||
Tree* b = (*i)->addBranch (new Tree ("data"));
|
Tree* b = (*i)->addBranch (new Tree ("metadata"));
|
||||||
b->attribute ("pattern", pattern);
|
b->attribute ("pattern", pattern);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////////////////////////////////////////////////////////////////
|
||||||
|
// /from/to/[g]
|
||||||
|
void A3t::findSubstitution ()
|
||||||
|
{
|
||||||
|
std::vector <Tree*>::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.
|
// Validate the parse tree.
|
||||||
void A3t::validate ()
|
void A3t::validate ()
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ private:
|
|||||||
void findFileOverride ();
|
void findFileOverride ();
|
||||||
void findConfigOverride ();
|
void findConfigOverride ();
|
||||||
void findPattern ();
|
void findPattern ();
|
||||||
|
void findSubstitution ();
|
||||||
void validate ();
|
void validate ();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#echo; ./args rc:x rc.debug:1 1234 done pri:H
|
#echo; ./args rc:x rc.debug:1 1234 done pri:H
|
||||||
#echo; ./args rc:x rc.debug:1 a.b\<c \(one or two\) modify 'quoted string' \'not quoted\' due:eom+1wk+1d
|
#echo; ./args rc:x rc.debug:1 a.b\<c \(one or two\) modify 'quoted string' \'not quoted\' due:eom+1wk+1d
|
||||||
|
|
||||||
echo; ./args rc:~/.taskrc 123 mod pro:'P 1' +home /from/to/g rc.name=value
|
echo; ./args rc:~/.taskrc 123 mod pro:'P 1' +home /from/to/g /from/to/ rc.name=value
|
||||||
echo; ./args rc:~/..taskrc rc.name=value add -- modify +tag /from/to/g name:value
|
echo; ./args rc:~/..taskrc rc.name=value add -- modify +tag /from/to/g name:value /long/path/to/file.txt
|
||||||
echo; ./args /pattern/ nex
|
echo; ./args /pattern/ nex
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user