A3t::findPattern

- Now parses patterns and extracts the pattern, which may include escaped /
  characters, which is an improvement.
This commit is contained in:
Paul Beckingham 2013-08-31 12:24:30 -04:00
parent 96a06eafbf
commit 2281c5a6bf
4 changed files with 36 additions and 4 deletions

View file

@ -27,6 +27,7 @@
#include <iostream>
#include <A3t.h>
#include <Nibbler.h>
#include <text.h>
#include <util.h>
@ -60,6 +61,9 @@ Tree* A3t::parse ()
findCommand ();
findFileOverride ();
findConfigOverride ();
findPattern ();
validate ();
return _tree;
}
@ -232,9 +236,34 @@ void A3t::findConfigOverride ()
}
////////////////////////////////////////////////////////////////////////////////
// Validate the parse tree.
void A3t::validate ()
// /pattern/
void A3t::findPattern ()
{
std::vector <Tree*>::iterator i;
for (i = _tree->_branches.begin (); i != _tree->_branches.end (); ++i)
{
// Parser override operator.
if ((*i)->attribute ("raw") == "--")
break;
Nibbler n ((*i)->attribute ("raw"));
std::string pattern;
if (n.getQuoted ('/', pattern) &&
n.depleted () &&
pattern.length () > 0)
{
(*i)->tag ("PATTERN");
Tree* b = (*i)->addBranch (new Tree ("data"));
b->attribute ("pattern", pattern);
}
}
}
////////////////////////////////////////////////////////////////////////////////
// Validate the parse tree.
void A3t::validate ()
{
// TODO Any RC node must have a root/*[+RC]/data[@file] that exists.
}
////////////////////////////////////////////////////////////////////////////////

View file

@ -46,6 +46,7 @@ private:
void findCommand ();
void findFileOverride ();
void findConfigOverride ();
void findPattern ();
void validate ();
private:
@ -55,4 +56,4 @@ private:
#endif
////////////////////////////////////////////////////////////////////////////////

View file

@ -240,7 +240,8 @@ void Tree::dumpNode (Tree* t, int depth)
for (int i = 0; i < depth; ++i)
std::cout << " ";
std::cout << t << " \033[1m" << t->_name << "\033[0m";
// std::cout << t << " \033[1m" << t->_name << "\033[0m";
std::cout << "\033[1m" << t->_name << "\033[0m";
// Dump attributes.
std::string atts;

View file

@ -10,4 +10,5 @@
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 /pattern/ nex