WingedSeal / jmc

A compiler for JMC (JavaScript-like Minecraft Function), a mcfunction extension language for making Minecraft Datapack
https://jmc.wingedseal.com
MIT License
64 stars 10 forks source link

Switch statements don't fully compile with curly braced anon function cases #55

Open w00tyd00d opened 1 year ago

w00tyd00d commented 1 year ago

Describe the bug

Switch statements that use an anonymous function (specifically with curly brackets) within a case will prevent any subsequent cases from being compiled. Since it needs curly brackets for it to bug, it seems like it's an error in the parser picking up the curly bracket to end the switch when it shouldn't.

To Reproduce

  1. Create a switch statement in any .jmc file.
  2. Use an anonymous execute function within a case that uses curly brackets. Any following cases will be ignored by the compiler.

Screenshots

JMC code: image

Transpiled result: image

Desktop

Nico314159 commented 1 year ago

Temporary workaround: add a break statement.

switch ($switch_var) {
    case 0:
        execute run $result = 0;
    case 1:
        execute run $result = 1;
    case 2:
        execute run {
            $result = 2;
        }
        break;
    case 3:
        execute run $result = 3;
}

compiles to what's expected.