aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-30 15:05:41 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-30 15:06:03 -0700
commitab4ebdf1751158391100efb0002f40b1d7f6314c (patch)
treebe675ed7b35164a24bdae5e8f1d3dd73af98490f
parent7c488dd266466f80e55a3f02050f4e4a019d64b5 (diff)
Changed autoformatting rules to ensure tests get clumped together with
the thing below them.
-rw-r--r--core/collections.nom24
-rw-r--r--core/control_flow.nom9
-rw-r--r--core/coroutines.nom1
-rw-r--r--core/math.nom7
-rw-r--r--core/metaprogramming.nom18
-rw-r--r--core/operators.nom11
-rw-r--r--core/scopes.nom1
-rw-r--r--core/text.nom13
-rw-r--r--lib/base64.nom6
-rw-r--r--lib/consolecolor.nom1
-rw-r--r--lib/file_hash.nom4
-rw-r--r--lib/object.nom1
-rw-r--r--lib/os.nom8
-rw-r--r--nomsu_compiler.lua38
-rw-r--r--nomsu_compiler.moon24
-rwxr-xr-xtools/test.nom6
16 files changed, 62 insertions, 110 deletions
diff --git a/core/collections.nom b/core/collections.nom
index 5f00358..99c84ca 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -11,7 +11,6 @@ use "core/operators.nom"
# Indexing
test:
assume ((2 nd to last in [1, 2, 3, 4, 5]) is 4)
-
compile [..]
%index st to last in %list, %index nd to last in %list
%index rd to last in %list, %index th to last in %list
@@ -25,7 +24,6 @@ parse [first in %list] as %list.1
# Membership testing
test:
assume (3 is in [1, 2, 3, 4, 5])
-
action [%item is in %list, %list contains %item, %list has %item]:
for %key = %value in %list:
if (%key is %item): return (yes)
@@ -33,7 +31,6 @@ action [%item is in %list, %list contains %item, %list has %item]:
test:
assume (99 isn't in [1, 2, 3])
-
action [..]
%item isn't in %list, %item is not in %list, %list doesn't contain %item
%list does not contain %item, %list doesn't have %item, %list does not have %item
@@ -44,12 +41,11 @@ action [..]
test:
assume ({x:no} has key "x")
-
parse [%list has key %index, %list has index %index] as (%list.%index != (nil))
+
test:
assume ({x:no} doesn't have key "y")
assume (not ({x:no} doesn't have key "x"))
-
parse [..]
%list doesn't have key %index, %list does not have key %index
%list doesn't have index %index, %list does not have index %index
@@ -66,7 +62,6 @@ test:
assume ((last in %list) is 5)
remove index 1 from %list
assume ((first in %list) is 2)
-
compile [..]
append %item to %list, add %item to %list, to %list add %item, to %list append %item
..to (Lua "table.insert(\(%list as lua expr), \(%item as lua expr))")
@@ -86,7 +81,6 @@ compile [remove index %index from %list] to (..)
# List Comprehension
test:
assume (((% * %) for % in [1, 2, 3]) == [1, 4, 9])
-
parse [%expression for %item in %iterable] as (..)
result of:
%comprehension = []
@@ -108,13 +102,11 @@ parse [..]
test:
assume (((% * %) for % in 1 to 3) == [1, 4, 9])
-
parse [%expression for %var in %start to %stop] as (..)
%expression for %var in %start to %stop via 1
test:
assume (("\%k,\%v" for %k = %v in {x:1}) == ["x,1"])
-
parse [..]
%expression for %key = %value in %iterable
%expression for %key %value in %iterable
@@ -128,7 +120,6 @@ parse [..]
# Dict comprehensions
test:
assume (((% * %) = % for % in [1, 2, 3]) == {1:1, 4:2, 9:3})
-
parse [%key = %value for %item in %iterable, %key %value for %item in %iterable] as
..(..)
result of:
@@ -139,7 +130,6 @@ parse [%key = %value for %item in %iterable, %key %value for %item in %iterable]
test:
assume ((%k = (%v * %v) for %k = %v in {x:1, y:2, z:3}) == {x:1, y:4, z:9})
-
parse [..]
%key = %value for %src_key = %src_value in %iterable
%key %value for %src_key %src_value in %iterable
@@ -164,7 +154,6 @@ parse [..]
test:
assume (((% * %) = % for % in 1 to 3) == {1:1, 4:2, 9:3})
-
parse [..]
%key = %value for %item in %start to %stop
%key %value for %item in %start to %stop
@@ -172,7 +161,6 @@ parse [..]
test:
assume (([[1, 2], [3, 4]] flattened) == [1, 2, 3, 4])
-
action [%lists flattened]:
%flat = []
for %list in %lists:
@@ -181,15 +169,14 @@ action [%lists flattened]:
test:
assume ((entries in {x:1}) == [{key:"x", value:1}])
-
parse [entries in %dict] as ({key:%k, value:%v} for %k = %v in %dict)
+
test:
assume ((keys in {x:1}) == ["x"])
-
parse [keys in %dict, keys of %dict] as (%k for %k = %v in %dict)
+
test:
assume ((values in {x:1}) == [1])
-
parse [values in %dict, values of %dict] as (%v for %k = %v in %dict)
# Metatable stuff
@@ -197,13 +184,11 @@ test:
%t = {}
set %t 's metatable to {__tostring:[%] -> "XXX"}
assume ("\%t" == "XXX")
-
compile [set %dict 's metatable to %metatable] to (..)
Lua "setmetatable(\(%dict as lua expr), \(%metatable as lua expr));"
test:
assume (({} with fallback % -> (% + 1)).10 == 11)
-
compile [%dict with fallback %key -> %value] to (..)
Lua value ".."
setmetatable(\(%dict as lua expr), {__index=function(self, \(%key as lua expr))
@@ -222,7 +207,6 @@ test:
%keys = {1:999, 2:0, 3:50}
sort %x by % = %keys.%
assume (%x == [2, 3, 1])
-
compile [sort %items] to (Lua "table.sort(\(%items as lua expr));")
parse [sort %items by %item = %key_expr, sort %items by %item -> %key_expr] as (..)
do:
@@ -233,7 +217,6 @@ parse [sort %items by %item = %key_expr, sort %items by %item -> %key_expr] as (
test:
assume ((sorted [3, 1, 2]) == [1, 2, 3])
-
action [%items sorted, sorted %items]:
%copy = (% for % in %items)
sort %copy
@@ -247,7 +230,6 @@ parse [%items sorted by %item = %key, %items sorted by %item -> %key] as (..)
test:
assume ((unique [1, 2, 1, 3, 2, 3]) == [1, 2, 3])
-
action [unique %items]:
%unique = []
%seen = {}
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 24e367d..0552771 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -16,7 +16,6 @@ compile [do nothing] to (Lua "")
test:
if (no):
barf "conditional fail"
-
compile [if %condition %if_body] to (..)
Lua ".."
if \(%condition as lua expr) then
@@ -26,7 +25,6 @@ compile [if %condition %if_body] to (..)
test:
unless (yes):
barf "conditional fail"
-
parse [unless %condition %unless_body] as (if (not %condition) %unless_body)
compile [..]
if %condition %if_body else %else_body, unless %condition %else_body else %if_body
@@ -46,7 +44,6 @@ compile [..]
test:
assume ((1 if (yes) else 2) == 1)
assume ((1 if (no) else 2) == 2)
-
compile [..]
%when_true_expr if %condition else %when_false_expr
%when_true_expr if %condition otherwise %when_false_expr
@@ -82,7 +79,6 @@ test:
%i += 1
unless (%i == 10): go to %loop
assume (%i == 10)
-
compile [=== %label ===, --- %label ---, *** %label ***] to (..)
Lua "::label_\(%label as lua identifier)::"
@@ -112,7 +108,6 @@ test:
barf "Failed to 'do next repeat'"
assume (%x == 30)
-
compile [do next repeat] to (Lua "goto continue_repeat")
compile [stop repeating] to (Lua "goto stop_repeat")
compile [repeat while %condition %body] to:
@@ -138,11 +133,11 @@ compile [repeat while %condition %body] to:
parse [repeat %body] as (repeat while (yes) %body)
parse [repeat until %condition %body] as (repeat while (not %condition) %body)
+
test:
%x = 0
repeat 10 times: %x += 1
assume (%x == 10)
-
compile [repeat %n times %body] to:
%lua = (..)
Lua ".."
@@ -466,7 +461,6 @@ test:
..and if it barfs: do nothing
assume (%d.x == "good")
-
compile [do %action then always %final_action] to (..)
Lua ".."
do
@@ -485,6 +479,7 @@ test:
# Inline thunk:
compile [result of %body] to (Lua value "\(compile as ([] -> %body))()")
+
test:
%t = [1, [2, [[3], 4], 5, [[[6]]]]]
%flat = []
diff --git a/core/coroutines.nom b/core/coroutines.nom
index 1ebb2db..1cc5a71 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -14,7 +14,6 @@ test:
for % in coroutine %co: add % to %nums
assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
-
compile [coroutine %body, generator %body] to (..)
Lua value ".."
(function()
diff --git a/core/math.nom b/core/math.nom
index 5337d8c..3fad8f0 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -14,7 +14,6 @@ test:
math constants failed
%nan = (NaN)
assume (%nan != %nan) or barf "NaN failed"
-
compile [infinity, inf] to (Lua value "math.huge")
compile [not a number, NaN, nan] to (Lua value "(0/0)")
compile [pi, Pi, PI] to (Lua value "math.pi")
@@ -25,8 +24,8 @@ compile [e] to (Lua value "math.exp(1)")
# Functions:
test:
assume (("5" as a number) == 5)
-
compile [% as a number, % as number] to (Lua value "tonumber(\(% as lua expr))")
+
test:
assume (..)
all of [..]
@@ -34,7 +33,6 @@ test:
arc tangent 5, arc tangent 5 / 10, hyperbolic sine 5, hyperbolic cosine 5
hyperbolic tangent 5, e^ 5, ln 5, log base 2 of 5, floor 5, ceiling 5, round 5
..or barf "math functions failed"
-
compile [absolute value %, | % |, abs %] to (..)
Lua value "math.abs(\(% as lua expr))"
@@ -63,10 +61,10 @@ compile [log % base %base, log base %base of %] to (..)
compile [floor %] to (Lua value "math.floor(\(% as lua expr))")
compile [ceiling %, ceil %] to (Lua value "math.ceil(\(% as lua expr))")
compile [round %, % rounded] to (Lua value "math.floor(\(% as lua expr) + .5)")
+
test:
assume ((463 to the nearest 100) == 500) or barf "rounding failed"
assume ((2.6 to the nearest 0.25) == 2.5) or barf "rounding failed"
-
action [%n to the nearest %rounder] (..)
=lua "(\%rounder)*math.floor((\%n / \%rounder) + .5)"
@@ -107,7 +105,6 @@ compile [max of %items, biggest of %items, largest of %items, highest of %items]
test:
assume ((min of [3, -4, 1, 2] by % = (% * %)) == 1)
assume ((max of [3, -4, 1, 2] by % = (% * %)) == -4)
-
parse [min of %items by %item = %value_expr] as (..)
result of:
set {%best:nil, %best_key:nil}
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 4168c82..9acc97e 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -32,11 +32,9 @@ lua> ".."
test:
compile [five] to (Lua value "5")
-
test:
assume ((five) == 5) or barf "Compile to expression failed."
compile [loc x] to (Lua "local _x = 99;")
-
test:
lua> "do"
loc x
@@ -46,11 +44,9 @@ test:
compile [asdf] to:
%tmp = ""
return (Lua %tmp)
-
test:
asdf
assume (%tmp is (nil)) or barf "compile to is leaking variables"
-
lua> ".."
nomsu.COMPILE_ACTIONS["compile % to %"] = function(nomsu, tree, \%actions, \%body)
local \%args = {"nomsu", "tree", unpack(table.map(\%actions[1]:get_args(), function(a) return tostring(nomsu:compile(\
@@ -96,7 +92,6 @@ test:
parse [baz %] as (foo %)
assume ((foo 1) == "outer")
-
compile [local action %actions %body] to (..)
lua> ".."
local fn_name = "A"..string.as_lua_id(\%actions[1].stub)
@@ -124,11 +119,9 @@ compile [local action %actions %body] to (..)
test:
action [baz1]: return "baz1"
action [baz2] "baz2"
-
test:
assume ((baz1) == "baz1")
assume ((baz2) == "baz2")
-
compile [action %actions %body] to (..)
lua> ".."
local lua = \(compile as (local action %actions %body))
@@ -137,15 +130,14 @@ compile [action %actions %body] to (..)
test:
assume ((action (say %)) == (=lua "A_say_1"))
-
compile [action %action] to (Lua value (%action as lua id))
+
test:
parse [swap %x and %y] as (..)
do:
%tmp = %x
%x = %y
%y = %tmp
-
test:
set {%1:1, %2:2}
swap %1 and %2
@@ -155,7 +147,6 @@ test:
swap %tmp and %tmp2
assume ((%tmp == 2) and (%tmp2 == 1)) or barf ".."
'parse % as %' variable mangling failed.
-
compile [parse %actions as %body] to (..)
lua> ".."
local replacements = {}
@@ -207,7 +198,6 @@ compile [remove action %action] to (..)
test:
assume ("\(\(foo %x) as nomsu)" == "foo %x") or barf ".."
action source code failed.
-
compile [%tree as nomsu] to (..)
Lua value "nomsu:tree_to_nomsu(\(%tree as lua expr))"
@@ -276,18 +266,16 @@ test:
one
"two"
..== "\"one\\n\\\"two\\\"\""
-
compile [quote %s] to (Lua value "repr(\(%s as lua expr))")
+
test:
assume ((type of {}) == "table") or barf "type of failed."
-
compile [type of %obj] to (Lua value "type(\(%obj as lua expr))")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
test:
assume ((parse "foo %") == \(foo %))
-
compile [parse %text] to (Lua value "nomsu:parse(\(%text as lua expr))")
compile [parse %text from %filename] to (..)
Lua value ".."
@@ -301,7 +289,6 @@ test:
run \:
external %passed = (yes)
assume %passed
-
compile [run %nomsu_code] to (..)
Lua value ".."
nomsu:run(\(%nomsu_code as lua expr), \(..)
@@ -310,7 +297,6 @@ compile [run %nomsu_code] to (..)
test:
assume ((\(5 + 5) as value) == 10) or barf "%tree as value failed."
-
action [run tree %tree, %tree as value] (lua> "return nomsu:run(\%tree)")
compile [compile %block, compiled %block, %block compiled] to (..)
Lua value "nomsu:compile(\(%block as lua))"
diff --git a/core/operators.nom b/core/operators.nom
index fbb8325..e3c71b0 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -22,7 +22,6 @@ compile [%a isn't %b, %a is not %b, %a not= %b, %a != %b] to (..)
# For strict identity checking, use (%x's id) is (%y's id)
test:
assume (([] == []) and (([]'s id) != ([]'s id)))
-
lua> ".."
do
local new_uuid = require('uuid')
@@ -117,7 +116,6 @@ test:
set global x local y
assume ((%foozle == "inner") and (%y == "outer")) or barf "external failed."
-
compile [external %var = %value] to:
%var_lua = (%var as lua)
assume %var_lua.is_value or barf "Invalid target for assignment: \%var"
@@ -135,7 +133,6 @@ test:
set global x local y
assume ((%foozle == "inner") and (%y == "outer")) or barf ".."
'with external' failed.
-
compile [with external %externs %body] to:
%body_lua = (%body as lua statements)
lua> ".."
@@ -151,7 +148,6 @@ test:
assume (%x == 1) or barf "'with' scoping failed"
assume (%z == (nil)) or barf "'with' scoping failed"
-
compile [with %assignments %body] to:
%lua = (%body as lua statements)
lua> ".."
@@ -189,7 +185,6 @@ compile [with %assignments %body] to:
# Math Operators
test:
assume ((5 wrapped around 2) == 1) or barf "mod not working"
-
compile [%x wrapped around %y, %x mod %y] to (..)
Lua value "(\(%x as lua expr) % \(%y as lua expr))"
@@ -204,7 +199,6 @@ test:
assume (0 <= (one) <= 2) or barf "Three-way chained comparison failed."
assume (%calls == 1) or barf ".."
Three-way comparison evaluated middle value multiple times
-
parse [%x < %y < %z] as (..)
call ([%a, %b, %c] -> ((%a < %b) and (%b < %c))) with [%x, %y, %z]
@@ -236,7 +230,6 @@ test:
assume (((no) and (barfer)) == (no))
assume ((no) or (yes))
assume ((yes) or (barfer))
-
compile [%x and %y] to (Lua value "(\(%x as lua expr) and \(%y as lua expr))")
compile [%x or %y] to (Lua value "(\(%x as lua expr) or \(%y as lua expr))")
@@ -292,12 +285,11 @@ compile [%x ARSHIFT %shift, %x >> %shift] to (..)
test:
assume ((- 5) == -5)
assume ((not (yes)) == (no))
-
compile [- %] to (Lua value "(- \(% as lua expr))")
compile [not %] to (Lua value "(not \(% as lua expr))")
+
test:
assume ((length of [1, 2, 3]) == 3)
-
compile [length of %list, len %list, || %list ||] to (..)
Lua value "(#\(%list as lua expr))"
@@ -314,7 +306,6 @@ test:
assume (%x == 4) or barf "*= failed"
wrap %x around 3
assume (%x == 1) or barf "wrap around failed"
-
parse [%var += %] as (%var = (%var + %))
parse [%var -= %] as (%var = (%var - %))
parse [%var *= %] as (%var = (%var * %))
diff --git a/core/scopes.nom b/core/scopes.nom
index 3dfe473..3456bc0 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -20,7 +20,6 @@ test:
assume ((foo) == "inner foo")
assume ((foo) == "outer foo")
-
compile [with local %locals %body, with local %locals do %body] to:
%body_lua = (%body as lua statements)
if %locals.type is:
diff --git a/core/text.nom b/core/text.nom
index 5ec7b23..395012f 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -21,7 +21,6 @@ test:
..gap
..== "nogap"
parse [アクション %spec %body] as (action %spec %body)
-
test:
%こんにちは = "こんにちは"
アクション [% と言う] "\(%)世界"
@@ -32,7 +31,6 @@ test:
test:
assume ((["x", "y"] joined with ",") == "x,y") or barf "joined with failed"
assume ((["x", "y"] joined) == "xy") or barf "joined failed"
-
action [%texts joined with %glue] (..)
lua> ".."
local text_bits = {}
@@ -40,15 +38,16 @@ action [%texts joined with %glue] (..)
return table.concat(text_bits, \%glue)
parse [joined %texts, %texts joined] as (%texts joined with "")
+
test:
assume ((byte 2 of "BAR") == 65)
assume ((bytes 1 to 2 of "BAR") == [66, 65])
-
compile [byte %i of %text] to (..)
Lua value "(\(%text as lua expr)):byte(\(%i as lua expr))"
compile [bytes %start to %stop of %text] to (..)
- Lua value "list{(\(%text as lua expr)):byte(\(%start as lua expr), \(%stop as lua expr))}"
+ Lua value ".."
+ list{(\(%text as lua expr)):byte(\(%start as lua expr), \(%stop as lua expr))}
test:
assume (("asdf" capitalized) == "Asdf")
@@ -63,7 +62,6 @@ compile [uppercase %text, %text uppercase] to (..)
test:
assume (("asdf" with "X" instead of "s") == "aXdf") or barf ".."
substitution failed
-
compile [..]
%text with %sub instead of %patt, %text with %patt replaced by %sub
%text s/ %patt / %sub
@@ -78,7 +76,6 @@ test:
one
two
..== ["one", "two"]
-
action [lines in %text, lines of %text] (..)
lua> ".."
local result = list{}
@@ -99,7 +96,9 @@ compile [%expr for %match in %text matching %patt] to (..)
Lua value ".."
(function()
local ret = list{}
- for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(%patt as lua expr)) do
+ for \(%match as lua expr) in (\(%text as lua expr)):gmatch(\(..)
+ %patt as lua expr
+ ..) do
ret[#ret+1] = \(%expr as lua statements)
end
return ret
diff --git a/lib/base64.nom b/lib/base64.nom
index a5bb9bb..a65a99d 100644
--- a/lib/base64.nom
+++ b/lib/base64.nom
@@ -6,6 +6,7 @@
%b64_str = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
%reverse_b64 = (%b64_str.%i = (%i - 1) for %i in 1 to (length of %b64_str))
%reverse_b64."=" = 0
+
test:
%cases = ["", "Zg==", "Zm8=", "Zm9v", "Zm9vYg==", "Zm9vYmE=", "Zm9vYmFy"]
for %len = %encoded in %cases:
@@ -16,7 +17,6 @@ test:
assume ((base64 decode %encoded) == %plain) or barf ".."
\(quote %encoded) base64 decoded to \(quote (base64 decode %encoded)) \
..instead of \(quote %plain)
-
action [base64 %str, base64 encode %str, %str base64]:
%chars = []
for %i in 1 to (length of %str) via 3:
@@ -46,9 +46,9 @@ action [decode base64 %str, %str base64 decoded, base64 decode %str]:
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
- if (%str.(%i+2) == "="): stop
+ if (%str.(%i + 2) == "="): stop
add (chr (((%indices.2 & 15) << 4) + ((%indices.3 & 60) >> 2))) to %chars
- if (%str.(%i+3) == "="): stop
+ if (%str.(%i + 3) == "="): stop
add (chr (((%indices.3 & 3) << 6) + %indices.4)) to %chars
return (%chars joined)
diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom
index 53ddecf..1fdf4b2 100644
--- a/lib/consolecolor.nom
+++ b/lib/consolecolor.nom
@@ -4,7 +4,6 @@
test:
bright "\(green)Color test passed."
-
%colors = {..}
normal:0, "reset color":0, bright:1, bold:1, dim:2, italic:3, underscore:4
"slow blink":5, "fast blink":6, reverse:7, inverse:7, inverted:7, hidden:8
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index aef1c78..2f9076e 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -9,7 +9,6 @@ use "lib/base64.nom"
test:
assume ((hash "hello world") == "Kq5sNclPz7QV2+lfQIuc6R7oRu0=")
-
action [hash %, sha1 %]:
%hash = (=lua "\%hashlib.new('sha1'):final(\%)")
return (base64 %hash)
@@ -18,7 +17,6 @@ action [file with hash %hash]:
for file %filename in ".":
%contents = (read file %filename)
%file_hash = (hash %contents)
- if (%file_hash == %hash):
- return %filename
+ if (%file_hash == %hash): return %filename
parse [hash of file %filename] as (sha1 (read file %filename))
diff --git a/lib/object.nom b/lib/object.nom
index 5b842c4..8c33f36 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -42,7 +42,6 @@ test:
assume ((sploot) == "splooted") or barf "subclass method failed"
assume ((bark) == "Bark!") or barf "inheritance failed"
assume ((woof) == "Bark!")
-
compile [@, me] to (Lua value "self")
compile [method %actions %body] to:
%lua = (compile as (local action %actions %body))
diff --git a/lib/os.nom b/lib/os.nom
index b61189a..a7df0a9 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -4,7 +4,6 @@
test:
path of Nomsu file "lib/os.nom"
-
action [path of Nomsu file %filename]:
lua> "for i,f in Files.walk(\%filename) do return f end"
barf "Could not find file: \%filename"
@@ -18,11 +17,10 @@ action [sh> %cmd]:
test:
read file "lib/os.nom"
-
action [read file %filename] (=lua "Files.read(\%filename)")
+
test:
for file %f in "core": do nothing
-
compile [for file %f in %path %body] to (..)
Lua ".."
for i,\(%f as lua expr) in Files.walk(\(%path as lua expr)) do
@@ -52,16 +50,14 @@ action [..]
test:
assume ((line number of 3 in "x\ny") == 2)
-
action [line number of %pos in %str] (=lua "Files.get_line_number(\%str, \%pos)")
+
test:
assume ((line 2 in "one\ntwo\nthree") == "two")
-
action [line %line_num in %str] (=lua "Files.get_line(\%str, \%line_num)")
test:
assume (source lines of \(this))
-
action [source lines of %tree]:
%source = (%tree.source if (%tree is syntax tree) else %tree)
%file = (read file %source.filename)
diff --git a/nomsu_compiler.lua b/nomsu_compiler.lua
index 4974bce..c338e8e 100644
--- a/nomsu_compiler.lua
+++ b/nomsu_compiler.lua
@@ -1045,8 +1045,25 @@ do
end
local _exp_0 = tree.type
if "FileChunks" == _exp_0 then
- local setup = nil
local nomsu = NomsuCode(tree.source, pop_comments(tree.source.start))
+ local should_clump
+ should_clump = function(prev_line, line)
+ if prev_line and prev_line.type == "Action" and line.type == "Action" then
+ if prev_line.stub == "use %" then
+ return line.stub == "use %"
+ end
+ if prev_line.stub == "test %" then
+ return true
+ end
+ if line.stub == "test %" then
+ return false
+ end
+ if recurse(prev_line):is_multiline() then
+ return false
+ end
+ end
+ return true
+ end
for chunk_no, chunk in ipairs(tree) do
if chunk_no > 1 then
nomsu:append("\n\n" .. tostring(("~"):rep(80)) .. "\n\n")
@@ -1054,24 +1071,19 @@ do
nomsu:append(pop_comments(chunk.source.start))
if chunk.type == "Block" then
for line_no, line in ipairs(chunk) do
- if setup == nil then
- setup = line.type == "Action" and line.stub == "use %"
- elseif setup and not (line.type == "Action" and line.stub == "use %") then
- nomsu:append("\n", pop_comments(line.source.start))
- setup = false
- end
- nomsu:append(pop_comments(line.source.start, tostring(nomsu):match("\n\n$") and "" or "\n"))
- local line_nomsu = self:tree_to_nomsu(line, pop_comments)
- nomsu:append(line_nomsu)
- if line_no < #chunk then
- nomsu:append(line_nomsu:is_multiline() and "\n\n" or "\n")
+ if line_no > 1 then
+ if should_clump(chunk[line_no - 1], line) then
+ nomsu:append("\n", pop_comments(line.source.start, '\n'))
+ else
+ nomsu:append("\n\n", pop_comments(line.source.start))
+ end
end
+ nomsu:append(self:tree_to_nomsu(line, pop_comments))
end
nomsu:append(pop_comments(chunk.source.stop, '\n'))
else
nomsu:append(recurse(chunk))
end
- setup = false
end
nomsu:append(pop_comments(tree.source.stop, '\n'))
if not (tostring(nomsu):match("\n$")) then
diff --git a/nomsu_compiler.moon b/nomsu_compiler.moon
index a8eba0c..b48a8f7 100644
--- a/nomsu_compiler.moon
+++ b/nomsu_compiler.moon
@@ -648,26 +648,28 @@ with NomsuCompiler
switch tree.type
when "FileChunks"
- setup = nil
nomsu = NomsuCode(tree.source, pop_comments(tree.source.start))
+ should_clump = (prev_line, line)->
+ if prev_line and prev_line.type == "Action" and line.type == "Action"
+ if prev_line.stub == "use %" then return line.stub == "use %"
+ if prev_line.stub == "test %" then return true
+ if line.stub == "test %" then return false
+ return false if recurse(prev_line)\is_multiline!
+ return true
for chunk_no, chunk in ipairs tree
nomsu\append "\n\n#{("~")\rep(80)}\n\n" if chunk_no > 1
nomsu\append pop_comments(chunk.source.start)
if chunk.type == "Block"
for line_no, line in ipairs chunk
- if setup == nil
- setup = line.type == "Action" and line.stub == "use %"
- elseif setup and not (line.type == "Action" and line.stub == "use %")
- nomsu\append "\n", pop_comments(line.source.start)
- setup = false
- nomsu\append pop_comments(line.source.start, tostring(nomsu)\match("\n\n$") and "" or "\n")
- line_nomsu = @tree_to_nomsu(line, pop_comments)
- nomsu\append line_nomsu
- nomsu\append(line_nomsu\is_multiline! and "\n\n" or "\n") if line_no < #chunk
+ if line_no > 1
+ if should_clump(chunk[line_no-1], line)
+ nomsu\append "\n", pop_comments(line.source.start, '\n')
+ else
+ nomsu\append "\n\n", pop_comments(line.source.start)
+ nomsu\append @tree_to_nomsu(line, pop_comments)
nomsu\append pop_comments(chunk.source.stop, '\n')
else
nomsu\append recurse(chunk)
- setup = false
nomsu\append pop_comments(tree.source.stop, '\n')
nomsu\append('\n') unless tostring(nomsu)\match("\n$")
return nomsu
diff --git a/tools/test.nom b/tools/test.nom
index ebd9fab..bd51e10 100755
--- a/tools/test.nom
+++ b/tools/test.nom
@@ -16,9 +16,7 @@ for %path in (command line args):
for file %filename in %path:
if (%filename matches "%.nom$"): use %filename
-for %path in (command line args):
- use %path
-
+for %path in (command line args): use %path
%tests = ((=lua "Source:from_string(\%s)") = %t for %s = %t in (tests))
for %path in (command line args):
for file %filename in %path:
@@ -27,7 +25,7 @@ for %path in (command line args):
for %src = %test in %tests:
if (%src.filename == %filename):
add {test:%test, source:%src} to %file_tests
-
+
unless (%file_tests is empty):
sort %file_tests by % -> %.source
lua> "io.write('[ .. ] ', \%filename); io.flush()"