]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
A hack to distinguish if..else from else: in case.
authorOndrej Zajicek <santiago@crfreenet.org>
Wed, 23 Mar 2011 11:49:53 +0000 (12:49 +0100)
committerOndrej Zajicek <santiago@crfreenet.org>
Wed, 23 Mar 2011 11:49:53 +0000 (12:49 +0100)
The old BIRD grammar needs two lookaheads to distinguish if..else from
else: in case, which caused the parser to fail on some combinations of
both expressions.

This patch replaces two tokens 'else' ':' by one token 'else:' to fix
that.

conf/cf-lex.l
conf/confbase.Y
doc/bird.sgml
filter/config.Y
filter/test.conf

index c6e9a0ea022f8ba4cf00fcdd5cc5f61f9f6704be..828dfd25ff13db7cebea49541a4809472196b953 100644 (file)
@@ -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;
index ce844ba5fcec2cd83f1c57a44bb86454076265c6..68960c2e542d5e40fdb2922452f4acb8c50021a9 100644 (file)
@@ -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 <i> NUM ENUM
index 7b6e97ab166f539258363bf898f19be92eda41e9..b5bdb9323cf90bd24e37daecc5a38702d15af7b6 100644 (file)
@@ -837,7 +837,7 @@ prefix and prefix (returning true if first prefix is more specific than second o
 <M>command_1</M>; <M>command_2</M>; <M>...</M> }</cf> instead of either command. The <cf>else</cf>
 clause may be omitted. If the <cf><m>boolean expression</m></cf> is true, <cf><m>command1</m></cf> is executed, otherwise <cf><m>command2</m></cf> is executed.
 
-<p>The <cf>case</cf> is similar to case from Pascal. Syntax is <cf>case <m/expr/ { else |
+<p>The <cf>case</cf> is similar to case from Pascal. Syntax is <cf>case <m/expr/ { else: |
 <m/num_or_prefix [ .. num_or_prefix]/: <m/statement/ ; [ ... ] }</cf>. The expression after
 <cf>case</cf> can be of any type which can be on the left side of the &tilde; operator and anything that could
 be a member of a set is allowed before <cf/:/. Multiple commands are allowed without <cf/{}/ grouping.
index 8ff20466aaff119e3955dcada97730b9a17e192f..b9aa67f841214366680c85a9d7912bfb2cacb63b 100644 (file)
@@ -305,11 +305,11 @@ switch_body: /* EMPTY */ { $$ = NULL; }
      $$->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;
    }
  ;
index 40fff19b66c06f0d52d392181706c58bc29770e8..6d7a7082bca6dcb0d30a29a8e6630c3410a49288 100644 (file)
@@ -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();