From 9a75d25c843b03e3671b71384fd48deb0607db43 Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 11 Nov 2018 15:05:18 -0800 Subject: Lots of fixes to the upgrading and codegen/autoformatting pipeline, also deleted nomnom files, since they're mostly not needed anymore. --- compatibility/2.4.nom | 16 ++++++------ compatibility/2.nom | 6 ++--- compatibility/4.10.12.7.nom | 49 ++++++++++++++++++++++++++++++++++++ compatibility/4.9.nom | 60 +++------------------------------------------ 4 files changed, 65 insertions(+), 66 deletions(-) create mode 100644 compatibility/4.10.12.7.nom (limited to 'compatibility') diff --git a/compatibility/2.4.nom b/compatibility/2.4.nom index 1f87a98..2b39dd5 100644 --- a/compatibility/2.4.nom +++ b/compatibility/2.4.nom @@ -9,7 +9,9 @@ use "compatibility/compatibility.nom" upgrade %tree to "2.4" as: unless (%tree is "Action" syntax tree): return if %tree.stub is: - "when": + "when" "if": + if ((size of %tree) == 3): + return %tree %conditions = [] %new_lines = [] %body = (..) @@ -29,15 +31,15 @@ upgrade %tree to "2.4" as: %conditions::add %line.2 %action = %line.3 unless (%action is "Block" syntax tree): - %action = (=lua "Block(\%action.source, \%action)") + %action = (=lua "SyntaxTree{type='Block', source=\%action.source, \%action}") %conditions::add %action - %new_lines::add (=lua "Action(\%conditions[1].source, unpack(\%conditions))") + %new_lines::add (=lua "SyntaxTree{type='Action', source=\%conditions[1].source, unpack(\%conditions)}") %conditions = [] return (..) - \(when %body) with vars {body:=lua "Block(\%tree[2].source, unpack(\%new_lines))"} + \(when %body) with vars {body:=lua "SyntaxTree{type='Block', source=\%tree[2].source, unpack(\%new_lines)}"} - "when 1 is ?" "when 1 = ?": + "if 1 is ?" "if 1 = ?": %values = [] %new_lines = [] %body = (..) @@ -59,9 +61,9 @@ upgrade %tree to "2.4" as: unless (%action is "Block" syntax tree): %action = \(: %action) %values::add %action - %new_lines::add (=lua "Action(\%values[1].source, unpack(\%values))") + %new_lines::add (=lua "SyntaxTree{type='Action', source=\%values[1].source, unpack(\%values)}") %values = [] return (..) \(if %var is %body) with vars {..} - var:%tree.2 upgraded, body:=lua "Block(\%tree[5].source, unpack(\%new_lines))" + var:%tree.2 upgraded, body:=lua "SyntaxTree{type='Block', source=\%tree[5].source, unpack(\%new_lines)}" diff --git a/compatibility/2.nom b/compatibility/2.nom index 5c78e29..84331a6 100644 --- a/compatibility/2.nom +++ b/compatibility/2.nom @@ -23,13 +23,13 @@ upgrade %tree to "2" as: "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" + "do", "for 1 in recursive", "test", "with", "result of", "when" for %n in %need_blocks: if (%tree.stub is %n): %bits = (((% upgraded) if (% is syntax tree) else %) for % in %tree) unless ((%bits::last) is "Block" syntax tree): %body = (%bits::last) - %bits.(size of %bits) = (=lua "Block(\%body.source, \%body)") + %bits.(size of %bits) = (=lua "SyntaxTree{type='Block', source=\%body.source, \%body}") - return (=lua "Action(\%tree.source, unpack(\%bits))") + return (=lua "SyntaxTree{type='Action', source=\%tree.source, unpack(\%bits)}") diff --git a/compatibility/4.10.12.7.nom b/compatibility/4.10.12.7.nom new file mode 100644 index 0000000..c314b68 --- /dev/null +++ b/compatibility/4.10.12.7.nom @@ -0,0 +1,49 @@ +#!/usr/bin/env nomsu -V4.10.12.7 +# + This file defines upgrades from Nomsu <4.10.12.7 to 4.10.12.7 +use "compatibility/compatibility.nom" + +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +upgrade action (% as lua statements) to "4.10.12.7" as (% as lua) +upgrade action (% as lua return) to "4.10.12.7" as (..) + =lua "\%.type == 'Block' and \(% as lua) or 'return '..\(% as lua expr)" +upgrade action (Lua value %) to "4.10.12.7" as (Lua %) + +upgrade action (%e for % in %items) to "4.10.12.7" as [:for % in %items: add %e] +upgrade action (%e for %k = %v in %items) to "4.10.12.7" as [:for %k = %v in %items: add %e] +upgrade action (%e for %i in %start to %stop) to "4.10.12.7" as [:for %i in %start to %stop: add %e] +upgrade action (%e for %i in %start to %stop by %step) to "4.10.12.7" as (..) + [:for %i in %start to %stop by %step: add %e] +upgrade action (%e for %i in %start to %stop via %step) to "4.10.12.7" as (..) + [:for %i in %start to %stop by %step: add %e] + +upgrade action (%k = %v for % in %items) to "4.10.12.7" as {:for % in %items: add %k = %v} +upgrade action (%k = %v for %k0 = %v0 in %items) to "4.10.12.7" as {:for %k0 = %v0 in %items: add %k = %v} +upgrade action (%k = %v for %i in %start to %stop) to "4.10.12.7" as {:for %i in %start to %stop: add %k = %v} +upgrade action (%k = %v for %i in %start to %stop by %step) to "4.10.12.7" as (..) + {:for %i in %start to %stop by %step: add %k = %v} +upgrade action (%k = %v for %i in %start to %stop via %step) to "4.10.12.7" as (..) + {:for %i in %start to %stop by %step: add %k = %v} + +upgrade action (% as lua statements) to "4.10.12.7" as (% as lua) + +upgrade %tree to "4.10.12.7" as: + if (%tree.type == "FileChunks"): + %first_chunk = %tree.1 + %first_has_use = (no) + %i = 1 + repeat while (%i < (size of %first_chunk)): + if %first_has_use: + if ((%first_chunk.%i.type != "Action") or (%first_chunk.%i.stub != "use")): + %chunk2 = (%SyntaxTree {type:"Block"}) + for %j in %i to (size of %first_chunk.%i): + %chunk2.((size of %chunk2) + 1) = %first_chunk.%i.%j + for %j in %i to (size of %first_chunk.%i): + %first_chunk.%i.%j = (nil) + %table.insert %tree 2 %chunk2 + return %tree + ..else: + if ((%first_chunk.type == "Action") and (%first_chunk.stub == "use")): + %first_has_use = (yes) + %i += 1 diff --git a/compatibility/4.9.nom b/compatibility/4.9.nom index 7eb54d4..76df07b 100644 --- a/compatibility/4.9.nom +++ b/compatibility/4.9.nom @@ -3,61 +3,9 @@ This file defines upgrades from Nomsu <4.9 to 4.9 use "compatibility/compatibility.nom" -upgrade action "local action" to "4.9" via (..) - [%tree, %end_version] ->: - %spec = %tree.3 - %body = %tree.4 - if %spec.type is: - "List": - if ((size of %spec) == 1): - return \(%spec.1 means %body) - ..else: - return \(%spec all mean %body) - else: - return \(%spec means %body) - -upgrade action "action" to "4.9" via (..) - [%tree, %end_version] ->: - %spec = %tree.2 - %body = %tree.3 - if %body: - if %spec.type is: - "List": - if ((size of %spec) == 1): - return \(externally %spec.1 means %body) - ..else: - return \(externally %spec all mean %body) - else: - return \(externally %spec means %body) - ..else: - return \(%spec's meaning) +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -upgrade action "compile 1 to" to "4.9" via (..) +upgrade action "if" to "4.9" via (..) [%tree, %end_version] ->: - %spec = %tree.2 - %body = %tree.4 - if %spec.type is: - "List": - if ((size of %spec) == 1): - return \(%spec.1 compiles to %body) - ..else: - return \(%spec all compile to %body) - else: - return \(%spec compiles to %body) - -upgrade action "parse 1 as" to "4.9" via (..) - [%tree, %end_version] ->: - %spec = %tree.2 - %body = %tree.4 - if %spec.type is: - "List": - if ((size of %spec) == 1): - return \(%spec.1 parses as %body) - ..else: - return \(%spec all parse as %body) - else: - return \(%spec parse as %body) - -upgrade action (compile as %) to "4.9" as (what % compiles to) -upgrade action (remove action %) to "4.9" as ((%'s meaning) = (nil)) -upgrade action (if %) to "4.9" as (when %) + if ((size of %tree) > 2): return %tree + return \(when %tree.2) -- cgit v1.2.3