Mercurial > hg > Members > masakoha > testcode
changeset 300:3e78631a6222
remove ragne list
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Feb 2016 13:56:01 +0900 |
parents | bdfe0a32c48f |
children | 4cb6eea3ab12 |
files | regexParser/node.cc regexParser/regexParser.cc regexParser/regexParser.h regexParser/subsetConstruction.cc |
diffstat | 4 files changed, 16 insertions(+), 35 deletions(-) [+] |
line wrap: on
line diff
--- a/regexParser/node.cc Wed Feb 03 13:11:10 2016 +0900 +++ b/regexParser/node.cc Wed Feb 03 13:56:01 2016 +0900 @@ -9,14 +9,8 @@ printCharacterClass(cc->left,nodeNumber,d+1); } printf("%*c",d*4, ' '); - for (RangeList range = cc->cond.range; range.begin != 0;) { - printf("[%c-%c] ",(unsigned char)range.begin,(unsigned char)range.end); - if (range.next != NULL) { - range = *range.next; - } else { - break; - } - } + 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);
--- a/regexParser/regexParser.cc Wed Feb 03 13:11:10 2016 +0900 +++ b/regexParser/regexParser.cc Wed Feb 03 13:56:01 2016 +0900 @@ -45,7 +45,6 @@ cc->cond.w.word = ri->tokenValue; cc->cond.w.length = ri->ptr - ri->tokenValue; cc->cond.range.begin = cc->cond.range.end = *ri->tokenValue; - cc->cond.range.next = NULL; return cc; } @@ -76,8 +75,11 @@ */ CharClassPtr insertCharClass(CharClassPtr cc, unsigned long begin, unsigned long end) { + if (begin>end) { + unsigned long tmp = begin; begin = end; end = tmp; + } if (cc == NULL) { - createCharClassRange(begin,end,0,0,0); + return createCharClassRange(begin,end,0,0,0); } if (end < cc->cond.range.begin ) { // 1 if (cc->left) { @@ -122,38 +124,25 @@ // <charClass> ::= '['<literal>'-'<literal>']' static NodePtr charClass(RegexInfoPtr ri) { - CharClassPtr cc = NEW(CharClass); + CharClassPtr cc = NULL; NodePtr n = createNode(ri,'c',cc,0,0); - cc->type = 'r'; - cc->nextState.bitContainer = 0; - cc->left = NULL; - cc->right = NULL; - cc->stateNum = 0; - RangeListPtr rangeList = &cc->cond.range; - rangeList->begin = *ri->ptr; - rangeList->end = *ri->ptr; - rangeList->next = NULL; + unsigned char begin = *ri->ptr; + unsigned char end = *ri->ptr; for (ri->ptr++; *ri->ptr && *ri->ptr != ']'; ri->ptr++) { if (*ri->ptr == '-') { - rangeList->end = *(ri->ptr + 1); + end = *(ri->ptr + 1); + cc = insertCharClass(cc, begin, end); ri->ptr++; continue; + } else { + cc = insertCharClass(cc, begin, end); } if (ri->ptr[0] == 0 || ri->ptr[0] == ']') break; - rangeList->next = NEW(RangeList); - rangeList = rangeList->next; - rangeList->begin = *ri->ptr; - rangeList->end = *ri->ptr; - rangeList->next = NULL; + begin = *ri->ptr; + end = *ri->ptr; } - - RangeListPtr r = cc->cond.range.next; - cc->cond.range.next = 0; - for (; r; r = r->next) { - cc = insertCharClass(cc, r->begin, r->end); - } - cc->cond.range.next = 0; + n->cc = insertCharClass(cc, begin, end); // TODO literal support // merge rangeList here if (*ri->ptr) ri->ptr++;
--- a/regexParser/regexParser.h Wed Feb 03 13:11:10 2016 +0900 +++ b/regexParser/regexParser.h Wed Feb 03 13:56:01 2016 +0900 @@ -19,7 +19,6 @@ typedef struct utf8Range { unsigned long begin; unsigned long end; - struct utf8Range *next; // only used in the parser. } RangeList , *RangeListPtr; typedef struct condition {
--- a/regexParser/subsetConstruction.cc Wed Feb 03 13:11:10 2016 +0900 +++ b/regexParser/subsetConstruction.cc Wed Feb 03 13:56:01 2016 +0900 @@ -15,7 +15,6 @@ cc->type = 'r'; cc->cond.range.begin = begin; cc->cond.range.end = end; - cc->cond.range.next = NULL; cc->cond.w.word = NULL; cc->cond.w.length = 0; cc->left = left;