Mercurial > hg > Applications > Grep
comparison c/regexParser/regexParser.cc @ 126:639b0b437ebf pairPro
remove error (do not work)
author | masa |
---|---|
date | Tue, 01 Dec 2015 21:42:05 +0900 |
parents | 4d6ac69801ad |
children | b061cd8205cc |
comparison
equal
deleted
inserted
replaced
125:4d6ac69801ad | 126:639b0b437ebf |
---|---|
4 #include <ctype.h> | 4 #include <ctype.h> |
5 #include "regexParser.h" | 5 #include "regexParser.h" |
6 #include "error.h" | 6 #include "error.h" |
7 | 7 |
8 static NodePtr allocateNode(); | 8 static NodePtr allocateNode(); |
9 static NodePtr createNode(RegexInfoPtr,unsigned char*,NodePtr,NodePtr); | 9 static NodePtr createNode(RegexInfoPtr,unsigned char,NodePtr,NodePtr); |
10 static NodePtr charClass(RegexInfoPtr); | 10 static NodePtr charClass(RegexInfoPtr); |
11 static NodePtr group(RegexInfoPtr); | 11 static NodePtr group(RegexInfoPtr); |
12 static void token(RegexInfoPtr); | 12 static void token(RegexInfoPtr); |
13 static NodePtr regexAtom(RegexInfoPtr); | 13 static NodePtr regexAtom(RegexInfoPtr); |
14 NodePtr regex(RegexInfoPtr); | 14 NodePtr regex(RegexInfoPtr); |
28 n->right = NULL; | 28 n->right = NULL; |
29 return n; | 29 return n; |
30 } | 30 } |
31 | 31 |
32 static | 32 static |
33 CharClassPtr createChaClassWord(RegexInfoPtr ri) { | 33 CharClassPtr createCharClassWord(RegexInfoPtr ri) { |
34 CharClassPtr cc = NEW(CharClass); | 34 CharClassPtr cc = NEW(CharClass); |
35 cc->type = 'a'; | 35 cc->type = 'a'; |
36 cc->cond = NEW(Condition); | 36 cc->cond = NEW(Condition); |
37 cc->cond->w = NEW(Word); | 37 cc->cond->w = NEW(Word); |
38 cc->cond->w->word = ri->tokenValue; | 38 cc->cond->w->word = ri->tokenValue; |
39 cc->cond->w->length = ri->ptr - ri->tokenValue; | 39 cc->cond->w->length = ri->ptr - ri->tokenValue; |
40 | |
41 return cc; | |
40 } | 42 } |
41 | 43 |
42 static | 44 static |
43 NodePtr createNode(RegexInfoPtr ri,unsigned char type, NodePtr left, NodePtr right) { | 45 NodePtr createNode(RegexInfoPtr ri,unsigned char type, NodePtr left, NodePtr right) { |
44 NodePtr n = allocateNode(); | 46 NodePtr n = allocateNode(); |
65 n->tokenType = 'c'; | 67 n->tokenType = 'c'; |
66 n->nodeNumber = ri->nodeNumber; | 68 n->nodeNumber = ri->nodeNumber; |
67 ri->nodeNumber++; | 69 ri->nodeNumber++; |
68 | 70 |
69 CharClassPtr cc = NEW(CharClass); | 71 CharClassPtr cc = NEW(CharClass); |
72 cc->type = 'r'; | |
70 cc->cond = NEW(Condition); | 73 cc->cond = NEW(Condition); |
71 cc->cond->type = 'r'; | 74 cc->cond->range = NEW(RangeList); |
72 cc->cond->rangeList = NEW(struct utf8Range); | 75 cc->cond->range->begin = ri->ptr; |
73 cc->cond->rangeList->begin = ri->ptr; | 76 cc->cond->range->end = ri->ptr + 1; |
74 cc->cond->rangeList->end = ri->ptr + 1; | 77 cc->cond->range->next = NULL; |
75 cc->cond->rangeList->next = NULL; | |
76 | 78 |
77 int i = 0; | 79 int i = 0; |
78 | 80 |
79 struct utf8Range *rangeList= cc->cond->rangeList; | 81 RangeListPtr rangeList = cc->cond->range; |
80 | 82 |
81 while (ri->ptr[i] != ']') { | 83 while (ri->ptr[i] != ']') { |
82 if (ri->ptr[i] == '-') i++; | 84 if (ri->ptr[i] == '-') i++; |
83 | 85 |
84 rangeList->end = ri->ptr + i; | 86 rangeList->end = ri->ptr + i; |
85 rangeList->next = NEW(struct utf8Range); | 87 rangeList->next = NEW(RangeList); |
86 rangeList = rangeList->next; | 88 rangeList = rangeList->next; |
87 rangeList->begin = ri->ptr+i+1; | 89 rangeList->begin = ri->ptr+i+1; |
88 rangeList->next = NULL; | 90 rangeList->next = NULL; |
89 i++; | 91 i++; |
90 } | 92 } |
91 | 93 |
92 rangeList->end = ri->ptr[i-1]; | 94 rangeList->end = ri->ptr + i - 1; |
93 | 95 |
94 return n; | 96 return n; |
95 } | 97 } |
96 | 98 |
97 // <literal> ::= [a-z][A-Z][0-9] | 99 // <literal> ::= [a-z][A-Z][0-9] |
98 static | 100 static |
99 NodePtr literal(RegexInfoPtr ri) { | 101 NodePtr literal(RegexInfoPtr ri) { |
100 NodePtr n = createNode(ri,ri->ptr,0,0); | 102 NodePtr n = createNode(ri,'a',0,0); |
101 return n; | 103 return n; |
102 } | 104 } |
103 | 105 |
104 // <group> ::= '('<regex>')' | 106 // <group> ::= '('<regex>')' |
105 static | 107 static |