nomsu/compatibility/2.4.nom

70 lines
3.1 KiB
Plaintext
Raw Normal View History

2018-10-31 15:05:17 -07:00
#!/usr/bin/env nomsu -V4.8.10
2018-07-23 15:56:59 -07:00
#
This file defines upgrades from Nomsu <2.4 to Nomsu 2.4
2018-07-20 17:56:06 -07:00
use "compatibility/compatibility.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2018-07-20 17:56:06 -07:00
upgrade %tree to "2.4" as:
unless (%tree is "Action" syntax tree): return
if %tree.stub is:
"when" "if":
if ((size of %tree) == 3):
return %tree
2018-07-20 17:56:06 -07:00
%conditions = []
%new_lines = []
%body = (..)
(%tree.2 upgraded) if (%tree.2 is "Block" syntax tree) else [%tree.2 upgraded]
2018-07-20 17:56:06 -07:00
for %line in %body:
when:
2018-07-20 17:56:06 -07:00
(not (%line is "Action" syntax tree)):
%new_lines::add %line
(%line.stub is "*"):
if ((size of %line) == 2):
%conditions::add %line.2
..else:
%new_lines::add %line
(%line.stub == "* else"):
%new_lines::add (\(else %block) with vars {block:%line.3})
2018-07-20 17:56:06 -07:00
else:
%conditions::add %line.2
2018-07-20 17:56:06 -07:00
%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)}")
2018-07-20 17:56:06 -07:00
%conditions = []
return (..)
\(when %body) with vars {body:=lua "SyntaxTree{type='Block', source=\%tree[2].source, unpack(\%new_lines)}"}
"if 1 is ?" "if 1 = ?":
2018-07-20 17:56:06 -07:00
%values = []
%new_lines = []
%body = (..)
(%tree.5 upgraded) if (%tree.5 is "Block" syntax tree) else [%tree.5 upgraded]
2018-07-20 17:56:06 -07:00
for %line in %body:
when:
2018-07-20 17:56:06 -07:00
(not (%line is "Action" syntax tree)):
%new_lines::add %line
(%line.stub is "*"):
if ((size of %line) == 2):
%values::add %line.2
..else:
%new_lines::add %line
(%line.stub == "* else"):
%new_lines::add (\(else %block) with vars {block:%line.3})
2018-07-20 17:56:06 -07:00
else:
%values::add %line.2
2018-07-20 17:56:06 -07:00
%action = %line.3
unless (%action is "Block" syntax tree):
%action = \(: %action)
%values::add %action
%new_lines::add (=lua "SyntaxTree{type='Action', source=\%values[1].source, unpack(\%values)}")
2018-07-20 17:56:06 -07:00
%values = []
return (..)
\(if %var is %body) with vars {..}
var:%tree.2 upgraded, body:=lua "SyntaxTree{type='Block', source=\%tree[5].source, unpack(\%new_lines)}"