aboutsummaryrefslogtreecommitdiff
path: root/lib/compatibility/2.nom
blob: 4dc867d0efde4a849ab40bd931d79b414b2ad71d (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
#!/usr/bin/env nomsu -V7.0.0

###
    This file defines upgrades from Nomsu 1 to Nomsu 2
    
use "compatibility/compatibility"

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

upgrade $tree to "2" as:
    unless ($tree is "Action" syntax tree): return
    if ($tree.stub == "if 1 2 else"):
        $true_body = ($tree.3 upgraded)
        unless ($true_body is "Block" syntax tree):
            $true_body = ("Block" tree with $true_body)
        $false_body = ($tree.5 upgraded)
        unless ($false_body is "Block" syntax tree):
            $false_body = (=lua "Block(\$false_body.source, \$false_body)")
        
        return `(if `($tree.2 upgraded) `$true_body else `$false_body)
    
    $need_blocks = [
        "if", "unless", "for 1 in", "for 1 = 2 in", "repeat while 1", "repeat 1 times"
        "repeat", "repeat until 1", "for 1 in 2 to 3 by", "for 1 in 2 to 3 via"
        "for 1 in 2 to", "for 1 2 in", "do", "for 1 in recursive", "test", "with"
        "result of", "when"
    ]
    
    for $n in $need_blocks:
        if ($tree.stub == $n):
            $bits = [: for $ in $tree: add (($ upgraded) if ($ is syntax tree) else $)]
            unless (($bits, last) is "Block" syntax tree):
                $body = ($bits, last)
                $bits.(#$bits) = (=lua "SyntaxTree{type='Block', source=\$body.source, \$body}")
            return (=lua "SyntaxTree{type='Action', source=\$tree.source, unpack(\$bits)}")