aboutsummaryrefslogtreecommitdiff
path: root/compatibility/2.4.nom
blob: ae0cfbaecda2d20a0a7f7d2a8569dc9be9e80273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/usr/bin/env nomsu -V2.4
use "core"
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)):
                        add %line to %new_lines
                    (%line.stub is "* %"):
                        add %line.2 to %conditions
                    (%line.stub == "* else %"):
                        add (\(else %block) with vars {block:%line.3}) to %new_lines
                    (%line.stub != "* % %"):
                        add %line to %new_lines
                    else:
                        add %line.2 to %conditions
                        %action = %line.3
                        unless (%action is "Block" syntax tree):
                            %action = (=lua "Block(\%action.source, \%action)")
                        add %action to %conditions
                        add (=lua "Action(\%conditions[1].source, unpack(\%conditions))") to %new_lines
                        %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)):
                        add %line to %new_lines
                    (%line.stub is "* %"):
                        add %line.2 to %values
                    (%line.stub == "* else %"):
                        add (\(else %block) with vars {block:%line.3}) to %new_lines
                    (%line.stub != "* % %"):
                        add %line to %new_lines
                    else:
                        add %line.2 to %values
                        %action = %line.3
                        unless (%action is "Block" syntax tree):
                            %action = (=lua "Block(\%action.source, \%action)")
                        add %action to %values
                        add (=lua "Action(\%values[1].source, unpack(\%values))") to %new_lines
                        %values = []
            return (\(if %var is %body) with vars {var: %tree.2 upgraded, body:=lua "Block(\%tree[5].source, unpack(\%new_lines))"})