aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-12-30 23:58:47 -0800
committerBruce Hill <bruce@bruce-hill.com>2018-12-30 23:58:47 -0800
commit5059c081ac624ede925d5256885509ddd17181c6 (patch)
tree0457d135e5193126bf73466bfaae09df94ab8a7d
parentec69ee6f62016a2edcc13e3183cbe4cadd75717f (diff)
Auto-upgraded code.
-rw-r--r--compatibility/2.4.nom15
-rw-r--r--compatibility/2.5.5.5.nom4
-rw-r--r--compatibility/3.6.nom4
-rw-r--r--compatibility/3.7.nom9
-rw-r--r--compatibility/3.nom2
-rw-r--r--compatibility/4.10.12.7.nom50
-rw-r--r--compatibility/4.11.nom12
-rw-r--r--compatibility/4.12.nom4
-rw-r--r--compatibility/compatibility.nom7
-rw-r--r--core/collections.nom13
-rw-r--r--core/control_flow.nom70
-rw-r--r--core/errors.nom9
-rw-r--r--core/id.nom4
-rw-r--r--core/math.nom18
-rw-r--r--core/metaprogramming.nom27
-rw-r--r--core/operators.nom30
-rw-r--r--core/text.nom9
-rw-r--r--examples/how_do_i.nom9
-rw-r--r--lib/file_hash.nom2
-rw-r--r--lib/object.nom2
-rw-r--r--lib/things.nom15
-rwxr-xr-xtools/find.nom19
-rwxr-xr-xtools/format.nom6
-rw-r--r--tools/repl.nom3
-rwxr-xr-xtools/test.nom7
-rwxr-xr-xtools/upgrade.nom4
26 files changed, 189 insertions, 165 deletions
diff --git a/compatibility/2.4.nom b/compatibility/2.4.nom
index 1279968..40b363a 100644
--- a/compatibility/2.4.nom
+++ b/compatibility/2.4.nom
@@ -37,12 +37,15 @@ upgrade $tree to "2.4" as:
$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)}"
+ =lua ("
+ SyntaxTree{type='Action', source=\$conditions[1].source, unpack(\$conditions)}
+ ")
$conditions = []
return
\(when $body) with vars {
- .body = (=lua "SyntaxTree{type='Block', source=\$tree[2].source, unpack(\$new_lines)}")
+ .body =
+ =lua "SyntaxTree{type='Block', source=\$tree[2].source, unpack(\$new_lines)}"
}
"if 1 is ?" "if 1 = ?":
@@ -70,11 +73,13 @@ upgrade $tree to "2.4" as:
$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)}")
+ $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 "SyntaxTree{type='Block', source=\$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.5.5.5.nom b/compatibility/2.5.5.5.nom
index 05bf705..a8ec2bc 100644
--- a/compatibility/2.5.5.5.nom
+++ b/compatibility/2.5.5.5.nom
@@ -7,7 +7,9 @@ use "compatibility/compatibility.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
upgrade action [hash $, sha1 $] to "2.5.5.5" as
- =lua "\(base64 decode (hash $)):gsub('.', function(c) return ('%x02'):format(c) end)"
+ =lua ("
+ \(base64 decode (hash $)):gsub('.', function(c) return ('%x02'):format(c) end)
+ ")
upgrade action [file with hash $] to "2.5.5.5" as
file with hash
diff --git a/compatibility/3.6.nom b/compatibility/3.6.nom
index 8fb52b5..eb19e39 100644
--- a/compatibility/3.6.nom
+++ b/compatibility/3.6.nom
@@ -18,10 +18,8 @@ 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, add $2)
upgrade action [to $1 write $2 joined by $3] to "3.6" as
-..($1, add $2 joined by $3)
-
+ $1, add $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
$lua, declare locals $locs
diff --git a/compatibility/3.7.nom b/compatibility/3.7.nom
index e81b9dc..052337c 100644
--- a/compatibility/3.7.nom
+++ b/compatibility/3.7.nom
@@ -7,19 +7,18 @@ use "compatibility/compatibility.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
upgrade action [$index st to last in $list] to "3.7" as
-..($list, $index st to last)
+ $list, $index st to last
upgrade action [$index nd to last in $list] to "3.7" as
-..($list, $index nd to last)
+ $list, $index nd to last
upgrade action [$index rd to last in $list] to "3.7" as
-..($list, $index rd to last)
+ $list, $index rd to last
upgrade action [$index th to last in $list] to "3.7" as
-..($list, $index rd th last)
+ $list, $index rd th last
upgrade action [last in $list] to "3.7" as ($list, last)
-
upgrade action [first in $list] to "3.7" as ($list, first)
upgrade action [$item is in $list, $list contains $item, $list has $item] to
.."3.7" as ($list, has $item)
diff --git a/compatibility/3.nom b/compatibility/3.nom
index 6086bd0..cba6f71 100644
--- a/compatibility/3.nom
+++ b/compatibility/3.nom
@@ -12,4 +12,4 @@ upgrade action (@) to "3" as $me
upgrade action "as" to "3" via
for $tree:
compile error at $tree "Object API has changed and 'as' is no longer supported."
- .."Use (%obj::action ...) instead of (as %obj: action ...)"
+ "Use (%obj::action ...) instead of (as %obj: action ...)"
diff --git a/compatibility/4.10.12.7.nom b/compatibility/4.10.12.7.nom
index 228fee9..1c0231c 100644
--- a/compatibility/4.10.12.7.nom
+++ b/compatibility/4.10.12.7.nom
@@ -12,41 +12,32 @@ upgrade action ($ as lua return) to "4.10.12.7" as
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 $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) 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 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 ($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 $ 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 $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) 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 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 ($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 (parse $text from $filename) to "4.10.12.7" as
(NomsuCode from (Source $filename 1 (size of $text)) $text) parsed
@@ -84,9 +75,8 @@ upgrade $tree to "4.10.12.7" as:
$chunk2.($j - $i + 1) = $first_chunk.$j
$new_tree =
- SyntaxTree {
- .source = $tree.source, .type = "FileChunks", .1 = $chunk1, .2 = $chunk2
- }
+ SyntaxTree
+ {.source = $tree.source, .type = "FileChunks", .1 = $chunk1, .2 = $chunk2}
for $i in 2 to (size of $tree):
$new_tree.($i + 1) = $tree.$i
diff --git a/compatibility/4.11.nom b/compatibility/4.11.nom
index 8f6aacc..082825d 100644
--- a/compatibility/4.11.nom
+++ b/compatibility/4.11.nom
@@ -27,22 +27,20 @@ upgrade action "set" to "4.11" via
$rhs.$i = $entry.2
return
- SyntaxTree {
- .type = "Action", .source = $tree.source, .1 = $lhs, .2 = "=", .3 = $rhs
- }
+ SyntaxTree
+ {.type = "Action", .source = $tree.source, .1 = $lhs, .2 = "=", .3 = $rhs}
upgrade action "1 with 2 ~>" to "4.11" via
for $tree:
compile error at $tree "This method has been deprecated."
- .."Perhaps this could be use %tree::map instead."
+ "Perhaps this could be use %tree::map instead."
# Changing filesystem API:
upgrade action (for file $f in $path $body) to "4.11" as
for $f in (files for $path) $body
-upgrade action ($expr for file $f in $path) to "4.11" as [
- : for $f in (files for $path): add $expr
-]
+upgrade action ($expr for file $f in $path) to "4.11" as
+ [: for $f in (files for $path): add $expr]
upgrade action (line $n in $text) to "4.11" as ($text, line $n)
upgrade action (line number of $pos in $text) to "4.11" as
diff --git a/compatibility/4.12.nom b/compatibility/4.12.nom
index 8ab69ae..816acaa 100644
--- a/compatibility/4.12.nom
+++ b/compatibility/4.12.nom
@@ -10,9 +10,9 @@ use "compatibility/compatibility.nom"
upgrade action "do next repeat" to "4.12" via
for $tree:
compile error at $tree "This method has been deprecated."
- .."Use either (do next) or (go to (label)) instead."
+ "Use either (do next) or (go to (label)) instead."
upgrade action "stop repeating" to "4.12" via
for $tree:
compile error at $tree "This method has been deprecated."
- .."Use either (stop) or (go to (label)) instead."
+ "Use either (stop) or (go to (label)) instead."
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom
index bc34c4f..a83011f 100644
--- a/compatibility/compatibility.nom
+++ b/compatibility/compatibility.nom
@@ -34,7 +34,9 @@ externally (upgrade action $stub to $version via $upgrade_fn) means:
return $replacements.($t.1)
..else:
external $needs_mangle = (yes)
- return "SyntaxTree{type=\(quote $t.type), source=\(quote "\($t.source)"), \(quote (mangle $t.1))}"
+ return ("
+ SyntaxTree{type=\(quote $t.type), source=\(quote "\($t.source)"), \(quote (mangle $t.1))}
+ ")
($t is syntax tree):
$args = []
@@ -54,7 +56,8 @@ externally (upgrade action $stub to $version via $upgrade_fn) means:
$retval = (make tree $body)
$lua, add
Lua ("
- upgrade_action_1_to_2_via(\(quote $action.stub), \($version as lua expr), function(\(\$tree as lua id))
+ upgrade_action_1_to_2_via(\(quote $action.stub), \($version as lua expr), function(\
+ ..\(\$tree as lua id))
return \$retval
end)
")
diff --git a/core/collections.nom b/core/collections.nom
index 77da968..5697af9 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -38,9 +38,8 @@ test:
$dict = {.x = 1, .y = 2, .z = 3}
assume (size of $dict) == 3
assume [: for $ in {.x = 1}: add $] == [{.key = "x", .value = 1}]
- assume [: for $k = $v in {.x = 1}: add {.key = $k, .value = $v}] == [
- {.key = "x", .value = 1}
- ]
+ assume [: for $k = $v in {.x = 1}: add {.key = $k, .value = $v}] ==
+ [{.key = "x", .value = 1}]
assume ({.x = 1, .y = 1} + {.y = 10, .z = 10}) == {.x = 1, .y = 11, .z = 10}
assume ({.x = 1, .y = 1} | {.y = 10, .z = 10}) == {.x = 1, .y = 1, .z = 10}
assume ({.x = 1, .y = 1} & {.y = 10, .z = 10}) == {.y = 1}
@@ -62,9 +61,8 @@ externally ($lists flattened) means:
test:
assume ((entries in {.x = 1}) == [{.key = "x", .value = 1}])
-(entries in $dict) parses as [
- : for $k = $v in $dict: add {.key = $k, .value = $v}
-]
+(entries in $dict) parses as
+ [: for $k = $v in $dict: add {.key = $k, .value = $v}]
test:
assume ((keys in {.x = 1}) == ["x"])
@@ -81,10 +79,9 @@ test:
assume ("\$t" == "XXX")
(set $dict's metatable to $metatable) compiles to
-.."setmetatable(\($dict as lua expr), \($metatable as lua expr));"
+ "setmetatable(\($dict as lua expr), \($metatable as lua expr));"
[$'s metatable, $'metatable] all compile to "getmetatable(\($ as lua expr))"
-
test:
assume (({} with fallback $ -> ($ + 1)).10 == 11)
diff --git a/core/control_flow.nom b/core/control_flow.nom
index b2db945..12bb9c6 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -30,8 +30,9 @@ test:
barf "conditional fail"
(unless $condition $unless_body) parses as (if (not $condition) $unless_body)
-[if $condition $if_body else $else_body, unless $condition $else_body else $if_body]
-..all compile to ("
+[
+ if $condition $if_body else $else_body, unless $condition $else_body else $if_body
+] all compile to ("
if \($condition as lua expr) then
\($if_body as lua)
else
@@ -58,7 +59,10 @@ test:
equivalent of a conditional expression: (cond and if_true or if_false)
if {.Text, .List, .Dict, .Number}.($when_true_expr.type):
return
- Lua "(\($condition as lua expr) and \($when_true_expr as lua expr) or \($when_false_expr as lua expr))"
+ Lua ("
+ (\($condition as lua expr) and \($when_true_expr as lua expr) or \
+ ..\($when_false_expr as lua expr))
+ ")
..else:
# Otherwise, need to do an anonymous inline function (yuck, too bad lua
doesn't have a proper ternary operator!)
@@ -135,9 +139,15 @@ test:
assume ($x == 20)
(repeat while $condition $body) compiles to:
- $lua = (Lua "while \($condition as lua expr) do\n \($body as lua)")
+ $lua =
+ Lua ("
+ while \($condition as lua expr) do
+ \($body as lua)
+ ")
+
if ($body has subtree \(do next)):
$lua, add "\n ::continue::"
+
$lua, add "\nend --while-loop"
return $lua
@@ -173,7 +183,10 @@ test:
] all compile to:
# This uses Lua's approach of only allowing loop-scoped variables in a loop
$lua =
- Lua "for \($var as lua identifier)=\($start as lua expr),\($stop as lua expr),\($step as lua expr) do"
+ Lua ("
+ for \($var as lua identifier)=\($start as lua expr),\($stop as lua expr),\
+ ..\($step as lua expr) do
+ ")
$lua, add "\n " ($body as lua)
if ($body has subtree \(do next)):
$lua, add "\n ::continue::"
@@ -265,7 +278,10 @@ test:
[for $key = $value in $iterable $body, for $key $value in $iterable $body]
..all compile to:
$lua =
- Lua "for \($key as lua identifier),\($value as lua identifier) in pairs(\($iterable as lua expr)) do"
+ Lua ("
+ for \($key as lua identifier),\($value as lua identifier) in pairs(\
+ ..\($iterable as lua expr)) do
+ ")
$lua, add "\n " ($body as lua)
if ($body has subtree \(do next)):
$lua, add "\n ::continue::"
@@ -314,7 +330,7 @@ test:
$else_allowed = (yes)
unless ($body.type is "Block"):
compile error at $body "'if' expected a Block, but got a \($body.type)."
- .."Perhaps you forgot to put a ':' after 'if'?"
+ "Perhaps you forgot to put a ':' after 'if'?"
for $line in $body:
unless
@@ -329,7 +345,7 @@ test:
if (($line.1 is "else") and ((size of $line) == 2)):
unless $else_allowed:
compile error at $line "You can't have two 'else' blocks."
- .."Merge all of the 'else' blocks together."
+ "Merge all of the 'else' blocks together."
unless ((size of "\$code") > 0):
compile error at $line
@@ -338,12 +354,7 @@ test:
..around it. Otherwise, make sure the 'else' block comes last.
")
- $code, add ("
-
- else
- \;
- ") ($action as lua)
-
+ $code, add "\nelse\n " ($action as lua)
$else_allowed = (no)
..else:
$code, add $clause " "
@@ -351,20 +362,14 @@ test:
if ($i > 1):
$code, add " or "
$code, add ($line.$i as lua expr)
-
- $code, add ("
- then
- \;
- ") ($action as lua)
-
+ $code, add " then\n " ($action as lua)
$clause = "\nelseif"
if ((size of "\$code") == 0):
compile error at $body "'if' block has an empty body."
- .."This means nothing would happen, so the 'if' block should be deleted."
+ "This means nothing would happen, so the 'if' block should be deleted."
$code, add "\nend --when"
-
return $code
test:
@@ -389,7 +394,7 @@ test:
define mangler
unless ($body.type is "Block"):
compile error at $body "'if' expected a Block, but got a \($body.type)"
- .."Perhaps you forgot to put a ':' after the 'is'?"
+ "Perhaps you forgot to put a ':' after the 'is'?"
for $line in $body:
unless
@@ -403,7 +408,7 @@ test:
if (($line.1 is "else") and ((size of $line) == 2)):
unless $else_allowed:
compile error at $line "You can't have two 'else' blocks."
- .."Merge all of the 'else' blocks together."
+ "Merge all of the 'else' blocks together."
unless ((size of "\$code") > 0):
compile error at $line
@@ -412,12 +417,7 @@ test:
..around it. Otherwise, make sure the 'else' block comes last.
")
- $code, add ("
-
- else
- \;
- ") ($action as lua)
-
+ $code, add "\nelse\n " ($action as lua)
$else_allowed = (no)
..else:
$code, add $clause " "
@@ -425,20 +425,14 @@ test:
if ($i > 1):
$code, add " or "
$code, add "\(mangle "branch value") == " ($line.$i as lua expr)
-
- $code, add ("
- then
- \;
- ") ($action as lua)
-
+ $code, add " then\n " ($action as lua)
$clause = "\nelseif"
if ((size of "\$code") == 0):
compile error at $body "'if' block has an empty body."
- .."This means nothing would happen, so the 'if' block should be deleted."
+ "This means nothing would happen, so the 'if' block should be deleted."
$code, add "\nend --when"
-
return
Lua ("
do --if % is...
diff --git a/core/errors.nom b/core/errors.nom
index 9cf7a23..edcfffa 100644
--- a/core/errors.nom
+++ b/core/errors.nom
@@ -7,10 +7,12 @@ use "core/metaprogramming.nom"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
(barf $msg) compiles to
-.."error(\(=lua "\$msg and \($msg as lua expr) or 'nil'"), 0);"
+ "error(\(=lua "\$msg and \($msg as lua expr) or 'nil'"), 0);"
(assume $condition) compiles to:
- lua> "local \$assumption = 'Assumption failed: '..tostring((\$condition):get_source_code())"
+ lua> ("
+ local \$assumption = 'Assumption failed: '..tostring((\$condition):get_source_code())
+ ")
return
Lua ("
@@ -29,7 +31,8 @@ use "core/metaprogramming.nom"
do
local \(mangle "a"), \(mangle "b") = \($a as lua expr), \($b as lua expr)
if \(mangle "a") ~= \(mangle "b") then
- error(\(quote "\$assumption").."\\n"..tostring(\(mangle "a")).." != "..tostring(\(mangle "b")), 0)
+ error(\(quote "\$assumption").."\\n"..tostring(\(mangle "a")).." != "..tostring(\
+ ..\(mangle "b")), 0)
end
end
")
diff --git a/core/id.nom b/core/id.nom
index bc9a96c..a450288 100644
--- a/core/id.nom
+++ b/core/id.nom
@@ -16,7 +16,8 @@ $obj_by_id = {}
set $obj_by_id's metatable to {.__mode = "v"}
$id_by_obj = {}
set $id_by_obj's metatable to {
- .__mode = "k", .__index = (
+ .__mode = "k"
+ .__index =
for ($self $key):
if ($key == (nil)):
return $self.$nil_surrogate
@@ -30,7 +31,6 @@ set $id_by_obj's metatable to {
$self.$key = $id
$obj_by_id.$id = $key
return $id
- )
}
externally (uuid) means:
diff --git a/core/math.nom b/core/math.nom
index d456bff..05b7dd8 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -13,10 +13,8 @@ use "core/collections.nom"
# Literals:
test:
assume (all of [inf, NaN, pi, tau, golden ratio, e]) or barf
- .."math constants failed"
-
+ "math constants failed"
$nan = (NaN)
-
assume ($nan != $nan) or barf "NaN failed"
[infinity, inf] all compile to "math.huge"
[not a number, NaN, nan] all compile to "(0/0)"
@@ -42,29 +40,23 @@ test:
[absolute value $, | $ |, abs $] all compile to "math.abs(\($ as lua expr))"
[square root $, square root of $, √ $, sqrt $] all compile to
-.."math.sqrt(\($ as lua expr))"
-
+ "math.sqrt(\($ as lua expr))"
[sine $, sin $] all compile to "math.sin(\($ as lua expr))"
-
[cosine $, cos $] all compile to "math.cos(\($ as lua expr))"
[tangent $, tan $] all compile to "math.tan(\($ as lua expr))"
[arc sine $, asin $] all compile to "math.asin(\($ as lua expr))"
[arc cosine $, acos $] all compile to "math.acos(\($ as lua expr))"
[arc tangent $, atan $] all compile to "math.atan(\($ as lua expr))"
[arc tangent $y / $x, atan2 $y $x] all compile to
-.."math.atan2(\($y as lua expr), \($x as lua expr))"
-
+ "math.atan2(\($y as lua expr), \($x as lua expr))"
[hyperbolic sine $, sinh $] all compile to "math.sinh(\($ as lua expr))"
-
[hyperbolic cosine $, cosh $] all compile to "math.cosh(\($ as lua expr))"
[hyperbolic tangent $, tanh $] all compile to "math.tanh(\($ as lua expr))"
[e^ $, exp $] all compile to "math.exp(\($ as lua expr))"
[natural log $, ln $, log $] all compile to "math.log(\($ as lua expr))"
[log $ base $base, log base $base of $] all compile to
-.."math.log(\($ as lua expr), \($base as lua expr))"
-
+ "math.log(\($ as lua expr), \($base as lua expr))"
(floor $) compiles to "math.floor(\($ as lua expr))"
-
[ceiling $, ceil $] all compile to "math.ceil(\($ as lua expr))"
[round $, $ rounded] all compile to "math.floor(\($ as lua expr) + .5)"
test:
@@ -204,7 +196,7 @@ externally (seed random with $) means:
(seed random) parses as (seed random with (=lua "os.time()"))
[random number, random, rand] all compile to "math.random()"
[random int $n, random integer $n, randint $n] all compile to
-.."math.random(\($n as lua expr))"
+ "math.random(\($n as lua expr))"
[random from $low to $high, random number from $low to $high, rand $low $high]
..all compile to "math.random(\($low as lua expr), \($high as lua expr))"
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 6dea00f..180614b 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -210,13 +210,11 @@ test:
[$1, $2] = [1, 2]
swap $1 and $2
assume (($1 == 2) and ($2 == 1)) or barf
- .."'parse % as %' failed on 'swap % and %'"
-
+ "'parse % as %' failed on 'swap % and %'"
[$tmp, $tmp2] = [1, 2]
-
swap $tmp and $tmp2
assume (($tmp == 2) and ($tmp2 == 1)) or barf
- .."'parse % as %' variable mangling failed."
+ "'parse % as %' variable mangling failed."
($actions all parse as $body) compiles to:
lua> ("
@@ -310,7 +308,12 @@ externally ($ is $kind syntax tree) means
($tree with $t -> $replacement) compiles to ("
\($tree as lua expr):map(function(\($t as lua expr))
- \(=lua "\$replacement.type == 'Block' and \($replacement as lua) or 'return '..\($replacement as lua expr)")
+ \(
+ =lua ("
+ \$replacement.type == 'Block' and \($replacement as lua) or 'return '..\
+ ..\($replacement as lua expr)
+ ")
+ )
end)
")
@@ -360,7 +363,13 @@ externally (match $tree with $patt) means:
")
test:
- assume ((quote "one\n\"two\"") == "\"one\\n\\\"two\\\"\"")
+ assume
+ (
+ quote ("
+ one
+ "two"
+ ")
+ ) == "\"one\\n\\\"two\\\"\""
(quote $s) compiles to "tostring(\($s as lua expr)):as_lua()"
test:
@@ -400,7 +409,7 @@ test:
assume (run \(return \(\(5) + \(5)))) == 10
(run $nomsu_code) compiles to "run_1_in(\($nomsu_code as lua expr), _ENV)"
[compile $block, compiled $block, $block compiled] all compile to
-.."compile(\($block as lua))"
+ "compile(\($block as lua))"
test:
(foo) means:
@@ -443,4 +452,6 @@ test:
")
externally (Nomsu version) means:
- return "\(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)"
+ return ("
+ \(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
+ ")
diff --git a/core/operators.nom b/core/operators.nom
index 8dfac09..9b095d0 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -17,7 +17,7 @@ test:
($x >= $y) compiles to "(\($x as lua expr) >= \($y as lua expr))"
[$a is $b, $a == $b] all compile to "(\($a as lua expr) == \($b as lua expr))"
[$a isn't $b, $a is not $b, $a not= $b, $a != $b] all compile to
-.."(\($a as lua expr) ~= \($b as lua expr))"
+ "(\($a as lua expr) ~= \($b as lua expr))"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@@ -91,11 +91,13 @@ test:
$y = "inner"
set global x local y
assume (($foozle == "inner") and ($y == "outer")) or barf
- .."'with external' failed."
+ "'with external' failed."
(with external $externs $body) compiles to:
$body_lua = ($body as lua)
- lua> "\$body_lua:remove_free_vars(table.map(\$externs, function(v) return compile(v):text() end))"
+ lua> ("
+ \$body_lua:remove_free_vars(table.map(\$externs, function(v) return compile(v):text() end))
+ ")
return $body_lua
test:
@@ -120,6 +122,7 @@ test:
\$defs:add("local ", item_lua, ";")
end
")
+
return
Lua ("
do
@@ -133,7 +136,7 @@ test:
assume ((5 wrapped around 2) == 1) or barf "mod not working"
[$x wrapped around $y, $x mod $y] all compile to
-.."((\($x as lua expr)) % (\($y as lua expr)))"
+ "((\($x as lua expr)) % (\($y as lua expr)))"
# 3-part chained comparisons
# (uses a lambda to avoid re-evaluating middle value, while still being an expression)
@@ -144,10 +147,8 @@ test:
return 1
assume (0 <= (one) <= 2) or barf "Three-way chained comparison failed."
assume ($calls == 1) or barf
- .."Three-way comparison evaluated middle value multiple times"
-
+ "Three-way comparison evaluated middle value multiple times"
($x < $y < $z) parses as ((($a $b $c) -> (($a < $b) and ($b < $c))) $x $y $z)
-
($x <= $y < $z) parses as ((($a $b $c) -> (($a <= $b) and ($b < $c))) $x $y $z)
($x < $y <= $z) parses as ((($a $b $c) -> (($a < $b) and ($b <= $c))) $x $y $z)
($x <= $y <= $z) parses as ((($a $b $c) -> (($a <= $b) and ($b <= $c))) $x $y $z)
@@ -183,31 +184,30 @@ test:
lua> "if \((is jit) or ((Lua version) == "Lua 5.2")) then"
[NOT $, ~ $] all compile to "bit.bnot(\($ as lua expr))"
[$x OR $y, $x | $y] all compile to
-.."bit.bor(\($x as lua expr), \($y as lua expr))"
+ "bit.bor(\($x as lua expr), \($y as lua expr))"
[$x XOR $y, $x ~ $y] all compile to
-.."bit.bxor(\($x as lua expr), \($y as lua expr))"
+ "bit.bxor(\($x as lua expr), \($y as lua expr))"
[$x AND $y, $x & $y] all compile to
-.."bit.band(\($x as lua expr), \($y as lua expr))"
+ "bit.band(\($x as lua expr), \($y as lua expr))"
[$x LSHIFT $shift, $x << $shift] all compile to
-.."bit.lshift(\($x as lua expr), \($shift as lua expr))"
+ "bit.lshift(\($x as lua expr), \($shift as lua expr))"
[$x RSHIFT $shift, $x >> $shift] all compile to
-.."bit.rshift(\($x as lua expr), \($shift as lua expr))"
+ "bit.rshift(\($x as lua expr), \($shift as lua expr))"
lua> "else"
-
[NOT $, ~ $] all compile to "~(\($ as lua expr))"
[$x OR $y, $x | $y] all compile to "(\($x as lua expr) | \($y as lua expr))"
[$x XOR $y, $x ~ $y] all compile to "(\($x as lua expr) ~ \($y as lua expr))"
[$x AND $y, $x & $y] all compile to "(\($x as lua expr) & \($y as lua expr))"
[$x LSHIFT $shift, $x << $shift] all compile to
-.."(\($x as lua expr) << \($shift as lua expr))"
+ "(\($x as lua expr) << \($shift as lua expr))"
[$x RSHIFT $shift, $x >> $shift] all compile to
-.."(\($x as lua expr) >> \($shift as lua expr))"
+ "(\($x as lua expr) >> \($shift as lua expr))"
lua> "end"
diff --git a/core/text.nom b/core/text.nom
index b5b22b3..97f560e 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -27,7 +27,14 @@ test:
assume ("asdf", capitalized) == "Asdf"
assume ("asdf", uppercase) == "ASDF"
assume ("asdf", with "s" -> "X") == "aXdf"
- assume ("one\ntwo\n", lines) == ["one", "two", ""]
+ assume
+ ("
+ one
+ two
+
+ "), lines
+ ..== ["one", "two", ""]
+
($spec とは $body) parses as ($spec means $body)
test:
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom
index cc1f699..b04e9f4 100644
--- a/examples/how_do_i.nom
+++ b/examples/how_do_i.nom
@@ -248,8 +248,7 @@ say (2 + 3)
# If you need to keep going after an indented region, you can start the next line with ".."
say both "Very long first argument that needs its own line" and also
-.."short second arg"
-
+ "short second arg"
(my favorite number) means (21 + 2)
# This can be nested:
@@ -272,7 +271,11 @@ say "The square root of 2 is \(square root of 2)"
# Or to transform nomsu code into custom lua code using "compile % to %"
(debug only $body) compiles to:
if $DEBUG_ENABLED:
- return (Lua "-- Debug code:\n\($body as lua)")
+ return
+ Lua ("
+ -- Debug code:
+ \($body as lua)
+ ")
..else:
return (Lua "-- (debug code removed for production)")
$DEBUG_ENABLED = (yes)
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index a45b684..67b4569 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -25,7 +25,7 @@ test:
) != "inf"
assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf
- .."Incorrect hashing of null strings"
+ "Incorrect hashing of null strings"
if $use_sha1:
assume ((hash "hello world") == "Kq5sNclPz7QV2+lfQIuc6R7oRu0=")
diff --git a/lib/object.nom b/lib/object.nom
index 72e1588..0cede18 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -81,7 +81,7 @@ test:
(object $classname extends $parent $class_body) compiles to:
unless ($classname.type == "Action"):
compile error at $classname
- .."Expected this to be an action, not a \$classname.type"
+ "Expected this to be an action, not a \$classname.type"
for $ in $classname:
unless ($ is text):
diff --git a/lib/things.nom b/lib/things.nom
index e10b9eb..cf5a53f 100644
--- a/lib/things.nom
+++ b/lib/things.nom
@@ -106,14 +106,14 @@ externally (a class named $classname with $members ((initialize $it)'s meaning))
barf "Cannot set \$key, it's not one of the allowed member fields."
set $class's metatable to {
- .__tostring = ($class -> $class.__type), .__call = (
+ .__tostring = ($class -> $class.__type)
+ .__call =
for ($class with $initial_values):
if ($initial_values == (nil)): return $class
set $initial_values's metatable to $class
if $initial_values.set_up:
$initial_values, set up
return $initial_values
- )
}
if ((initialize)'s meaning):
@@ -136,8 +136,15 @@ externally (a class named $classname with $members ((initialize $it)'s meaning))
return
Lua ("
- \$class_id = a_class_named_1_with(\(quote $classname.stub), \($members as lua)\((Lua ", function(\$class_id)\n \$body_lua\nend") if $class_body else "")\
- ..)
+ \$class_id = a_class_named_1_with(\(quote $classname.stub), \($members as lua)\(
+ (
+ Lua ("
+ , function(\$class_id)
+ \$body_lua
+ end
+ ")
+ ) if $class_body else ""
+ ))
a_\$class_id = function(initial_values) return \($classname.stub, as lua id)(initial_values \
..or {}) end
an_\$class_id, a_\($class_id)_with, an_\($class_id)_with = a_\$class_id, a_\$class_id, a_\$class_id
diff --git a/tools/find.nom b/tools/find.nom
index d2678d2..00b65e5 100755
--- a/tools/find.nom
+++ b/tools/find.nom
@@ -24,7 +24,9 @@ use "lib/consolecolor.nom"
$wildcard = ($(COMMAND LINE ARGS)."--wildcard" or "%*")
$pattern = $(COMMAND LINE ARGS).extras.1
if (any of [not $pattern, $pattern == "*", $pattern == "**"]):
- barf "Usage: nomsu -t find [-l] [--wildcard=<wildcard>] <pattern>, where <pattern> is valid Nomsu code"
+ barf ("
+ Usage: nomsu -t find [-l] [--wildcard=<wildcard>] <pattern>, where <pattern> is valid Nomsu code
+ ")
$pattern = ($pattern, with "\$wildcard\$wildcard" -> "$multi_wildcard")
$pattern = ($pattern, with $wildcard -> "$wildcard")
$pattern_tree = ($pattern parsed)
@@ -47,7 +49,9 @@ $pattern_tree = ($pattern parsed)
return (yes)
$filenames = ($(COMMAND LINE ARGS).extras, from 2 to -1)
if ((#$filenames) == 0):
- say "Warning: searching stdin (ctrl-d to abort). To avoid this message, use nomsu -t find -"
+ say ("
+ Warning: searching stdin (ctrl-d to abort). To avoid this message, use nomsu -t find -
+ ")
$filenames = ["stdin"]
for $filename in $filenames:
@@ -58,7 +62,11 @@ for $filename in $filenames:
try:
$tree = ($code parsed)
..and if it barfs $msg:
- say (red "\$filename failed to parse:\n\$msg")
+ say
+ red ("
+ \$filename failed to parse:
+ \$msg
+ ")
$tree = (nil)
unless $tree:
@@ -68,8 +76,9 @@ for $filename in $filenames:
for $t in recursive $tree:
if ($t matches $pattern_tree):
$line_num = ($file, line number at $t.source.start)
- $results,
- add {.line = $line_num, .text = "\(blue "\$filename:\$line_num:")\n\(source lines of $t)"}
+ $results, add {
+ .line = $line_num, .text = "\(blue "\$filename:\$line_num:")\n\(source lines of $t)"
+ }
for $sub in $t:
if ($sub is syntax tree):
diff --git a/tools/format.nom b/tools/format.nom
index 7d9d1d4..7d8cca1 100755
--- a/tools/format.nom
+++ b/tools/format.nom
@@ -12,7 +12,9 @@ use "lib/os.nom"
$filenames = $(COMMAND LINE ARGS).extras
if ((#$filenames) == 0):
- say "Warning: reading from stdin (ctrl-d to abort). To avoid this message, use nomsu -t format -"
+ say ("
+ Warning: reading from stdin (ctrl-d to abort). To avoid this message, use nomsu -t format -
+ ")
$filenames = ["stdin"]
for $filename in $filenames:
@@ -31,7 +33,7 @@ for $filename in $filenames:
if ($tree and (not $formatted)):
$formatted =
- .."\$leading_indent\($tree as nomsu, text, with "\n" -> "\n\$leading_indent")"
+ "\$leading_indent\($tree as nomsu, text, with "\n" -> "\n\$leading_indent")"
if $formatted:
if $(COMMAND LINE ARGS)."-i":
diff --git a/tools/repl.nom b/tools/repl.nom
index 49a4d3d..ef262e1 100644
--- a/tools/repl.nom
+++ b/tools/repl.nom
@@ -17,7 +17,8 @@ externally (help) means:
say ("
- \(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\(reset color)
+ \(bright)\(underscore)Welcome to the Nomsu v\(Nomsu version) interactive console!\
+ ..\(reset color)
press 'enter' twice to run a command
")
diff --git a/tools/test.nom b/tools/test.nom
index 0202675..1e135db 100755
--- a/tools/test.nom
+++ b/tools/test.nom
@@ -13,7 +13,12 @@ for $filename in $(COMMAND LINE ARGS).extras: use $filename
$tests = {: for $s = $t in $TESTS: add (=lua "Source:from_string(\$s)") = $t}
for $filename in $(COMMAND LINE ARGS).extras:
$file = (read file $filename)
- $version = ($file, matching "#![^\n]* nomsu %-V[ ]*([^\n]*)")
+ $version =
+ $file, matching ("
+ #![^
+ ]* nomsu %-V[ ]*([^
+ ]*)
+ ")
$file_tests = []
for $src = $test in $tests:
if ($src.filename == $filename):
diff --git a/tools/upgrade.nom b/tools/upgrade.nom
index 23716a2..d890dc9 100755
--- a/tools/upgrade.nom
+++ b/tools/upgrade.nom
@@ -24,10 +24,8 @@ for $filename in $(COMMAND LINE ARGS).extras:
$tree = ($code parsed $start_version)
$uptree =
$tree upgraded from ($start_version or ($tree.version or (Nomsu version))) to
- ..$version
-
+ $version
$text = "\$leading_indent\($uptree as nomsu, text, with "\n" -> "\n\$leading_indent")"
-
when:
$inplace:
say "Upgraded \$filename"