skx / evalfilter

A bytecode-based virtual machine to implement scripting/filtering support in your golang project.
GNU General Public License v2.0
117 stars 12 forks source link

Allow better support for if .. else if .. #171

Closed skx closed 3 years ago

skx commented 3 years ago

Currently our if support only allows blocks, like so:

    if ( true ) {
        print( "FALSE\n");
    } else {
        print( "FALSE\n");
    }

This means if you want to chain you cannot write:

if ( 1 ==  2 ) {
   print( "OK\n");
} else if ( 3 == 4 ) {
   print( "Meh?\n");
} else {
   print( "Moi!");
}

Instead you must nest things, like so:

if ( 1 ==  2 ) {
   print( "OK\n");
} else {
     if ( 3 == 4 ) {
         print( "Meh?\n");
     } else {
       print( "Moi!");
     }
}

We should allow the more natural approach to work.