aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-08-29 15:59:30 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-08-29 16:00:04 -0700
commit811fdd685670d2eb8c6bcb9e6e103e57bf402ca8 (patch)
treec599fd7a609159c2ec50a30f1131000070e8eb03
parent22495c7d708b4950b83c5bc9b97806e19cd1fcfa (diff)
Tweaked version 3.6 to include deprecating list append/removal functions
in favor of using a method call style.
-rw-r--r--compatibility/2.4.nom28
-rw-r--r--compatibility/3.6.nom24
-rw-r--r--compatibility/compatibility.nom4
-rw-r--r--core/collections.nom14
-rw-r--r--core/control_flow.nom16
-rw-r--r--core/coroutines.nom2
-rw-r--r--lib/base64.nom26
-rw-r--r--nomsu_compiler.lua13
-rw-r--r--nomsu_compiler.moon8
-rwxr-xr-xtools/autoformat.nom2
-rwxr-xr-xtools/replace.nom9
-rwxr-xr-xtools/test.nom4
-rwxr-xr-xtools/upgrade.nom4
13 files changed, 92 insertions, 62 deletions
diff --git a/compatibility/2.4.nom b/compatibility/2.4.nom
index 2207343..4b416fb 100644
--- a/compatibility/2.4.nom
+++ b/compatibility/2.4.nom
@@ -17,20 +17,20 @@ upgrade %tree to "2.4" as:
(not (%line is syntax tree)):
compile error at %tree.source "WUT: %s"
(not (%line is "Action" syntax tree)):
- add %line to %new_lines
+ %new_lines::add %line
(%line.stub is "* %"):
- add %line.2 to %conditions
+ %conditions::add %line.2
(%line.stub == "* else %"):
- add (\(else %block) with vars {block:%line.3}) to %new_lines
+ %new_lines::add (\(else %block) with vars {block:%line.3})
(%line.stub != "* % %"):
- add %line to %new_lines
+ %new_lines::add %line
else:
- add %line.2 to %conditions
+ %conditions::add %line.2
%action = %line.3
unless (%action is "Block" syntax tree):
%action = (=lua "Block(\%action.source, \%action)")
- add %action to %conditions
- add (=lua "Action(\%conditions[1].source, unpack(\%conditions))") to %new_lines
+ %conditions::add %action
+ %new_lines::add (=lua "Action(\%conditions[1].source, unpack(\%conditions))")
%conditions = []
return (..)
@@ -44,20 +44,20 @@ upgrade %tree to "2.4" as:
for %line in %body:
if:
(not (%line is "Action" syntax tree)):
- add %line to %new_lines
+ %new_lines::add %line
(%line.stub is "* %"):
- add %line.2 to %values
+ %values::add %line.2
(%line.stub == "* else %"):
- add (\(else %block) with vars {block:%line.3}) to %new_lines
+ %new_lines::add (\(else %block) with vars {block:%line.3})
(%line.stub != "* % %"):
- add %line to %new_lines
+ %new_lines::add %line
else:
- add %line.2 to %values
+ %values::add %line.2
%action = %line.3
unless (%action is "Block" syntax tree):
%action = \(: %action)
- add %action to %values
- add (=lua "Action(\%values[1].source, unpack(\%values))") to %new_lines
+ %values::add %action
+ %new_lines::add (=lua "Action(\%values[1].source, unpack(\%values))")
%values = []
return (..)
diff --git a/compatibility/3.6.nom b/compatibility/3.6.nom
index 297612a..ecf4fb3 100644
--- a/compatibility/3.6.nom
+++ b/compatibility/3.6.nom
@@ -4,17 +4,27 @@
use "compatibility/compatibility.nom"
-upgrade action (to %1 write %2) to "3.6" as (%1::append %2)
-upgrade action (%1 <-write %2) to "3.6" as (%1::append %2)
-upgrade action (to %1 write %2 joined by %3) to "3.6" as (..)
+upgrade action [..]
+ append %item to %list, add %item to %list, to %list add %item, to %list append %item
+..to "3.6" as (%list::add %item)
+
+upgrade action [add %item to %list at index %i] to "3.6" as (..)
+ %list::at index %i add %item
+
+upgrade action [pop from %list, remove last from %list] to "3.6" as (%list::pop)
+upgrade action [remove index %index from %list] to "3.6" as (..)
+ %list::remove index %index
+
+upgrade action [to %1 write %2, %1 <-write %2] to "3.6" as (%1::append %2)
+upgrade action [to %1 write %2 joined by %3] to "3.6" as (..)
%1::append %2 joined by %3
-upgrade action (declare locals in %lua) to "3.6" as (%lua::declare locals)
-upgrade action (declare locals %locs in %lua) to "3.6" as (..)
+upgrade action [declare locals in %lua] to "3.6" as (%lua::declare locals)
+upgrade action [declare locals %locs in %lua] to "3.6" as (..)
%lua::declare locals %locs
-upgrade action (add free vars %vars to %lua) to "3.6" as (..)
+upgrade action [add free vars %vars to %lua] to "3.6" as (..)
%lua::add free vars %vars
-upgrade action (remove free vars %vars from %lua) to "3.6" as (..)
+upgrade action [remove free vars %vars from %lua] to "3.6" as (..)
%lua::remove free vars %vars
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom
index d74cabe..d63383b 100644
--- a/compatibility/compatibility.nom
+++ b/compatibility/compatibility.nom
@@ -39,9 +39,9 @@ compile [upgrade action %actions to %version as %body] to:
(%t is syntax tree):
%args = ((make tree %) for % in %t)
- add "source=\(\%tree as lua id).source" to %args at index 1
+ %args::add "source=\(\%tree as lua id).source"
if %t.target:
- add "target=\(make tree %t.target)" to %args at index 1
+ %args::add "target=\(make tree %t.target)"
return "\(%t.type){\(%args joined with ", ")}"
else:
diff --git a/core/collections.nom b/core/collections.nom
index cba20f9..aade458 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -58,9 +58,9 @@ test:
%list = [1, 2, 3, 4, 5]
append 6 to %list
assume ((last in %list) is 6)
- pop from %list
+ %list::pop
assume ((last in %list) is 5)
- remove index 1 from %list
+ %list::remove index 1
assume ((first in %list) is 2)
compile [..]
append %item to %list, add %item to %list, to %list add %item, to %list append %item
@@ -85,7 +85,7 @@ parse [%expression for %item in %iterable] as (..)
result of:
%comprehension = []
for %item in %iterable:
- add %expression to %comprehension
+ %comprehension::add %expression
return %comprehension
parse [..]
@@ -95,7 +95,7 @@ parse [..]
result of:
%comprehension = []
for %index in %start to %stop via %step:
- add %expression to %comprehension
+ %comprehension::add %expression
return %comprehension
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -114,7 +114,7 @@ parse [..]
result of:
%comprehension = []
for %key = %value in %iterable:
- add %expression to %comprehension
+ %comprehension::add %expression
return %comprehension
# Dict comprehensions
@@ -164,7 +164,7 @@ test:
action [%lists flattened]:
%flat = []
for %list in %lists:
- for %item in %list: add %item to %flat
+ for %item in %list: %flat::add %item
return %flat
test:
@@ -240,7 +240,7 @@ action [unique %items]:
%seen = {}
for % in %items:
unless %seen.%:
- add % to %unique
+ %unique::add %
%seen.% = (yes)
return %unique
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 95b9bcb..63601f7 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -172,19 +172,19 @@ compile [===next %var ===, ---next %var ---, ***next %var ***] to (..)
test:
%nums = []
- for %x in 1 to 5: add %x to %nums
+ for %x in 1 to 5: %nums::add %x
assume (%nums == [1, 2, 3, 4, 5])
%nums = []
- for %x in 1 to 5 via 2: add %x to %nums
+ for %x in 1 to 5 via 2: %nums::add %x
assume (%nums == [1, 3, 5])
%nums = []
for %outer in 1 to 100:
for %inner in %outer to (%outer + 2):
if (%inner == 2):
- add -2 to %nums
+ %nums::add -2
do next %inner
- add %inner to %nums
+ %nums::add %inner
if (%inner == 5): stop %outer
assume (%nums == [1, -2, 3, -2, 3, 4, 3, 4, 5])
@@ -227,13 +227,13 @@ parse [for %var in %start to %stop %body] as (..)
test:
%a = [10, 20, 30, 40, 50]
%b = []
- for %x in %a: add %x to %b
+ for %x in %a: %b::add %x
assume (%a == %b)
%b = []
for %x in %a:
if (%x == 10): do next %x
if (%x == 50): stop %x
- add %x to %b
+ %b::add %x
assume (%b == [20, 30, 40])
@@ -268,7 +268,7 @@ test:
for %k = %v in %d:
if (%k == "a"): do next %k
if (%v == 20): do next %v
- add "\%k = \%v" to %result
+ %result::add "\%k = \%v"
assume ((%result sorted) == ["c = 30", "d = 40", "e = 50"])
@@ -486,7 +486,7 @@ test:
for % in recursive %t:
if ((type of %) is "table"):
for %2 in %: recurse % on %2
- ..else: add % to %flat
+ ..else: %flat::add %
assume ((sorted %flat) == [1, 2, 3, 4, 5, 6])
diff --git a/core/coroutines.nom b/core/coroutines.nom
index 1570ed7..80f3b60 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -12,7 +12,7 @@ test:
-> 5
repeat 3 times: -> 6
- for % in coroutine %co: add % to %nums
+ for % in coroutine %co: %nums::add %
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
compile [coroutine %body, generator %body] to (..)
Lua value ".."
diff --git a/lib/base64.nom b/lib/base64.nom
index 2b7e22e..fb12319 100644
--- a/lib/base64.nom
+++ b/lib/base64.nom
@@ -21,22 +21,22 @@ action [base64 %str, base64 encode %str, %str base64]:
%chars = []
for %i in 1 to (length of %str) via 3:
%bytes = [=lua "\%str:byte(\%i, \(%i + 2))"]
- add %b64_str.(((%bytes.1 & 252) >> 2) + 1) to %chars
+ %chars::add %b64_str.(((%bytes.1 & 252) >> 2) + 1)
if (length of %bytes) is:
3:
- add %b64_str.(((%bytes.1 & 3) << 4) + ((%bytes.2 & 240) >> 4) + 1) to %chars
- add %b64_str.(((%bytes.2 & 15) << 2) + ((%bytes.3 & 192) >> 6) + 1) to %chars
- add %b64_str.((%bytes.3 & 63) + 1) to %chars
+ %chars::add %b64_str.(((%bytes.1 & 3) << 4) + ((%bytes.2 & 240) >> 4) + 1)
+ %chars::add %b64_str.(((%bytes.2 & 15) << 2) + ((%bytes.3 & 192) >> 6) + 1)
+ %chars::add %b64_str.((%bytes.3 & 63) + 1)
2:
- add %b64_str.(((%bytes.1 & 3) << 4) + ((%bytes.2 & 240) >> 4) + 1) to %chars
- add %b64_str.(((%bytes.2 & 15) << 2) + 1) to %chars
- add "=" to %chars
+ %chars::add %b64_str.(((%bytes.1 & 3) << 4) + ((%bytes.2 & 240) >> 4) + 1)
+ %chars::add %b64_str.(((%bytes.2 & 15) << 2) + 1)
+ %chars::add "="
1:
- add %b64_str.(((%bytes.1 & 3) << 4) + 1) to %chars
- add "=" to %chars
- add "=" to %chars
+ %chars::add %b64_str.(((%bytes.1 & 3) << 4) + 1)
+ %chars::add "="
+ %chars::add "="
return (%chars joined)
@@ -45,10 +45,10 @@ action [decode base64 %str, %str base64 decoded, base64 decode %str]:
%chars = []
for %i in 1 to (length of %str) via 4:
%indices = (%reverse_b64.(%str.%) for % in %i to (%i + 3))
- add (chr ((%indices.1 << 2) + ((%indices.2 & 48) >> 4))) to %chars
+ %chars::add (chr ((%indices.1 << 2) + ((%indices.2 & 48) >> 4)))
if (%str.(%i + 2) == "="): stop
- add (chr (((%indices.2 & 15) << 4) + ((%indices.3 & 60) >> 2))) to %chars
+ %chars::add (chr (((%indices.2 & 15) << 4) + ((%indices.3 & 60) >> 2)))
if (%str.(%i + 3) == "="): stop
- add (chr (((%indices.3 & 3) << 6) + %indices.4)) to %chars
+ %chars::add (chr (((%indices.3 & 3) << 6) + %indices.4))
return (%chars joined)
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 2cda146..4855476 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -125,7 +125,18 @@ local _list_mt = {
end
end
return true
- end
+ end,
+ __index = {
+ add_1 = insert,
+ append_1 = insert,
+ add_1_at_index_2 = function(t, x, i)
+ return insert(t, i, x)
+ end,
+ at_index_1_add_2 = insert,
+ pop = table.remove,
+ remove_last = table.remove,
+ remove_index_1 = table.remove
+ }
}
local list
list = function(t)
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index e05c209..5ac6a87 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -80,6 +80,14 @@ _list_mt =
elseif @[i] < other[i] then return true
elseif @[i] > other[i] then return false
return true
+ __index:
+ add_1: insert
+ append_1: insert
+ add_1_at_index_2: (t,x,i)-> insert(t,i,x)
+ at_index_1_add_2: insert
+ pop: table.remove
+ remove_last: table.remove
+ remove_index_1: table.remove
list = (t)-> setmetatable(t, _list_mt)
diff --git a/tools/autoformat.nom b/tools/autoformat.nom
index 6c4420a..719b826 100755
--- a/tools/autoformat.nom
+++ b/tools/autoformat.nom
@@ -11,7 +11,7 @@ use "lib/os.nom"
%inplace = (no)
if (%args.1 is "-i"):
%inplace = (yes)
- remove index 1 from %args
+ %args::remove index 1
for %path in %args:
for file %filename in %path:
diff --git a/tools/replace.nom b/tools/replace.nom
index 4557c2c..3140675 100755
--- a/tools/replace.nom
+++ b/tools/replace.nom
@@ -11,14 +11,14 @@ use "lib/os.nom"
%inplace = (no)
if (%args.1 is "-i"):
%inplace = (yes)
- remove index 1 from %args
+ %args::remove index 1
if ((length of %args) < 3):
say "Usage: nomsu tools/replace.nom [-i] tree_to_replace replacement files..."
lua> "os.exit(1)"
-%pattern = (parse (remove index 1 from %args))
-%replacement = (parse (remove index 1 from %args))
+%pattern = (parse (%args::remove index 1))
+%replacement = (parse (%args::remove index 1))
for %path in %args:
for file %filename in %path:
unless (any [%filename matches "%.nom$", %filename == "-", %filename == "stdin"]):
@@ -28,7 +28,7 @@ for %path in %args:
if (%tree2 == %tree):
say "No changes in \%filename"
do next %filename
-
+
%text = ".."
#!/usr/bin/env nomsu -V\(%tree.version or (Nomsu version))
\(%tree2 as nomsu)
@@ -37,4 +37,5 @@ for %path in %args:
%inplace:
say "Replaced in \%filename"
write %text to file %filename
+
else: say %text
diff --git a/tools/test.nom b/tools/test.nom
index 7a1ee1e..2446069 100755
--- a/tools/test.nom
+++ b/tools/test.nom
@@ -8,7 +8,7 @@ use "lib/consolecolor.nom"
%args = (command line args)
if (%args.1 == "-v"):
- remove index 1 from %args
+ %args::remove index 1
%verbose = (yes)
# Make sure all the files get run
@@ -24,7 +24,7 @@ for %path in (command line args):
%file_tests = []
for %src = %test in %tests:
if (%src.filename == %filename):
- add {test:%test, source:%src} to %file_tests
+ %file_tests::add {test:%test, source:%src}
unless (%file_tests is empty):
sort %file_tests by % -> %.source
diff --git a/tools/upgrade.nom b/tools/upgrade.nom
index c74b8e7..4676f77 100755
--- a/tools/upgrade.nom
+++ b/tools/upgrade.nom
@@ -12,12 +12,12 @@ use "lib/os.nom"
%inplace = (no)
if (%args.1 is "-i"):
%inplace = (yes)
- remove index 1 from %args
+ %args::remove index 1
if (%args.1 is "-t"):
use "lib/consolecolor.nom"
%test = (yes)
- remove index 1 from %args
+ %args::remove index 1
for %path in %args:
for file %filename in %path: