|
@ -20,7 +20,7 @@ void fatal(char *fmt, ...) |
|
|
exit(1); |
|
|
exit(1); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
enum op { String, Query, Star, Plus, Or, And, Class, Dot, Exc, Id } ; |
|
|
|
|
|
|
|
|
enum op { String, Query, Star, Plus, Or, And, Class, Dot, Exc, Et, Id} ; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
typedef union Node Node; |
|
|
typedef union Node Node; |
|
@ -41,6 +41,7 @@ struct And { enum op type; Node *children[2]; }; |
|
|
struct Class { enum op type; char *stringValue; int len; }; |
|
|
struct Class { enum op type; char *stringValue; int len; }; |
|
|
struct Dot { enum op type; }; |
|
|
struct Dot { enum op type; }; |
|
|
struct Exc { enum op type; Node *children[1]; }; |
|
|
struct Exc { enum op type; Node *children[1]; }; |
|
|
|
|
|
struct Et { enum op type; Node *children[1]; }; |
|
|
struct Id { enum op type; Symbol *symbol; }; |
|
|
struct Id { enum op type; Symbol *symbol; }; |
|
|
|
|
|
|
|
|
union Node { |
|
|
union Node { |
|
@ -54,6 +55,7 @@ union Node { |
|
|
struct Class Class; |
|
|
struct Class Class; |
|
|
struct Dot Dot; |
|
|
struct Dot Dot; |
|
|
struct Exc Exc; |
|
|
struct Exc Exc; |
|
|
|
|
|
struct Et Et; |
|
|
struct Id Id; |
|
|
struct Id Id; |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
@ -163,6 +165,13 @@ Node *mkExc(Node *n) |
|
|
return node; |
|
|
return node; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
Node *mkEt(Node *n) |
|
|
|
|
|
{ |
|
|
|
|
|
Node *node= new(Et); |
|
|
|
|
|
node->Et.children[0]= n; |
|
|
|
|
|
return node; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
Node *_checktype(Node *object, enum op type) |
|
|
Node *_checktype(Node *object, enum op type) |
|
|
{ |
|
|
{ |
|
|
if (object->type == type) return object; |
|
|
if (object->type == type) return object; |
|
@ -211,6 +220,10 @@ void print(Node *node) |
|
|
printf("!"); |
|
|
printf("!"); |
|
|
print(node->Exc.children[0]); |
|
|
print(node->Exc.children[0]); |
|
|
return; |
|
|
return; |
|
|
|
|
|
case Et: |
|
|
|
|
|
printf("&"); |
|
|
|
|
|
print(node->Et.children[0]); |
|
|
|
|
|
return; |
|
|
case Id: |
|
|
case Id: |
|
|
printf("%s\n",get(node,Id,symbol)->name); |
|
|
printf("%s\n",get(node,Id,symbol)->name); |
|
|
return; |
|
|
return; |
|
@ -288,6 +301,7 @@ and = p:prefix a:and { $$ = mkAnd(p, a) } |
|
|
| p:prefix { $$ = p } |
|
|
| p:prefix { $$ = p } |
|
|
|
|
|
|
|
|
prefix = "!" - p : postfix { $$ = mkExc(p) } |
|
|
prefix = "!" - p : postfix { $$ = mkExc(p) } |
|
|
|
|
|
| "&" - p : postfix { $$ = mkEt(p) } |
|
|
| p: postfix { $$ = p} |
|
|
| p: postfix { $$ = p} |
|
|
|
|
|
|
|
|
postfix = s:atom ( "?" - { s = mkQuery(s) } |
|
|
postfix = s:atom ( "?" - { s = mkQuery(s) } |
|
@ -374,6 +388,14 @@ int execute(Node *node, InputBuffer *in) |
|
|
setPosition(in, pos); |
|
|
setPosition(in, pos); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|
|
|
|
case Et: { |
|
|
|
|
|
int pos= getPosition(in); |
|
|
|
|
|
if (!execute(get(node,Et,children[0]), in)) { |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
setPosition(in, pos); |
|
|
|
|
|
return 1; |
|
|
|
|
|
} |
|
|
case Dot: { |
|
|
case Dot: { |
|
|
if (atEnd(in)) { |
|
|
if (atEnd(in)) { |
|
|
return 0; |
|
|
return 0; |
|
|