summaryrefslogtreecommitdiff
path: root/drivers/nrex/nrex.cpp
diff options
context:
space:
mode:
authorZher Huei Lee <lee.zh.92@gmail.com>2015-10-19 04:45:45 +0100
committerZher Huei Lee <lee.zh.92@gmail.com>2015-11-07 11:03:24 +0000
commit8766d3100d72f4315457485506ec7ff9e8df3efa (patch)
tree9e9832037a18ce2965175c7c5a823288e7310353 /drivers/nrex/nrex.cpp
parentdde6396f221672d34d178c75f4080c1e87612aea (diff)
Updated nrex for LookAhead support
Diffstat (limited to 'drivers/nrex/nrex.cpp')
-rw-r--r--drivers/nrex/nrex.cpp44
1 files changed, 32 insertions, 12 deletions
diff --git a/drivers/nrex/nrex.cpp b/drivers/nrex/nrex.cpp
index 696d46240e..ba8bfa8a59 100644
--- a/drivers/nrex/nrex.cpp
+++ b/drivers/nrex/nrex.cpp
@@ -210,14 +210,18 @@ struct nrex_node
struct nrex_node_group : public nrex_node
{
- int capturing;
+ static const int NonCapture = -1;
+ static const int Class = -2;
+ static const int LookAhead = -3;
+
+ int mode;
bool negate;
nrex_array<nrex_node*> childset;
nrex_node* back;
- nrex_node_group(int capturing)
+ nrex_node_group(int mode)
: nrex_node(true)
- , capturing(capturing)
+ , mode(mode)
, negate(false)
, back(NULL)
{
@@ -234,9 +238,9 @@ struct nrex_node_group : public nrex_node
int test(nrex_search* s, int pos) const
{
- if (capturing >= 0)
+ if (mode >= 0)
{
- s->captures[capturing].start = pos;
+ s->captures[mode].start = pos;
}
for (unsigned int i = 0; i < childset.size(); ++i)
{
@@ -256,12 +260,20 @@ struct nrex_node_group : public nrex_node
{
return -1;
}
+ if (i + 1 < childset.size())
+ {
+ continue;
+ }
}
if (res >= 0)
{
- if (capturing >= 0)
+ if (mode >= 0)
+ {
+ s->captures[mode].length = res - pos;
+ }
+ else if (mode == LookAhead)
{
- s->captures[capturing].length = res - pos;
+ res = pos;
}
return next ? next->test(s, res) : res;
}
@@ -271,9 +283,9 @@ struct nrex_node_group : public nrex_node
virtual int test_parent(nrex_search* s, int pos) const
{
- if (capturing >= 0)
+ if (mode >= 0)
{
- s->captures[capturing].length = pos - s->captures[capturing].start;
+ s->captures[mode].length = pos - s->captures[mode].start;
}
return nrex_node::test_parent(s, pos);
}
@@ -647,7 +659,15 @@ bool nrex::compile(const nrex_char* pattern)
if (c[2] == ':')
{
c = &c[2];
- nrex_node_group* group = NREX_NEW(nrex_node_group(-1));
+ nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_node_group::NonCapture));
+ stack.top()->add_child(group);
+ stack.push(group);
+ }
+ else if (c[2] == '!' || c[2] == '=')
+ {
+ c = &c[2];
+ nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_node_group::LookAhead));
+ group->negate = (c[0] == '!');
stack.top()->add_child(group);
stack.push(group);
}
@@ -664,7 +684,7 @@ bool nrex::compile(const nrex_char* pattern)
}
else
{
- nrex_node_group* group = NREX_NEW(nrex_node_group(-1));
+ nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_node_group::NonCapture));
stack.top()->add_child(group);
stack.push(group);
}
@@ -682,7 +702,7 @@ bool nrex::compile(const nrex_char* pattern)
}
else if (c[0] == '[')
{
- nrex_node_group* group = NREX_NEW(nrex_node_group(-1));
+ nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_node_group::Class));
stack.top()->add_child(group);
if (c[1] == '^')
{