aboutsummaryrefslogtreecommitdiff
path: root/compatibility/2.nom
blob: 399d4853e766814331cf486219a7b02d9590d4e9 (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
#!/usr/bin/env nomsu -V2.5.5.5
#
    This file defines upgrades from Nomsu 1 to Nomsu 2

use "compatibility/compatibility.nom"

upgrade %tree to "2" as:
    unless (%tree is "Action" syntax tree): return
    if (%tree.stub is "if % % else %"):
        %true_body = (%tree.3 upgraded)
        unless (%true_body is "Block" syntax tree):
            %true_body = (=lua "Block(\%true_body.source, \%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 %cond %true_body else %false_body) with vars {..}
                cond:%tree.2 upgraded, true_body:%true_body, false_body:%false_body
    
    %need_blocks = [..]
        "if % %", "unless % %", "for % in % %", "for % = % in % %", "repeat while % %"
        "repeat % times %", "repeat %", "repeat until % %", "for % in % to % by % %"
        "for % in % to % via % %", "for % in % to % %", "for % % in % %"
        "do %", "for % in recursive % %", "test %", "with % %", "result of %"
    
    for %n in %need_blocks:
        if (%tree.stub is %n):
            %bits = (((% upgraded) if (% is syntax tree) else %) for % in %tree)
            unless ((last in %bits) is "Block" syntax tree):
                %body = (last in %bits)
                %bits.(length of %bits) = (=lua "Block(\%body.source, \%body)")
            
            return (=lua "Action(\%tree.source, unpack(\%bits))")