#!/usr/bin/env nomsu -V4.8.10 # This file defines upgrades from Nomsu <2.4 to Nomsu 2.4 use "compatibility/compatibility.nom" upgrade %tree to "2.4" as: unless (%tree is "Action" syntax tree): return if %tree.stub is: "when %": %conditions = [] %new_lines = [] %body = (..) (%tree.2 upgraded) if (%tree.2 is "Block" syntax tree) else [%tree.2 upgraded] for %line in %body: if: (not (%line is syntax tree)): compile error at %tree.source "WUT: %s" (not (%line is "Action" syntax tree)): %new_lines::add %line (%line.stub is "* %"): %conditions::add %line.2 (%line.stub == "* else %"): %new_lines::add (\(else %block) with vars {block:%line.3}) (%line.stub != "* % %"): %new_lines::add %line else: %conditions::add %line.2 %action = %line.3 unless (%action is "Block" syntax tree): %action = (=lua "Block(\%action.source, \%action)") %conditions::add %action %new_lines::add (=lua "Action(\%conditions[1].source, unpack(\%conditions))") %conditions = [] return (..) \(if %body) with vars {body:=lua "Block(\%tree[2].source, unpack(\%new_lines))"} "when % is ? %" "when % = ? %": %values = [] %new_lines = [] %body = (..) (%tree.5 upgraded) if (%tree.5 is "Block" syntax tree) else [%tree.5 upgraded] for %line in %body: if: (not (%line is "Action" syntax tree)): %new_lines::add %line (%line.stub is "* %"): %values::add %line.2 (%line.stub == "* else %"): %new_lines::add (\(else %block) with vars {block:%line.3}) (%line.stub != "* % %"): %new_lines::add %line else: %values::add %line.2 %action = %line.3 unless (%action is "Block" syntax tree): %action = \(: %action) %values::add %action %new_lines::add (=lua "Action(\%values[1].source, unpack(\%values))") %values = [] return (..) \(if %var is %body) with vars {..} var:%tree.2 upgraded, body:=lua "Block(\%tree[5].source, unpack(\%new_lines))"