summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorOndrej Filip <feela@network.cz>2011-03-26 14:18:56 +0100
committerOndrej Filip <feela@network.cz>2011-03-26 14:18:56 +0100
commit4fc36f394ec0988a18decb2d1916e3cebef18d22 (patch)
tree5ce96a6f8b13574af35d1def832afd09ded45848 /filter
parentd0e9b36d30176a9e18cad6151b20746e1588cdc8 (diff)
This adds (*,x) functionality.
Diffstat (limited to 'filter')
-rw-r--r--filter/config.Y30
-rw-r--r--filter/test.conf31
2 files changed, 54 insertions, 7 deletions
diff --git a/filter/config.Y b/filter/config.Y
index b9aa67f8..d1dd081e 100644
--- a/filter/config.Y
+++ b/filter/config.Y
@@ -25,6 +25,19 @@ static int make_pair(int i1, int i2)
return (u1 << 16) | u2;
}
+struct f_tree *f_generate_rev_wcard(int from, int to, int expr)
+{
+ struct f_tree * ret = NULL;
+ if(from <= to) {
+ ret = f_new_tree();
+ ret->from.type = ret->to.type = T_PAIR;
+ ret->from.val.i = ret->to.val.i = make_pair(from, expr);
+ ret->left = f_generate_rev_wcard(from+1, to, expr);
+ }
+ return ret;
+
+}
+
CF_DECLS
CF_KEYWORDS(FUNCTION, PRINT, PRINTN, UNSET, RETURN,
@@ -229,10 +242,10 @@ fipa:
;
set_atom:
- expr { $$.type = T_INT; $$.val.i = $1; }
+ expr { $$.type = T_INT; $$.val.i = $1; } /* 'SYM' included in 'expr' creates 3 reduce/shift conflicts */
| RTRID { $$.type = T_QUAD; $$.val.i = $1; }
| fipa { $$ = $1; }
- | ENUM { $$.type = $1 >> 16; $$.val.i = $1 & 0xffff; }
+ | ENUM { $$.type = $1 >> 16; $$.val.i = $1 & 0xffff; }
;
set_item:
@@ -254,12 +267,25 @@ set_item:
$$->from.val.i = make_pair($2, $4);
$$->to.val.i = make_pair($9, $11);
}
+ | '(' '*' ',' '*' ')' { /* This is probably useless :-) */
+ $$ = f_new_tree();
+ $$->from.type = $$->to.type = T_PAIR;
+ $$->from.val.i = 0;
+ $$->to.val.i = 0xffffffff;
+ }
| '(' expr ',' '*' ')' {
$$ = f_new_tree();
$$->from.type = $$->to.type = T_PAIR;
$$->from.val.i = make_pair($2, 0);
$$->to.val.i = make_pair($2, 0xffff);
}
+ | '(' '*' ',' expr ')' {
+ $$ = f_generate_rev_wcard(0, 0xffff, $4);
+ }
+ /* This causes 3 reduce/reduce conflicts
+ | '(' expr '.' '.' expr ',' expr ')' {
+ cf_error("Not implemented yet");
+ }*/
| set_atom {
$$ = f_new_tree();
$$->from = $1;
diff --git a/filter/test.conf b/filter/test.conf
index fd025ca5..b4d34000 100644
--- a/filter/test.conf
+++ b/filter/test.conf
@@ -11,6 +11,11 @@ define xyzzy = (120+10);
define '1a-a1' = (20+10);
define one = 1;
+function onef(int a)
+{
+ return 1;
+}
+
function 'mkpair-a'(int a)
{
@@ -31,8 +36,9 @@ int i;
i = arg2;
case arg1 {
- 2: printn "dva, "; printn "jeste jednou dva";
- 3 .. 5: if arg2 < 3 then printn "tri az pet";
+ one: printn "jedna, "; printn "jedna";
+ (one+onef(2)): printn "dva, "; printn "jeste jednou dva";
+ (2+one) .. 5: if arg2 < 3 then printn "tri az pet";
else: printn "neco jineho";
}
print;
@@ -78,7 +84,9 @@ clist l;
print "Should be true: ", p2 ~ pm1, " ", p2, " ", pm1;
l = - empty -;
+ print "Should be false in this special case: ", l ~ [(*,*)];
l = add( l, (one,2) );
+ print "Should be always true: ", l ~ [(*,*)];
l = add( l, (2,one+2) );
print "Community list (1,2) (2,3) ", l;
print "Should be true: ", (2,3) ~ l, " ", l ~ [(1,*)], " ", l ~ [(2,3)]," ", l ~ [(2,2..3)], " ", l ~ [(1,1..2)], " ", l ~ [(1,1)..(1,2)];
@@ -91,6 +99,7 @@ clist l;
l = delete( l, [(2,*)] );
print "Community list (1,2) ", l;
print "Should be false: ", (2,3) ~ l, " ", l ~ [(2,*)], " ", l ~ [(one,3..6)];
+ print "Should be always true: ", l ~ [(*,*)];
l = add( l, (3,one) );
l = add( l, (one+one+one,one+one) );
l = add( l, (3,3) );
@@ -98,6 +107,16 @@ clist l;
l = add( l, (3,5) );
l = delete( l, [(3,2..4)] );
print "Community list (1,2) (3,1) (3,5) ", l;
+ l = add( l, (3,2) );
+ l = add( l, (4,5) );
+ print "Community list (1,2) (3,1) (3,2) (3,5) (4,5) ", l;
+ print "Should be true: ", l ~ [(*,2)], " ", l ~ [(*,5)], " ", l ~ [(*, one)];
+ print "Should be false: ", l ~ [(*,3)], " ", l ~ [(*,(one+6))], " ", l ~ [(*, (one+one+one))];
+ l = delete( l, [(*,(one+onef(3)))] );
+ l = delete( l, [(*,(4+one))] );
+ print "Community list (3,1) ", l;
+ l = delete( l, [(*,(onef(5)))] );
+ print "Community list empty ", l;
}
function bla()
@@ -185,8 +204,10 @@ string s;
print " must be true: ", defined(1), ",", defined(1.2.3.4), ",", 1 != 2, ",", 1 <= 2;
print " data types: must be false: ", 1 ~ [ 2, 3, 4 ], ",", 5 ~ is, ",", 1.2.3.4 ~ [ 1.2.3.3, 1.2.3.5 ], ",", (1,2) > (2,2), ",", (1,1) > (1,1), ",", 1.0.0.0/9 ~ [ 1.0.0.0/8- ], ",", 1.2.0.0/17 ~ [ 1.0.0.0/8{ 15 , 16 } ], ",", true && false;
- is1 = [one, (2+1), (6-one), 8, 11, 15, 17, 19];
- is2 = [19, 17, 15, 11, 8, 5, 3, 2];
+ is1 = [ 1, 5, 8, 11, 15, 17, 19];
+
+ is1 = [ one, (2+1), (6-one), 8, 11, 15, 17, 19];
+ is2 = [(17+2), 17, 15, 11, 8, 5, 3, 2];
is3 = [5, 17, 2, 11, 8, 15, 3, 19];
print " must be true: ", 1 ~ is1, " ", 3 ~ is1, " ", 5 ~ is1;
@@ -244,7 +265,7 @@ string s;
print "What will this do? ", [ 1, 2, 1, 1, 1, 3, 4, 1, 1, 1, 5 ];
print "Testing functions...";
-# callme ( 1, 2 );
+ callme ( 1, 2 );
callme ( 2, 2 );
callme ( 2, 2 );
callme ( 3, 2 );