Mercurial > hg > Applications > Grep
comparison regexParser/regexParser.cc @ 300:3e78631a6222
remove ragne list
author | Shinji KONO <kono@ie.u-ryukyu.ac.jp> |
---|---|
date | Wed, 03 Feb 2016 13:56:01 +0900 |
parents | 2f3e7bba038e |
children | 1188debbef10 |
comparison
equal
deleted
inserted
replaced
299:bdfe0a32c48f | 300:3e78631a6222 |
---|---|
43 cc->left = NULL; | 43 cc->left = NULL; |
44 cc->right = NULL; | 44 cc->right = NULL; |
45 cc->cond.w.word = ri->tokenValue; | 45 cc->cond.w.word = ri->tokenValue; |
46 cc->cond.w.length = ri->ptr - ri->tokenValue; | 46 cc->cond.w.length = ri->ptr - ri->tokenValue; |
47 cc->cond.range.begin = cc->cond.range.end = *ri->tokenValue; | 47 cc->cond.range.begin = cc->cond.range.end = *ri->tokenValue; |
48 cc->cond.range.next = NULL; | |
49 return cc; | 48 return cc; |
50 } | 49 } |
51 | 50 |
52 /* | 51 /* |
53 cond.range.begin cond.range.end | 52 cond.range.begin cond.range.end |
74 |----------------| | 73 |----------------| |
75 13. b--e | 74 13. b--e |
76 | 75 |
77 */ | 76 */ |
78 CharClassPtr insertCharClass(CharClassPtr cc, unsigned long begin, unsigned long end) { | 77 CharClassPtr insertCharClass(CharClassPtr cc, unsigned long begin, unsigned long end) { |
78 if (begin>end) { | |
79 unsigned long tmp = begin; begin = end; end = tmp; | |
80 } | |
79 if (cc == NULL) { | 81 if (cc == NULL) { |
80 createCharClassRange(begin,end,0,0,0); | 82 return createCharClassRange(begin,end,0,0,0); |
81 } | 83 } |
82 if (end < cc->cond.range.begin ) { // 1 | 84 if (end < cc->cond.range.begin ) { // 1 |
83 if (cc->left) { | 85 if (cc->left) { |
84 cc->left = insertCharClass(cc->left,begin,end); | 86 cc->left = insertCharClass(cc->left,begin,end); |
85 } else { | 87 } else { |
120 } | 122 } |
121 | 123 |
122 // <charClass> ::= '['<literal>'-'<literal>']' | 124 // <charClass> ::= '['<literal>'-'<literal>']' |
123 static | 125 static |
124 NodePtr charClass(RegexInfoPtr ri) { | 126 NodePtr charClass(RegexInfoPtr ri) { |
125 CharClassPtr cc = NEW(CharClass); | 127 CharClassPtr cc = NULL; |
126 NodePtr n = createNode(ri,'c',cc,0,0); | 128 NodePtr n = createNode(ri,'c',cc,0,0); |
127 cc->type = 'r'; | 129 unsigned char begin = *ri->ptr; |
128 cc->nextState.bitContainer = 0; | 130 unsigned char end = *ri->ptr; |
129 cc->left = NULL; | |
130 cc->right = NULL; | |
131 cc->stateNum = 0; | |
132 RangeListPtr rangeList = &cc->cond.range; | |
133 rangeList->begin = *ri->ptr; | |
134 rangeList->end = *ri->ptr; | |
135 rangeList->next = NULL; | |
136 | 131 |
137 for (ri->ptr++; *ri->ptr && *ri->ptr != ']'; ri->ptr++) { | 132 for (ri->ptr++; *ri->ptr && *ri->ptr != ']'; ri->ptr++) { |
138 if (*ri->ptr == '-') { | 133 if (*ri->ptr == '-') { |
139 rangeList->end = *(ri->ptr + 1); | 134 end = *(ri->ptr + 1); |
135 cc = insertCharClass(cc, begin, end); | |
140 ri->ptr++; | 136 ri->ptr++; |
141 continue; | 137 continue; |
138 } else { | |
139 cc = insertCharClass(cc, begin, end); | |
142 } | 140 } |
143 if (ri->ptr[0] == 0 || ri->ptr[0] == ']') break; | 141 if (ri->ptr[0] == 0 || ri->ptr[0] == ']') break; |
144 rangeList->next = NEW(RangeList); | 142 begin = *ri->ptr; |
145 rangeList = rangeList->next; | 143 end = *ri->ptr; |
146 rangeList->begin = *ri->ptr; | 144 } |
147 rangeList->end = *ri->ptr; | 145 n->cc = insertCharClass(cc, begin, end); |
148 rangeList->next = NULL; | |
149 } | |
150 | |
151 RangeListPtr r = cc->cond.range.next; | |
152 cc->cond.range.next = 0; | |
153 for (; r; r = r->next) { | |
154 cc = insertCharClass(cc, r->begin, r->end); | |
155 } | |
156 cc->cond.range.next = 0; | |
157 // TODO literal support | 146 // TODO literal support |
158 // merge rangeList here | 147 // merge rangeList here |
159 if (*ri->ptr) ri->ptr++; | 148 if (*ri->ptr) ri->ptr++; |
160 token(ri); | 149 token(ri); |
161 return n; | 150 return n; |