aboutsummaryrefslogtreecommitdiff
path: root/lib/compatibility/2.4.nom
blob: eca5d73eb9ecf1d6f2d84489cdc6a75e680b096e (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env nomsu -V7.0.0
###
    This file defines upgrades from Nomsu <2.4 to Nomsu 2.4
    
use "compatibility/compatibility"

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

upgrade $tree to "2.4" as:
    unless ($tree is "Action" syntax tree): return
    if $tree.stub is:
        "when" "if":
            if (#$tree == 3):
                return $tree
            $conditions = []
            $new_lines = []
            $body =
                $tree.2 if ($tree.2 is "Block" syntax tree) else [$tree.2]
            
            for $line in $body:
                when:
                    (not ($line is "Action" syntax tree)):
                        $new_lines, add $line
                    
                    ($line.stub == "*"):
                        if (#$line == 2):
                            $conditions, add $line.2
                        ..else:
                            $new_lines, add $line
                    
                    ($line.stub == "* else"):
                        $new_lines, add \(else \$line.3)
                    
                    else:
                        $conditions, add $line.2
                        $action = $line.3
                        unless ($action is "Block" syntax tree):
                            $action = (=lua "SyntaxTree{type='Block', source=\$action.source, \$action}")
                        $conditions, add $action
                        $new_lines, add
                            =lua ("
                                SyntaxTree{type='Action', source=\$conditions[1].source, unpack(\$conditions)}
                            ")
                        $conditions = []
            
            return \(when \("Block" tree from $tree.2.source with (unpack $new_lines)))
        
        "if 1 is ?" "if 1 = ?":
            $values = []
            $new_lines = []
            $body =
                $tree.5 if ($tree.5 is "Block" syntax tree) else [$tree.5]
            
            for $line in $body:
                when:
                    (not ($line is "Action" syntax tree)):
                        $new_lines, add $line
                    
                    ($line.stub == "*"):
                        if (#$line == 2):
                            $values, add $line.2
                        ..else:
                            $new_lines, add $line
                    
                    ($line.stub == "* else"):
                        $new_lines, add \(else \$line.3)
                    
                    else:
                        $values, add $line.2
                        $action = $line.3
                        unless ($action is "Block" syntax tree):
                            $action = ("Block" tree with $action)
                        $values, add $action
                        $new_lines, add
                            =lua "SyntaxTree{type='Action', source=\$values[1].source, unpack(\$values)}"
                        $values = []
            
            return
                \(
                    if \($tree.2) is
                        \("Block" tree from $tree.5.source with (unpack $new_lines))
                )