Mercurial > hg > Applications > Grep
changeset 309:058c87665213
small fix
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Mon, 08 Feb 2016 18:04:28 +0900 |
parents | 1188debbef10 |
children | df27e6cab846 |
files | regexParser/CharClass.cc regexParser/node.cc regexParser/regexParser.h |
diffstat | 3 files changed, 31 insertions(+), 28 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/CharClass.cc Mon Feb 08 12:45:45 2016 +0900 +++ b/regexParser/CharClass.cc Mon Feb 08 18:04:28 2016 +0900 @@ -10,10 +10,20 @@ #include "CharClass.h" +CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { + CharClassPtr cc = NEW(CharClass); + cc->cond.range.begin = begin; + cc->cond.range.end = end; + cc->cond.w.word = NULL; + cc->cond.w.length = 0; + cc->left = left; + cc->right = right; + cc->nextState.bitContainer = state; + return cc; +} CharClassPtr createCharClassWord(RegexInfoPtr ri) { CharClassPtr cc = NEW(CharClass); - cc->type = 'a'; cc->left = NULL; cc->right = NULL; cc->cond.w.word = ri->tokenValue; @@ -96,18 +106,6 @@ } -CharClassPtr createCharClassRange(unsigned long begin, unsigned long end,unsigned long state, CharClassPtr left, CharClassPtr right) { - CharClassPtr cc = NEW(CharClass); - cc->type = 'r'; - cc->cond.range.begin = begin; - cc->cond.range.end = end; - cc->cond.w.word = NULL; - cc->cond.w.length = 0; - cc->left = left; - cc->right = right; - cc->nextState.bitContainer = state; - return cc; -} CharClassPtr charClassMerge(CharClassPtr cc,unsigned long begin, unsigned long end, BitVector nextState) ;
--- a/regexParser/node.cc Mon Feb 08 12:45:45 2016 +0900 +++ b/regexParser/node.cc Mon Feb 08 18:04:28 2016 +0900 @@ -2,19 +2,27 @@ #include "regexParser.h" #include "node.h" +static void printCharClassWord(CharClassPtr cc) { + for (int i = 0; i < cc->cond.w.length; i++) { + putchar(cc->cond.w.word[i]); + } +} + void printCharacterClass(CharClassPtr cc, long nodeNumber,int d) { if (!cc) return; - if (cc->type == 'a' || cc->type == 'r') { - if (cc->left) { - printCharacterClass(cc->left,nodeNumber,d+1); - } - printf("%*c",d*4, ' '); + if (cc->left) { + printCharacterClass(cc->left,nodeNumber,d+1); + } + printf("%*c",d*4, ' '); + if (cc->cond.w.word) { + printCharClassWord(cc); + } else { RangeList range = cc->cond.range; printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); - printf("(%lx)\n",cc->nextState.bitContainer); - if (cc->right) { - printCharacterClass(cc->right,nodeNumber,d+1); - } + } + printf("(0x%lx)\n",cc->nextState.bitContainer); + if (cc->right) { + printCharacterClass(cc->right,nodeNumber,d+1); } } @@ -24,13 +32,11 @@ } if (n->tokenType == 'a') { printf("%*c",d*4, ' '); - for (int i = 0; i < n->cc->cond.w.length; i++) { - putchar(n->cc->cond.w.word[i]); - } + printCharClassWord(n->cc); if (n->state && n->nextState) { - printf("(%ld)->(%ld)\n",n->state->bitState.bitContainer,n->nextState->bitState.bitContainer); + printf("(0x%lx)->(0x%lx)\n",n->state->bitState.bitContainer,n->nextState->bitState.bitContainer); } else if (n->state) { - printf("(%ld)\n",n->state->bitState.bitContainer); + printf("(0x%lx)\n",n->state->bitState.bitContainer); } else { printf("\n"); }