code / nomsu

Lines6.6K Lua5.1K PEG1.3K make117
2 others 83
Markdown60 Bourne Again Shell23
(33 lines)
1 #!/usr/bin/env nomsu -V7.0.0
2 ###
3 This file defines upgrades from Nomsu 1 to Nomsu 2
5 use "compatibility/compatibility"
7 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9 upgrade $tree to "2" as:
10 unless ($tree is "Action" syntax tree): return
11 if ($tree.stub == "if 1 2 else"):
12 $true_body = $tree.3
13 unless ($true_body is "Block" syntax tree):
14 $true_body = ("Block" tree with $true_body)
15 $false_body = $tree.5
16 unless ($false_body is "Block" syntax tree):
17 $false_body = (=lua "Block(\$false_body.source, \$false_body)")
18 return \(if \$tree.2 \$true_body else \$false_body)
20 $need_blocks = [
21 "if", "unless", "for 1 in", "for 1 = 2 in", "repeat while 1", "repeat 1 times"
22 "repeat", "repeat until 1", "for 1 in 2 to 3 by", "for 1 in 2 to 3 via"
23 "for 1 in 2 to", "for 1 2 in", "do", "for 1 in recursive", "test", "with"
24 "result of", "when"
27 for $n in $need_blocks:
28 if ($tree.stub == $n):
29 $bits = [: for $ in $tree: add ($ if ($ is syntax tree) else $)]
30 unless (($bits, last) is "Block" syntax tree):
31 $body = ($bits, last)
32 $bits.(#$bits) = (=lua "SyntaxTree{type='Block', source=\$body.source, \$body}")
33 return (=lua "SyntaxTree{type='Action', source=\$tree.source, unpack(\$bits)}")