diff --git a/conf/cf-lex.l b/conf/cf-lex.l index c6e9a0ea..828dfd25 100644 --- a/conf/cf-lex.l +++ b/conf/cf-lex.l @@ -137,6 +137,11 @@ WHITE [ \t] return NUM; } +else: { + /* Hack to distinguish if..else from else: in case */ + return ELSECOL; +} + ({ALPHA}{ALNUM}*|[']({ALNUM}|[-])*[']) { if(*yytext == '\'') { yytext[yyleng-1] = 0; diff --git a/conf/confbase.Y b/conf/confbase.Y index ce844ba5..68960c2e 100644 --- a/conf/confbase.Y +++ b/conf/confbase.Y @@ -48,7 +48,7 @@ CF_DECLS struct timeformat *tf; } -%token END CLI_MARKER INVALID_TOKEN +%token END CLI_MARKER INVALID_TOKEN ELSECOL %token GEQ LEQ NEQ AND OR %token PO PC %token NUM ENUM diff --git a/doc/bird.sgml b/doc/bird.sgml index 7b6e97ab..b5bdb932 100644 --- a/doc/bird.sgml +++ b/doc/bird.sgml @@ -837,7 +837,7 @@ prefix and prefix (returning true if first prefix is more specific than second o command_1; command_2; ... } instead of either command. The else clause may be omitted. If the boolean expression is true, command1 is executed, otherwise command2 is executed. -

The case is similar to case from Pascal. Syntax is case The case is similar to case from Pascal. Syntax is case . The expression after case can be of any type which can be on the left side of the ˜ operator and anything that could be a member of a set is allowed before data = $4; $$->left = $1; } - | switch_body ELSE ':' cmds { + | switch_body ELSECOL cmds { $$ = f_new_tree(); $$->from.type = T_VOID; $$->to.type = T_VOID; - $$->data = $4; + $$->data = $3; $$->left = $1; } ; diff --git a/filter/test.conf b/filter/test.conf index 40fff19b..6d7a7082 100644 --- a/filter/test.conf +++ b/filter/test.conf @@ -27,14 +27,15 @@ int local1; int local2; int i; { - printn "Function callme called arguments ", arg1, " and ", arg2, ":" ; + printn "Function callme called arguments ", arg1, " and ", arg2, ": " ; i = arg2; case arg1 { - 2: print "dva"; print "jeste jednou dva"; - 3 .. 5: print "tri az pet"; - else: print "neco jineho"; - } + 2: printn "dva, "; printn "jeste jednou dva"; + 3 .. 5: if arg2 < 3 then printn "tri az pet"; + else: printn "neco jineho"; + } + print; } function fifteen() @@ -247,7 +248,7 @@ string s; callme ( 2, 2 ); callme ( 2, 2 ); callme ( 3, 2 ); - callme ( 4, 2 ); + callme ( 4, 4 ); callme ( 7, 2 ); i = fifteen();