mirror of
https://github.com/GothenburgBitFactory/taskwarrior.git
synced 2025-07-07 20:06:36 +02:00
A3t::findSubstitution
- Added support for standard and escaped '/from/to/g' constructs, which is an additional feature.
This commit is contained in:
parent
663c82837c
commit
272450ff9b
3 changed files with 45 additions and 5 deletions
|
@ -28,6 +28,7 @@
|
|||
#include <iostream>
|
||||
#include <A3t.h>
|
||||
#include <Nibbler.h>
|
||||
#include <Directory.h>
|
||||
#include <text.h>
|
||||
#include <util.h>
|
||||
|
||||
|
@ -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 <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.
|
||||
void A3t::validate ()
|
||||
|
|
|
@ -47,6 +47,7 @@ private:
|
|||
void findFileOverride ();
|
||||
void findConfigOverride ();
|
||||
void findPattern ();
|
||||
void findSubstitution ();
|
||||
void validate ();
|
||||
|
||||
private:
|
||||
|
|
|
@ -8,7 +8,7 @@
|
|||
#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:~/.taskrc 123 mod pro:'P 1' +home /from/to/g rc.name=value
|
||||
echo; ./args rc:~/..taskrc rc.name=value add -- modify +tag /from/to/g 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 /long/path/to/file.txt
|
||||
echo; ./args /pattern/ nex
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue