zeek / spicy

C++ parser generator for dissecting protocols & files.
https://docs.zeek.org/projects/spicy
Other
246 stars 35 forks source link

Add support for `if` to group unit items #1841

Open rsmmr opened 3 weeks ago

rsmmr commented 3 weeks ago

Support if-blocks in unit.

We now support if around a block of unit items:

    type X = unit {
         x: uint8;

         if ( self.x == 1 ) {
             a1: bytes &size=2;
             a2: bytes &size=2;
         };
    };

if supports the same attributes right after the closing } as switch does. For example, the following works:

         if ( self.x == 1 ) {
             x: bytes &eod;
         } &size=10;

TODO:

Closes #1839.

rsmmr commented 2 weeks ago

Updates this to align syntax with switch: Requiring semicolon at the end and supporting the same attributes (&size, &parse-*) on the whole block. PR description updated accordingly.

I think the main question at this point is if we want/like this syntax. Feedback welcome.