Browse Source

[4271] Fixed parser

Francis Dupont 8 years ago
parent
commit
86ad729e81
1 changed files with 118 additions and 102 deletions
  1. 118 102
      src/lib/eval/parser.yy

+ 118 - 102
src/lib/eval/parser.yy

@@ -167,33 +167,33 @@ bool_expr : "(" bool_expr ")"
                     }
                     }
                 }
                 }
           | VENDOR_CLASS "[" enterprise_id "]" "." EXISTS
           | VENDOR_CLASS "[" enterprise_id "]" "." EXISTS
-          {
-              // Expression: vendor-class[1234].exists
-              //
-              // This token will find option 124 (DHCPv4) or 16 (DHCPv6), and will check
-              // if enterprise-id equals specified value.
-              TokenPtr exist(new TokenVendorClass(ctx.getUniverse(), $3, TokenOption::EXISTS));
-              ctx.expression.push_back(exist);
-          }
+              {
+                  // Expression: vendor-class[1234].exists
+                  //
+                  // This token will find option 124 (DHCPv4) or 16 (DHCPv6),
+                  // and will check if enterprise-id equals specified value.
+                  TokenPtr exist(new TokenVendorClass(ctx.getUniverse(), $3, TokenOption::EXISTS));
+                  ctx.expression.push_back(exist);
+              }
           | VENDOR "[" enterprise_id "]" "." EXISTS
           | VENDOR "[" enterprise_id "]" "." EXISTS
-          {
-              // Expression: vendor[1234].exists
-              //
-              // This token will find option 125 (DHCPv4) or 17 (DHCPv6), and will check
-              // if enterprise-id equals specified value.
-              TokenPtr exist(new TokenVendor(ctx.getUniverse(), $3, TokenOption::EXISTS));
-              ctx.expression.push_back(exist);
-
-          }
+              {
+                  // Expression: vendor[1234].exists
+                  //
+                  // This token will find option 125 (DHCPv4) or 17 (DHCPv6),
+                  // and will check if enterprise-id equals specified value.
+                  TokenPtr exist(new TokenVendor(ctx.getUniverse(), $3, TokenOption::EXISTS));
+                  ctx.expression.push_back(exist);
+              }
           | VENDOR "[" enterprise_id "]" "." OPTION "[" option_code "]" "." EXISTS
           | VENDOR "[" enterprise_id "]" "." OPTION "[" option_code "]" "." EXISTS
-          {
-              // Expression vendor[1234].option[123].exists
-              //
-              // This token will check if specified vendor option exists, has specified
-              // enterprise-id and if has specified suboption.
-              TokenPtr exist(new TokenVendor(ctx.getUniverse(), $3, TokenOption::EXISTS, $8));
-              ctx.expression.push_back(exist);
-          }
+              {
+                  // Expression vendor[1234].option[123].exists
+                  //
+                  // This token will check if specified vendor option
+                  // exists, has specified enterprise-id and if has
+                  // specified suboption.
+                  TokenPtr exist(new TokenVendor(ctx.getUniverse(), $3, TokenOption::EXISTS, $8));
+                  ctx.expression.push_back(exist);
+               }
           ;
           ;
 
 
 string_expr : STRING
 string_expr : STRING
@@ -287,58 +287,61 @@ string_expr : STRING
                       TokenPtr conc(new TokenConcat());
                       TokenPtr conc(new TokenConcat());
                       ctx.expression.push_back(conc);
                       ctx.expression.push_back(conc);
                   }
                   }
-          | VENDOR "." ENTERPRISE
-          {
-              // expression: vendor.enterprise
-              //
-              // This token will return enterprise-id number of received vendor option.
-              TokenPtr vendor(new TokenVendor(ctx.getUniverse(), 0, TokenVendor::ENTERPRISE_ID));
-              ctx.expression.push_back(vendor);
-          }
-          | VENDOR_CLASS "." ENTERPRISE
-          {
-              // expression: vendor-class.enterprise
-              //
-              // This token will return enterprise-id number of received vendor class option.
-              TokenPtr vendor(new TokenVendorClass(ctx.getUniverse(), 0,
-                                                   TokenVendor::ENTERPRISE_ID));
-              ctx.expression.push_back(vendor);
-          }
-          | VENDOR "[" enterprise_id "]" "." OPTION "[" option_code "]" "." option_repr_type
-          {
-              // expression: vendor[1234].option[56].exists
-              // expression: vendor[1234].option[56].hex
-              //
-              // This token will search for vendor option with specified enterprise-id.
-              // If found, will search for specified suboption and finally will return
-              // if it exists ('exists') or its content ('hex')
-              TokenPtr opt(new TokenVendor(ctx.getUniverse(), $3, $11, $8));
-              ctx.expression.push_back(opt);
-          }
-          | VENDOR_CLASS "[" enterprise_id "]" "." DATA
-          {
-              // expression: vendor-class[1234].data
-              //
-              // Vendor class option does not have suboptions, but chunks of data (typically 1,
-              // but the option structure allows multiple of them). If chunk offset is not
-              // specified, we assume the first (0th) is requested.
-              TokenPtr vendor_class(new TokenVendorClass(ctx.getUniverse(), $3,
-                                                         TokenVendor::DATA, 0));
-              ctx.expression.push_back(vendor_class);
-          }
-          | VENDOR_CLASS "[" enterprise_id "]" "." DATA "[" INTEGER "]"
-          {
-              // expression: vendor-class[1234].data[5]
-              //
-              // Vendor class option does not have suboptions, but chunks of data (typically 1,
-              // but the option structure allows multiple of them). This syntax specifies
-              // which data chunk (tuple) we want.
-              uint8_t index = ctx.convertUint8($8, @8);
-              TokenPtr vendor_class(new TokenVendorClass(ctx.getUniverse(), $3,
-                                                         TokenVendor::DATA, index));
-              ctx.expression.push_back(vendor_class);
-          }
-          ;
+            | VENDOR "." ENTERPRISE
+                {
+                    // expression: vendor.enterprise
+                    //
+                    // This token will return enterprise-id number of
+                    // received vendor option.
+                    TokenPtr vendor(new TokenVendor(ctx.getUniverse(), 0, TokenVendor::ENTERPRISE_ID));
+                    ctx.expression.push_back(vendor);
+                }
+            | VENDOR_CLASS "." ENTERPRISE
+                {
+                    // expression: vendor-class.enterprise
+                    //
+                    // This token will return enterprise-id number of
+                    // received vendor class option.
+                    TokenPtr vendor(new TokenVendorClass(ctx.getUniverse(), 0,
+                                                         TokenVendor::ENTERPRISE_ID));
+                    ctx.expression.push_back(vendor);
+                }
+            | VENDOR "[" enterprise_id "]" "." OPTION "[" option_code "]" "." option_repr_type
+                {
+                    // This token will search for vendor option with
+                    // specified enterprise-id.  If found, will search
+                    // for specified suboption and finally will return
+                    // its content.
+                    TokenPtr opt(new TokenVendor(ctx.getUniverse(), $3, $11, $8));
+                    ctx.expression.push_back(opt);
+                }
+            | VENDOR_CLASS "[" enterprise_id "]" "." DATA
+                {
+                    // expression: vendor-class[1234].data
+                    //
+                    // Vendor class option does not have suboptions,
+                    // but chunks of data (typically 1, but the option
+                    // structure allows multiple of them). If chunk
+                    // offset is not specified, we assume the first (0th)
+                    // is requested.
+                    TokenPtr vendor_class(new TokenVendorClass(ctx.getUniverse(), $3,
+                                                               TokenVendor::DATA, 0));
+                    ctx.expression.push_back(vendor_class);
+                }
+            | VENDOR_CLASS "[" enterprise_id "]" "." DATA "[" INTEGER "]"
+                {
+                    // expression: vendor-class[1234].data[5]
+                    //
+                    // Vendor class option does not have suboptions,
+                    // but chunks of data (typically 1, but the option
+                    // structure allows multiple of them). This syntax
+                    // specifies which data chunk (tuple) we want.
+                    uint8_t index = ctx.convertUint8($8, @8);
+                    TokenPtr vendor_class(new TokenVendorClass(ctx.getUniverse(), $3,
+                                                               TokenVendor::DATA, index));
+                    ctx.expression.push_back(vendor_class);
+                }
+            ;
 
 
 option_code : INTEGER
 option_code : INTEGER
                  {
                  {
@@ -361,13 +364,14 @@ option_repr_type : TEXT
                  ;
                  ;
 
 
 enterprise_id : INTEGER
 enterprise_id : INTEGER
-{
-    $$ = ctx.convertUint32($1, @1);
-}
-| "*"
-{
-    $$ = 0;
-}
+                   {
+                       $$ = ctx.convertUint32($1, @1);
+                   }
+              | "*"
+                   {
+                       $$ = 0;
+                   }
+              ;
 
 
 pkt4_field : CHADDR
 pkt4_field : CHADDR
                 {
                 {
@@ -400,17 +404,17 @@ pkt4_field : CHADDR
            ;
            ;
 
 
 start_expr : INTEGER
 start_expr : INTEGER
+                {
+                    TokenPtr str(new TokenString($1));
+                    ctx.expression.push_back(str);
+                }
+           ;
+
+length_expr : INTEGER
                  {
                  {
                      TokenPtr str(new TokenString($1));
                      TokenPtr str(new TokenString($1));
                      ctx.expression.push_back(str);
                      ctx.expression.push_back(str);
                  }
                  }
-           ;
-
-length_expr : INTEGER
-                  {
-                      TokenPtr str(new TokenString($1));
-                      ctx.expression.push_back(str);
-                  }
             | ALL
             | ALL
                  {
                  {
                      TokenPtr str(new TokenString("all"));
                      TokenPtr str(new TokenString("all"));
@@ -418,22 +422,34 @@ length_expr : INTEGER
                  }
                  }
             ;
             ;
 
 
-relay6_field : PEERADDR { $$ = TokenRelay6Field::PEERADDR; }
-             | LINKADDR { $$ = TokenRelay6Field::LINKADDR; }
+relay6_field : PEERADDR
+                  {
+                      $$ = TokenRelay6Field::PEERADDR;
+                  }
+             | LINKADDR
+                  {
+                      $$ = TokenRelay6Field::LINKADDR;
+                  }
              ;
              ;
 
 
 nest_level : INTEGER
 nest_level : INTEGER
-                 {
-                 $$ = ctx.convertNestLevelNumber($1, @1);
-                 }
-                 // Eventually we may add strings to handle different
-                 // ways of choosing from which relay we want to extract
-                 // an option or field.
+                {
+                    $$ = ctx.convertNestLevelNumber($1, @1);
+                }
+                // Eventually we may add strings to handle different
+                // ways of choosing from which relay we want to extract
+                // an option or field.
            ;
            ;
 
 
-pkt6_field:MSGTYPE { $$ = TokenPkt6::MSGTYPE; }
-          | TRANSID { $$ = TokenPkt6::TRANSID; }
-          ;
+pkt6_field : MSGTYPE
+                {
+                    $$ = TokenPkt6::MSGTYPE;
+                }
+           | TRANSID
+                {
+                    $$ = TokenPkt6::TRANSID;
+                }
+           ;
 
 
 %%
 %%
 void
 void