Mercurial > hg > Applications > Grep
changeset 199:98ff9d94566a pairPro
fix CharClassWalker
author | Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp> |
---|---|
date | Sat, 26 Dec 2015 18:09:27 +0900 |
parents | 63a98405aafa |
children | 89cec6238a75 |
files | regexParser/TODO regexParser/regexParser.h regexParser/subsetConstraction.cc |
diffstat | 3 files changed, 19 insertions(+), 21 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/regexParser/TODO Sat Dec 26 18:09:27 2015 +0900 @@ -0,0 +1,3 @@ +2015年 12月26日 土曜日 18時07分00秒 JST + TODO CharClassWalker のテストルーチンを作成する + TODO CharClassMerge のテストルーチンを作成する
--- a/regexParser/regexParser.h Sat Dec 26 14:05:14 2015 +0900 +++ b/regexParser/regexParser.h Sat Dec 26 18:09:27 2015 +0900 @@ -86,6 +86,7 @@ typedef struct charClassWalker { CharClassStackPtr stack; + charClassStackState turn; CharClassPtr next; } CharClassWalker, *CharClassWalkerPtr;
--- a/regexParser/subsetConstraction.cc Sat Dec 26 14:05:14 2015 +0900 +++ b/regexParser/subsetConstraction.cc Sat Dec 26 18:09:27 2015 +0900 @@ -117,11 +117,13 @@ while (next->left) { CharClassStackPtr ccs = NEW(CharClassStack); ccs->next = walk->stack; - ccs->turn = LEFT; + ccs->turn = walk->turn; + walk->turn = LEFT; ccs->cc = next; walk->stack = ccs; next = next->left; } + walk->turn = SELF; walk->next = next; } @@ -130,10 +132,6 @@ walk->next = NULL; walk->stack = NULL; if (!next) return walk; - if (!next->left) { - walk->next = next; - return walk; - } findLeftMost(next,walk); return walk; } @@ -143,36 +141,32 @@ } CharClassStackPtr charClassStackPop(CharClassWalkerPtr walk) { - if (!walk->stack) { - return NULL; - } CharClassStackPtr prev = walk->stack->next; free(walk->stack); walk->stack = prev; + walk->turn = prev->turn; return prev; } CharClassPtr getNext(CharClassWalkerPtr walk) { CharClassPtr current = walk->next; walk->next = NULL; - while (walk->stack) { - while (walk->stack->turn == RIGHT) { - if (charClassStackPop(walk) == NULL) { - return current; - } - } - if (walk->stack->turn == LEFT) { - walk->next = walk->stack->cc; - walk->stack->turn = SELF; - return current; - } + if (walk->turn == SELF) { if (current->right) { - walk->stack->turn = RIGHT; + walk->turn = RIGHT; findLeftMost(current->right,walk); return current; } + } + while (walk->stack) { + walk->next = walk->stack->cc; charClassStackPop(walk); - } + if (walk->turn == LEFT) { + walk->turn = SELF; + return current; + } + } + walk->next = NULL; return current; }