aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-18 01:27:56 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-18 01:28:17 -0700
commitd5cfaa37be9e278c44a25ef448a071390597306e (patch)
tree7fbe78b5153bb9c761c283533943ab80da3a1844
parentc7c657d38f999901225b33482ef3a15994526feb (diff)
Upgrading to version 2.3 (main change: "=" instead of "<-" for
assignment)
-rw-r--r--compatibility/2.3.nom16
-rw-r--r--compatibility/2.nom18
-rw-r--r--compatibility/compatibility.nom36
-rw-r--r--core/collections.nom94
-rw-r--r--core/control_flow.nom154
-rw-r--r--core/coroutines.nom2
-rw-r--r--core/errors.nom2
-rw-r--r--core/io.nom2
-rw-r--r--core/math.nom30
-rw-r--r--core/metaprogramming.nom12
-rw-r--r--core/operators.nom41
-rw-r--r--core/scopes.nom19
-rw-r--r--core/text.nom4
-rw-r--r--examples/how_do_i.nom195
-rw-r--r--lib/consolecolor.nom7
-rw-r--r--lib/file_hash.nom10
-rw-r--r--lib/object.nom20
-rw-r--r--lib/os.nom9
-rw-r--r--lib/training_wheels.nom15
-rw-r--r--lib/version.nom2
-rw-r--r--tests/collections.nom61
-rw-r--r--tests/colors.nom4
-rw-r--r--tests/control_flow.nom255
-rw-r--r--tests/coroutines.nom21
-rw-r--r--tests/errors.nom29
-rw-r--r--tests/math.nom26
-rw-r--r--tests/metaprogramming.nom89
-rw-r--r--tests/object.nom105
-rw-r--r--tests/operators.nom92
-rw-r--r--tests/os.nom16
-rw-r--r--tests/scopes.nom22
-rw-r--r--tests/text.nom99
-rw-r--r--tools/autoformat.nom5
-rw-r--r--tools/upgrade.nom16
34 files changed, 700 insertions, 828 deletions
diff --git a/compatibility/2.3.nom b/compatibility/2.3.nom
new file mode 100644
index 0000000..d405181
--- /dev/null
+++ b/compatibility/2.3.nom
@@ -0,0 +1,16 @@
+#!/usr/bin/env nomsu -V2.3
+use "core"
+use "compatibility/compatibility.nom"
+
+upgrade action (%a = %b) to "2.3" as (%a == %b)
+upgrade action (<- %) to "2.3" as (set %)
+upgrade action (assign %) to "2.3" as (set %)
+upgrade action (%a <- %b) to "2.3" as (%a = %b)
+upgrade action (external %a <- %b) to "2.3" as (external %a = %b)
+upgrade action (%a +<- %b) to "2.3" as (%a += %b)
+upgrade action (%a -<- %b) to "2.3" as (%a -= %b)
+upgrade action (%a *<- %b) to "2.3" as (%a *= %b)
+upgrade action (%a /<- %b) to "2.3" as (%a /= %b)
+upgrade action (%a ^<- %b) to "2.3" as (%a ^= %b)
+upgrade action (%a and<- %b) to "2.3" as (%a and= %b)
+upgrade action (%a or<- %b) to "2.3" as (%a or= %b)
diff --git a/compatibility/2.nom b/compatibility/2.nom
index 409f374..9903ddd 100644
--- a/compatibility/2.nom
+++ b/compatibility/2.nom
@@ -1,30 +1,30 @@
-#!/usr/bin/env nomsu -V2
+#!/usr/bin/env nomsu -V2.3.4.3
use "core"
use "compatibility/compatibility.nom"
upgrade %tree to "2" as:
unless (%tree is "Action" syntax tree): return
if (all[%tree.stub is "if % % else %", not (%tree.3 is "Var" syntax tree), not (%tree.5 is "Var" syntax tree)]):
- %true_body <- (%tree.3 upgraded from "1.2")
+ %true_body = (%tree.3 upgraded from "1.2")
unless (%true_body is "Block" syntax tree):
- %true_body <- (=lua "Block(\%true_body.source, \%true_body)")
- %false_body <- (%tree.5 upgraded from "1.2")
+ %true_body = (=lua "Block(\%true_body.source, \%true_body)")
+ %false_body = (%tree.5 upgraded from "1.2")
unless (%false_body is "Block" syntax tree):
- %false_body <- (=lua "Block(\%false_body.source, \%false_body)")
+ %false_body = (=lua "Block(\%false_body.source, \%false_body)")
return (..)
\(if %cond %true_body else %false_body)
..with vars {..}
cond:%tree.2 upgraded from "1.2", true_body:%true_body, false_body:%false_body
- %need_blocks <- [..]
+ %need_blocks = [..]
"if % %", "unless % %", "for % in % %", "for % = % in % %", "repeat while % %"
"repeat % times %", "repeat %", "repeat until % %", "for % in % to % by % %",
"for % in % to % via % %", "for % in % to % %", "for % % in % %", "do %"
"for % in recursive % %", "test %", "with % %", "result of %"
for %n in %need_blocks:
if ((%tree.stub is %n) and (not ((last in %tree) is "Var" syntax tree))):
- %bits <- (((% upgraded from "1.2") if (% is syntax tree) else %) for % in %tree)
+ %bits = (((% upgraded from "1.2") if (% is syntax tree) else %) for % in %tree)
unless ((last in %bits) is "Block" syntax tree):
- %body <- (last in %bits)
- %bits.(length of %bits) <- (=lua "Block(\%body.source, \%body)")
+ %body = (last in %bits)
+ %bits.(length of %bits) = (=lua "Block(\%body.source, \%body)")
return (=lua "Action(\%tree.source, unpack(\%bits))")
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom
index 1e68f35..9482e32 100644
--- a/compatibility/compatibility.nom
+++ b/compatibility/compatibility.nom
@@ -1,24 +1,24 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
use "core"
use "lib/os.nom"
-%UPGRADES <- {}
+%UPGRADES = {}
action [upgrade to %version via %upgrade_fn]:
- %UPGRADES.%version <- %upgrade_fn
+ %UPGRADES.%version = %upgrade_fn
-%ACTION_UPGRADES <- {}
+%ACTION_UPGRADES = {}
action [upgrade action %stub to %version via %upgrade_fn]:
- unless (%ACTION_UPGRADES.%version): %ACTION_UPGRADES.%version <- []
- %ACTION_UPGRADES.%version.%stub <- %upgrade_fn
+ unless (%ACTION_UPGRADES.%version): %ACTION_UPGRADES.%version = []
+ %ACTION_UPGRADES.%version.%stub = %upgrade_fn
parse [upgrade %tree to %version as %body] as (..)
upgrade to %version via ([%] -> (% with %tree -> %body))
compile [upgrade action %action to %version as %body] to:
- %replacements <- {}
+ %replacements = {}
for %i in 1 to (length of %action):
if (%action.%i.type is "Var"):
- %replacements.(%action.%i.1) <- "\(\%tree as lua id)[\%i]"
+ %replacements.(%action.%i.1) = "\(\%tree as lua id)[\%i]"
local action [make tree %t]:
when:
* (%t is "Var" syntax tree):
@@ -27,7 +27,7 @@ compile [upgrade action %action to %version as %body] to:
..else:
return "\(%t.type)(\(quote "\(%t.source)"), \(quote "\(%t.1) \0\(=lua "string.format('%X', __MANGLE_INDEX)")"))"
* (%t is syntax tree):
- %args <- ((make tree %) for % in %t)
+ %args = ((make tree %) for % in %t)
add "\(\%tree as lua id).source" to %args at index 1
return "\(%t.type)(\(%args joined with ", "))"
*else: return (quote "\%t")
@@ -43,20 +43,20 @@ action [..]
%tree upgraded to %end_version from %start_version
..:
local action [%ver as list] ((% as number) for % where %ver matches "[0-9]+")
- %versions <- {}
- for %v = % in %UPGRADES: %versions.%v <- (yes)
- for %v = % in %ACTION_UPGRADES: %versions.%v <- (yes)
- %versions <- ((keys in %versions) sorted by % -> (% as list))
+ %versions = {}
+ for %v = % in %UPGRADES: %versions.%v = (yes)
+ for %v = % in %ACTION_UPGRADES: %versions.%v = (yes)
+ %versions = ((keys in %versions) sorted by % -> (% as list))
for %ver in %versions:
if ((%ver as list) <= (%start_version as list)): do next %ver
if ((%ver as list) > (%end_version as list)): stop %ver
if %ACTION_UPGRADES.%ver:
- %tree <- (..)
+ %tree = (..)
%tree with % -> (..)
if ((% is "Action" syntax tree) and %ACTION_UPGRADES.%ver.(%.stub)):
return (call %ACTION_UPGRADES.%ver.(%.stub) with [%])
if %UPGRADES.%ver:
- %tree <- (call %UPGRADES.%ver with [%tree])
+ %tree = (call %UPGRADES.%ver with [%tree])
return %tree
@@ -72,7 +72,7 @@ parse [%tree upgraded] as (%tree upgraded from %tree.version to (Nomsu version))
action [use %path from version %version] (..)
for file %filename in %path:
if (=lua "LOADED[\%filename]"): do next %filename
- %file <- (read file %filename)
- %tree <- (parse %file from %filename)
- %tree <- (upgrade %tree from %version)
+ %file = (read file %filename)
+ %tree = (parse %file from %filename)
+ %tree = (upgrade %tree from %version)
run tree %tree
diff --git a/core/collections.nom b/core/collections.nom
index d99ae49..45ca74c 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains code that supports manipulating and using collections like lists
and dictionaries.
@@ -34,22 +34,22 @@ action [..]
for %key = %value in %list: if (%key is %item): return (no)
return (yes)
-test: assume ({"x": no} has key "x")
+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"))
+ 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
-..as (%list.%index = (nil))
+..as (%list.%index == (nil))
compile [number of keys in %list] to (..)
Lua value "utils.size(\(%list as lua expr))"
test:
- %list <- [1, 2, 3, 4, 5]
+ %list = [1, 2, 3, 4, 5]
append 6 to %list
assume ((last in %list) is 6)
pop from %list
@@ -74,10 +74,10 @@ compile [remove index %index from %list] to (..)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# List Comprehension
-test: assume (((% * %) for % in [1, 2, 3]) = [1, 4, 9])
+test: assume (((% * %) for % in [1, 2, 3]) == [1, 4, 9])
parse [%expression for %item in %iterable] as (..)
result of:
- %comprehension <- []
+ %comprehension = []
for %item in %iterable: add %expression to %comprehension
return %comprehension
@@ -86,47 +86,46 @@ parse [..]
%expression for %index in %start to %stop by %step
..as (..)
result of:
- %comprehension <- []
+ %comprehension = []
for %index in %start to %stop via %step: add %expression to %comprehension
return %comprehension
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-test: assume (((% * %) for % in 1 to 3) = [1, 4, 9])
+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"])
+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
..as (..)
result of:
- %comprehension <- []
+ %comprehension = []
for %key = %value in %iterable: add %expression to %comprehension
return %comprehension
# Dict comprehensions
-test: assume (((% * %) = % for % in [1, 2, 3]) = {1: 1, 4: 2, 9: 3})
+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:
- %comprehension <- {}
- for %item in %iterable: %comprehension.%key <- %value
+ %comprehension = {}
+ for %item in %iterable: %comprehension.%key = %value
return %comprehension
test:
- assume (..)
- (%k = (%v * %v) for %k = %v in {"x": 1, "y": 2, "z": 3}) = {"x": 1, "y": 4, "z": 9}
+ 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
..as (..)
result of:
- %comprehension <- {}
- for %src_key = %src_value in %iterable: %comprehension.%key <- %value
+ %comprehension = {}
+ for %src_key = %src_value in %iterable: %comprehension.%key = %value
return %comprehension
parse [..]
@@ -134,41 +133,41 @@ parse [..]
%key %value for %item in %start to %stop via %step
..as (..)
result of:
- %comprehension <- {}
- for %item in %start to %stop via %step: %comprehension.%key <- %value
+ %comprehension = {}
+ for %item in %start to %stop via %step: %comprehension.%key = %value
return %comprehension
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-test: assume (((% * %) = % for % in 1 to 3) = {1: 1, 4: 2, 9: 3})
+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
..as (%key = %value for %item in %start to %stop via 1)
-test: assume (([[1, 2], [3, 4]] flattened) = [1, 2, 3, 4])
+test: assume (([[1, 2], [3, 4]] flattened) == [1, 2, 3, 4])
action [%lists flattened]:
- %flat <- []
+ %flat = []
for %list in %lists: for %item in %list: add %item to %flat
return %flat
-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"])
+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])
+test: assume ((values in {x: 1}) == [1])
parse [values in %dict, values of %dict] as (%v for %k = %v in %dict)
# Metatable stuff
test:
- %t <- {}
- set %t 's metatable to {"__tostring": [%] -> "XXX"}
- assume ("\%t" = "XXX")
+ %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)
+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))
@@ -180,41 +179,38 @@ compile [%dict with fallback %key -> %value] to (..)
# Sorting
test:
- %x <- [3, 1, 2]
+ %x = [3, 1, 2]
sort %x
- assume (%x = [1, 2, 3])
+ assume (%x == [1, 2, 3])
sort %x by % = (- %)
- assume (%x = [3, 2, 1])
- %keys <- {1: 999, 2: 0, 3: 50}
+ assume (%x == [3, 2, 1])
+ %keys = {1: 999, 2: 0, 3: 50}
sort %x by % = %keys.%
- assume (%x = [2, 3, 1])
+ 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:
- %keys <- ({} with fallback %item -> %key_expr)
+ %keys = ({} with fallback %item -> %key_expr)
lua> "table.sort(\%items, function(x,y) return \%keys[x] < \%keys[y] end)"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-test: assume ((sorted [3, 1, 2]) = [1, 2, 3])
+test: assume ((sorted [3, 1, 2]) == [1, 2, 3])
action [%items sorted, sorted %items]:
- %copy <- (% for % in %items)
+ %copy = (% for % in %items)
sort %copy
return %copy
parse [%items sorted by %item = %key, %items sorted by %item -> %key] as (..)
result of:
- %copy <- (% for % in %items)
+ %copy = (% for % in %items)
sort %copy by %item = %key
return %copy
-test: assume ((unique [1, 2, 1, 3, 2, 3]) = [1, 2, 3])
+test: assume ((unique [1, 2, 1, 3, 2, 3]) == [1, 2, 3])
action [unique %items]:
- %unique <- []
- %seen <- {}
- for % in %items:
- unless %seen.%:
- add % to %unique
- %seen.% <- (yes)
- return %unique
+ %unique = []
+ %seen = {}
+ for % in %items: unless %seen.% (: add % to %unique; %seen.% = (yes))
+ return %unique \ No newline at end of file
diff --git a/core/control_flow.nom b/core/control_flow.nom
index bb30e49..b3f0978 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains compile-time actions that define basic control flow structures
like "if" statements and loops.
@@ -15,10 +15,7 @@ compile [do nothing] to (Lua "")
# Conditionals
test: if (no): barf "conditional fail"
compile [if %condition %if_body] to (..)
- Lua ".."
- if \(%condition as lua expr) then
- \(%if_body as lua statements)
- end
+ Lua "if \(%condition as lua expr) then\n \(%if_body as lua statements)\nend"
test: unless (yes): barf "conditional fail"
parse [unless %condition %unless_body] as (if (not %condition) %unless_body)
@@ -43,10 +40,9 @@ compile [..]
%when_false_expr unless %condition else %when_true_expr
%when_false_expr unless %condition then %when_true_expr
..to (..)
-
# If %when_true_expr is guaranteed to be truthy, we can use Lua's idiomatic
equivalent of a conditional expression: (cond and if_true or if_false)
- if {"Text": yes, "List": yes, "Dict": yes, "Number": yes}.(%when_true_expr.type):
+ if {Text: yes, List: yes, Dict: yes, Number: yes}.(%when_true_expr.type):
return (..)
Lua value ".."
(\(%condition as lua expr) and \(%when_true_expr as lua expr) or \(%when_false_expr as lua expr))
@@ -65,13 +61,11 @@ compile [..]
end
end)())
-
# GOTOs
compile [=== %label ===, --- %label ---, *** %label ***] to (..)
Lua "::label_\(%label as lua identifier)::"
-compile [go to %label] to (..)
- Lua "goto label_\(%label as lua identifier)"
+compile [go to %label] to (Lua "goto label_\(%label as lua identifier)")
# Basic loop control
compile [do next] to (Lua "continue")
@@ -96,18 +90,19 @@ compile [%tree has subtree %subtree where %condition] to (..)
compile [do next repeat] to (Lua "goto continue_repeat")
compile [stop repeating] to (Lua "goto stop_repeat")
compile [repeat while %condition %body] to:
- %lua <- (..)
- Lua ".."
- while \(%condition as lua expr) do
- \(%body as lua statements)
+ %lua = (..)
+ Lua "while \(%condition as lua expr) do\n \(%body as lua statements)"
if (..)
- %body has subtree % where ((%.type = "Action") and (%.stub is "do next repeat"))
- ..: to %lua write "\n ::continue_repeat::"
+ %body has subtree % where ((%.type == "Action") and (%.stub is "do next repeat"))
+ ..:
+ to %lua write "\n ::continue_repeat::"
to %lua write "\nend --while-loop"
- if (%body has subtree % where ((%.type = "Action") and (%.stub is "stop repeating"))):
- %lua <- (..)
+ if (..)
+ %body has subtree % where ((%.type == "Action") and (%.stub is "stop repeating"))
+ ..:
+ %lua = (..)
Lua ".."
do -- scope of "stop repeating" label
\%lua
@@ -119,13 +114,19 @@ 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)
compile [repeat %n times %body] to:
- %lua <- (Lua "for i=1,\(%n as lua expr) do\n \(%body as lua statements)")
- if (%body has subtree % where ((%.type = "Action") and (%.stub is "do next repeat"))):
+ %lua = (..)
+ Lua "for i=1,\(%n as lua expr) do\n \(%body as lua statements)"
+
+ if (..)
+ %body has subtree % where ((%.type == "Action") and (%.stub is "do next repeat"))
+ ..:
to %lua write "\n ::continue_repeat::"
to %lua write "\nend --numeric for-loop"
- if (%body has subtree % where ((%.type = "Action") and (%.stub is "stop repeating"))):
- %lua <- (..)
+ if (..)
+ %body has subtree % where ((%.type == "Action") and (%.stub is "stop repeating"))
+ ..:
+ %lua = (..)
Lua ".."
do -- scope of "stop repeating" label
\%lua
@@ -151,24 +152,26 @@ compile [..]
for %var in %start to %stop by %step %body
for %var in %start to %stop via %step %body
..to:
+
# This uses Lua's approach of only allowing loop-scoped variables in a loop
assume (%var.type is "Var") or barf "Loop expected variable, not: \%var"
- %lua <- (..)
+ %lua = (..)
Lua ".."
for \(%var as lua expr)=\(%start as lua expr),\(%stop as lua expr),\(%step as lua expr) do
\(%body as lua statements)
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "do next %") and (%.(3).1 = %var.1))
- ..: to %lua write "\n \(compile as (===next %var ===))"
+ (%.type == "Action") and ((%.stub is "do next %") and (%.(3).1 == %var.1))
+ ..:
+ to %lua write "\n \(compile as (===next %var ===))"
to %lua write "\nend --numeric for-loop"
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "stop %") and (%.(2).1 = %var.1))
+ (%.type == "Action") and ((%.stub is "stop %") and (%.(2).1 == %var.1))
..:
- %lua <- (..)
+ %lua = (..)
Lua ".."
do -- scope for stopping for-loop
\%lua
@@ -185,24 +188,27 @@ parse [for %var in %start to %stop %body] as (..)
# For-each loop (lua's "ipairs()")
compile [for %var in %iterable %body] to:
+
# This uses Lua's approach of only allowing loop-scoped variables in a loop
assume (%var.type is "Var") or barf "Loop expected variable, not: \%var"
- %lua <- (..)
+ %lua = (..)
Lua ".."
for i,\(%var as lua identifier) in ipairs(\(%iterable as lua expr)) do
\(%body as lua statements)
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "do next %") and (%.(3).1 = %var.1))
- ..: to %lua write (Lua "\n\(compile as (===next %var ===))")
+ (%.type == "Action") and ((%.stub is "do next %") and (%.(3).1 == %var.1))
+ ..:
+ to %lua write (..)
+ Lua "\n\(compile as (===next %var ===))"
to %lua write "\nend --foreach-loop"
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "stop %") and (%.(2).1 = %var.1))
+ (%.type == "Action") and ((%.stub is "stop %") and (%.(2).1 == %var.1))
..:
- %lua <- (..)
+ %lua = (..)
Lua ".."
do -- scope for stopping for-loop
\%lua
@@ -213,39 +219,47 @@ compile [for %var in %iterable %body] to:
# Dict iteration (lua's "pairs()")
-compile [for %key = %value in %iterable %body, for %key %value in %iterable %body] to:
+compile [for %key = %value in %iterable %body, for %key %value in %iterable %body]
+..to:
+
# This uses Lua's approach of only allowing loop-scoped variables in a loop
assume (%key.type is "Var") or barf "Loop expected variable, not: \%key"
assume (%value.type is "Var") or barf "Loop expected variable, not: \%value"
- %lua <- (..)
+ %lua = (..)
Lua ".."
for \(%key as lua identifier),\(%value as lua identifier) in pairs(\(%iterable as lua expr)) do
\(%body as lua statements)
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "do next %") and (%.(3).1 = %key.1))
- ..: to %lua write (Lua "\n\(compile as (===next %key ===))")
+ (%.type == "Action") and ((%.stub is "do next %") and (%.(3).1 == %key.1))
+ ..:
+ to %lua write (..)
+ Lua "\n\(compile as (===next %key ===))"
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "do next %") and (%.(3).1 = %value.1))
- ..: to %lua write (Lua "\n\(compile as (===next %value ===))")
+ (%.type == "Action") and ((%.stub is "do next %") and (%.(3).1 == %value.1))
+ ..:
+ to %lua write (..)
+ Lua "\n\(compile as (===next %value ===))"
to %lua write "\nend --foreach-loop"
- %stop_labels <- (Lua "")
+ %stop_labels = (Lua "")
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "stop %") and (%.(2).1 = %key.1))
- ..: to %stop_labels write "\n\(compile as (===stop %key ===))"
+ (%.type == "Action") and ((%.stub is "stop %") and (%.(2).1 == %key.1))
+ ..:
+ to %stop_labels write "\n\(compile as (===stop %key ===))"
if (..)
%body has subtree % where (..)
- (%.type = "Action") and ((%.stub is "stop %") and (%.(2).1 = %value.1))
- ..: to %stop_labels write "\n\(compile as (===stop %value ===))"
+ (%.type == "Action") and ((%.stub is "stop %") and (%.(2).1 == %value.1))
+ ..:
+ to %stop_labels write "\n\(compile as (===stop %value ===))"
if ((length of "\%stop_labels") > 0):
- %lua <- (..)
+ %lua = (..)
Lua "do -- scope for stopping for % = % loop\n \%lua\%stop_labels\nend"
return %lua
@@ -254,15 +268,15 @@ compile [for %key = %value in %iterable %body, for %key %value in %iterable %bod
# Switch statement/multi-branch if
compile [when %body] to:
- %code <- (Lua "")
- %fallthroughs <- []
- %is_first <- (yes)
- %seen_else <- (no)
- %branches <- (%body if (%body.type = "Block") else [%body])
+ %code = (Lua "")
+ %fallthroughs = []
+ %is_first = (yes)
+ %seen_else = (no)
+ %branches = (%body if (%body.type == "Block") else [%body])
for %func_call in %branches:
assume (%func_call.type is "Action") or barf "Invalid format for 'when' statement. Only '*' blocks are allowed."
with {%star: %func_call.1, %condition: %func_call.2, %action: %func_call.3}:
- assume (%star = "*") or barf "Invalid format for 'when' statement. Lines must begin with '*'"
+ assume (%star == "*") or barf "Invalid format for 'when' statement. Lines must begin with '*'"
assume %condition or barf ".."
Invalid format for 'when' statement. Lines must begin with '*' and have a condition \
..or the word "else"
@@ -271,11 +285,11 @@ compile [when %body] to:
lua> "table.insert(\%fallthroughs, \(%condition as lua expr))"
do next %func_call
- if (%condition = "else"):
+ if (%condition == "else"):
assume (not %is_first) or barf "'else' clause cannot be first in 'when % = ?' block"
to %code write "\nelse\n "
to %code write (%action as lua statements)
- %seen_else <- (yes)
+ %seen_else = (yes)
..else:
assume (not %seen_else) or barf "'else' clause needs to be last in 'when' block"
lua> "table.insert(\%fallthroughs, \(%condition as lua expr))"
@@ -287,26 +301,26 @@ compile [when %body] to:
to %code write " then\n "
to %code write (%action as lua statements)
- %fallthroughs <- []
- %is_first <- (no)
+ %fallthroughs = []
+ %is_first = (no)
- assume (%fallthroughs = []) or barf "Unfinished fallthrough conditions in 'when' block"
+ assume (%fallthroughs == []) or barf "Unfinished fallthrough conditions in 'when' block"
assume ((length of "\%code") > 0) or barf "Empty body for 'when' block"
to %code write "\nend --when"
return %code
# Switch statement
-compile [when %branch_value = ? %body, when %branch_value is ? %body] to:
- %code <- (Lua "")
- %fallthroughs <- []
- %is_first <- (yes)
- %seen_else <- (no)
- %branches <- (%body if (%body.type = "Block") else [%body])
+compile [when %branch_value = ? %body, when %branch_value is? %body] to:
+ %code = (Lua "")
+ %fallthroughs = []
+ %is_first = (yes)
+ %seen_else = (no)
+ %branches = (%body if (%body.type == "Block") else [%body])
for %func_call in %branches:
assume (%func_call.type is "Action") or barf "Invalid format for 'when' statement. Only '*' blocks are allowed."
with {%star: %func_call.1, %condition: %func_call.2, %action: %func_call.3}:
- assume (%star = "*") or barf "Invalid format for 'when' statement. Lines must begin with '*'"
+ assume (%star == "*") or barf "Invalid format for 'when' statement. Lines must begin with '*'"
assume %condition or barf ".."
Invalid format for 'when' statement. Lines must begin with '*' and have a condition \
..or the word "else"
@@ -315,7 +329,7 @@ compile [when %branch_value = ? %body, when %branch_value is ? %body] to:
lua> "table.insert(\%fallthroughs, \(%condition as lua expr))"
do next %func_call
- if (%condition = "else"):
+ if (%condition == "else"):
assume (not %is_first) or barf "'else' clause cannot be first in 'when % = ?' block"
to %code write "\nelse\n "
to %code write (%action as lua statements)
@@ -332,13 +346,13 @@ compile [when %branch_value = ? %body, when %branch_value is ? %body] to:
to %code write "then\n "
to %code write (%action as lua statements)
- %fallthroughs <- []
- %is_first <- (no)
+ %fallthroughs = []
+ %is_first = (no)
- assume (%fallthroughs = []) or barf "Unfinished fallthrough conditions in 'when' block"
+ assume (%fallthroughs == []) or barf "Unfinished fallthrough conditions in 'when' block"
assume ((length of "\%code") > 0) or barf "No body for 'when % = ?' block!"
to %code write "\nend"
- %code <- (..)
+ %code = (..)
Lua ".."
do --when % = ?
local branch_value = \(%branch_value as lua expr)
@@ -350,10 +364,8 @@ compile [when %branch_value = ? %body, when %branch_value is ? %body] to:
# Do/finally
compile [do %action] to (..)
- Lua ".."
- do
- \(%action as lua statements)
- end --do
+ Lua "do\n \(%action as lua statements)\nend --do"
+
compile [do %action then always %final_action] to (..)
Lua ".."
do
diff --git a/core/coroutines.nom b/core/coroutines.nom
index c14042c..54889d4 100644
--- a/core/coroutines.nom
+++ b/core/coroutines.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file defines the code that creates and manipulates coroutines
diff --git a/core/errors.nom b/core/errors.nom
index 42348a9..efa69a8 100644
--- a/core/errors.nom
+++ b/core/errors.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains basic error reporting code
diff --git a/core/io.nom b/core/io.nom
index e04c88b..2659b3b 100644
--- a/core/io.nom
+++ b/core/io.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains basic input/output code
diff --git a/core/math.nom b/core/math.nom
index 9d432e7..d8952f6 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file defines some common math literals and functions
@@ -57,7 +57,7 @@ compile [all of %items, all %items] to:
unless (%items.type is "List"):
return (Lua value "utils.all(\(%items as lua expr))")
- %clauses <- ((% as lua expr) for % in %items)
+ %clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " and "))")
parse [not all of %items, not all %items] as (not (all of %items))
@@ -65,7 +65,7 @@ compile [any of %items, any %items] to:
unless (%items.type is "List"):
return (Lua value "utils.any(\(%items as lua expr))")
- %clauses <- ((% as lua expr) for % in %items)
+ %clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " or "))")
parse [none of %items, none %items] as (not (any of %items))
@@ -73,14 +73,14 @@ compile [sum of %items, sum %items] to:
unless (%items.type is "List"):
return (Lua value "utils.sum(\(%items as lua expr))")
- %clauses <- ((% as lua expr) for % in %items)
+ %clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " + "))")
compile [product of %items, product %items] to:
unless (%items.type is "List"):
return (Lua value "utils.product(\(%items as lua expr))")
- %clauses <- ((% as lua expr) for % in %items)
+ %clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses joined with " * "))")
action [avg of %items, average of %items] (=lua "(utils.sum(\%items)/#\%items)")
@@ -92,21 +92,21 @@ compile [max of %items, biggest of %items, largest of %items, highest of %items]
parse [min of %items by %item = %value_expr] as (..)
result of:
- <- {%best: nil, %best_key: nil}
+ set {%best: nil, %best_key: nil}
for %item in %items:
- %key <- %value_expr
- if ((%best = (nil)) or (%key < %best_key)):
- <- {%best: %item, %best_key: %key}
+ %key = %value_expr
+ if ((%best == (nil)) or (%key < %best_key)):
+ set {%best: %item, %best_key: %key}
return %best
parse [max of %items by %item = %value_expr] as (..)
result of:
- <- {%best: nil, %best_key: nil}
+ set {%best: nil, %best_key: nil}
for %item in %items:
- %key <- %value_expr
- if ((%best = (nil)) or (%key > %best_key)):
- <- {%best: %item, %best_key: %key}
+ %key = %value_expr
+ if ((%best == (nil)) or (%key > %best_key)):
+ set {%best: %item, %best_key: %key}
return %best
@@ -123,5 +123,5 @@ compile [random int %n, random integer %n, randint %n] to (..)
compile [random from %low to %high, random number from %low to %high, rand %low %high]
..to (Lua value "math.random(\(%low as lua expr), \(%high as lua expr))")
-action [random choice from %elements, random choice %elements, random %elements] (..)
- =lua "\%elements[math.random(#\%elements)]"
+action [random choice from %elements, random choice %elements, random %elements]
+..(=lua "\%elements[math.random(#\%elements)]") \ No newline at end of file
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index c81eb74..8328d26 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This File contains actions for making actions and compile-time actions and some helper
functions to make that easier.
@@ -13,7 +13,7 @@ lua> ".."
local body_lua = AST.is_syntax_tree(\%body) and nomsu:compile(\%body):as_statements("return ") or \%body
body_lua:remove_free_vars(lua_args)
body_lua:declare_locals()
- lua:append(")\n ", body_lua, "\nend")
+ lua:append(")\\n ", body_lua, "\\nend")
return lua
end
@@ -37,7 +37,8 @@ lua> ".."
"] = ", \(compile as (%args -> %body)))
for i=2,#\%actions do
local alias = \%actions[i]
- local \%alias_args = {"nomsu", "tree", unpack(table.map(alias:get_args(), function(a) return tostring(nomsu:compile(a)) end))}
+ local \%alias_args = {"nomsu", "tree", unpack(table.map(alias:get_args(), function(a) return tostring(nomsu:compile(a)) \
+ ..end))}
lua:append("\\nnomsu.COMPILE_ACTIONS[", repr(alias.stub), "] = ")
if utils.equivalent(\%args, \%alias_args) then
lua:append("nomsu.COMPILE_ACTIONS[", repr(\%actions[1].stub), "]")
@@ -107,7 +108,8 @@ compile [parse %actions as %body] to (..)
elseif replacements[t[1]] then
return replacements[t[1]]
else
- return t.type.."("..repr(tostring(t.source))..", "..repr(t[1].." \\0").."..string.format('%X', __MANGLE_INDEX))"
+ return t.type.."("..repr(tostring(t.source))..", "..repr(t[1].." \\0").."..string.format('%X', \
+ ..__MANGLE_INDEX))"
end
end
local \%new_body = LuaCode(\%body.source,
@@ -230,4 +232,4 @@ compile [with local compile actions %body] to (..)
action [Nomsu version]:
use "lib/version.nom"
return ".."
- \(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
+ \(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version) \ No newline at end of file
diff --git a/core/operators.nom b/core/operators.nom
index eeb5e7a..70b0207 100644
--- a/core/operators.nom
+++ b/core/operators.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains definitions of operators like "+" and "and".
@@ -10,7 +10,7 @@ compile [%x < %y] to (Lua value "(\(%x as lua expr) < \(%y as lua expr))")
compile [%x > %y] to (Lua value "(\(%x as lua expr) > \(%y as lua expr))")
compile [%x <= %y] to (Lua value "(\(%x as lua expr) <= \(%y as lua expr))")
compile [%x >= %y] to (Lua value "(\(%x as lua expr) >= \(%y as lua expr))")
-compile [%a is %b, %a = %b, %a == %b] to (..)
+compile [%a is %b, %a == %b] to (..)
Lua value "(\(%a as lua expr) == \(%b as lua expr))"
compile [%a isn't %b, %a is not %b, %a not= %b, %a != %b] to (..)
@@ -40,7 +40,7 @@ compile [% 's id, id of %] to (Lua value "IDS[\(% as lua expr)]")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Variable assignment operator
-compile [%var <- %value] to:
+compile [%var = %value] to:
lua> "local \%var_lua = \(%var as lua)"
assume %var_lua.is_value or barf "Invalid target for assignment: \%var"
lua> ".."
@@ -61,7 +61,7 @@ compile [%var <- %value] to:
# Simultaneous mutli-assignments like: x,y,z = 1,x,3;
-compile [<- %assignments, assign %assignments] to:
+compile [set %assignments] to:
assume (%assignments.type is "Dict") or barf ".."
Expected a Dict for the assignments part of '<- %' statement, not \%assignments
@@ -92,22 +92,22 @@ compile [<- %assignments, assign %assignments] to:
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-compile [external %var <- %value] to:
- %var_lua <- (%var as lua)
+compile [external %var = %value] to:
+ %var_lua = (%var as lua)
assume %var_lua.is_value or barf "Invalid target for assignment: \%var"
- %value_lua <- (%value as lua)
+ %value_lua = (%value as lua)
assume %value_lua.is_value or barf "Invalid value for assignment: \%value"
return (Lua "\%var_lua = \%value_lua;")
compile [with external %externs %body] to:
- %body_lua <- (%body as lua statements)
+ %body_lua = (%body as lua statements)
lua> ".."
\%body_lua:remove_free_vars(table.map(\%externs, function(v) return tostring(nomsu:compile(v)) end))
return %body_lua
compile [with %assignments %body] to:
- %lua <- (%body as lua statements)
+ %lua = (%body as lua statements)
lua> ".."
local lhs, rhs = LuaCode(tree.source), LuaCode(tree.source)
local vars = {}
@@ -135,10 +135,7 @@ compile [with %assignments %body] to:
\%lua:prepend("local ", lhs, " = ", rhs, ";\\n")
return (..)
- Lua ".."
- do
- \%lua
- end -- 'with' block
+ Lua "do\n \%lua\nend -- 'with' block"
# Math Operators
@@ -194,17 +191,17 @@ compile [%x ARSHIFT %shift, %x >> %shift] to (..)
# Unary operators
compile [- %] to (Lua value "(- \(% as lua expr))")
compile [not %] to (Lua value "(not \(% as lua expr))")
-test: assume ((length of [1, 2, 3]) = 3)
+test: assume ((length of [1, 2, 3]) == 3)
compile [length of %list, || %list ||] to (Lua value "(#\(%list as lua expr))")
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Update operators
-parse [%var + <- %, %var +<- %] as (%var <- (%var + %))
-parse [%var - <- %, %var -<- %] as (%var <- (%var - %))
-parse [%var * <- %, %var *<- %] as (%var <- (%var * %))
-parse [%var / <- %, %var /<- %] as (%var <- (%var / %))
-parse [%var ^ <- %, %var ^<- %] as (%var <- (%var ^ %))
-parse [%var and<- %] as (%var <- (%var and %))
-parse [%var or<- %] as (%var <- (%var or %))
-parse [wrap %var around %] as (%var <- (%var wrapped around %))
+parse [%var += %] as (%var = (%var + %))
+parse [%var -= %] as (%var = (%var - %))
+parse [%var *= %] as (%var = (%var * %))
+parse [%var /= %] as (%var = (%var / %))
+parse [%var ^= %] as (%var = (%var ^ %))
+parse [%var and= %] as (%var = (%var and %))
+parse [%var or= %] as (%var = (%var or %))
+parse [wrap %var around %] as (%var = (%var wrapped around %))
diff --git a/core/scopes.nom b/core/scopes.nom
index 256ddd5..2be24e6 100644
--- a/core/scopes.nom
+++ b/core/scopes.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains definitions pertaining to variable scoping
@@ -7,21 +7,18 @@ use "core/operators.nom"
use "core/collections.nom"
use "core/control_flow.nom"
compile [with local %locals %body, with local %locals do %body] to:
- %body_lua <- (%body as lua statements)
+ %body_lua = (%body as lua statements)
when %locals.type = ?:
* "Dict":
- %body_lua <- (Lua "\(compile as (<- %locals))\n\%body_lua")
+ %body_lua = (..)
+ Lua "\(compile as (<- %locals))\n\%body_lua"
+
declare locals ("\(%.1 as lua)" for % in %locals) in %body_lua
- * "List":
- declare locals ("\(% as lua)" for % in %locals) in %body_lua
+ * "List": declare locals ("\(% as lua)" for % in %locals) in %body_lua
* "Var"
- * "Action":
- declare locals ["\(%locals as lua)"] in %body_lua
+ * "Action": declare locals ["\(%locals as lua)"] in %body_lua
*else (barf "Unexpected local: \(%locals as nomsu)")
return (..)
- Lua ".."
- do
- \%body_lua
- end
+ Lua "do\n \%body_lua\nend" \ No newline at end of file
diff --git a/core/text.nom b/core/text.nom
index fa0d908..62ec056 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains some definitions of text escape sequences, including ANSI console
color codes.
@@ -66,4 +66,4 @@ lua> ".."
return LuaCode.Value(tree.source, lua)
end
end
- end
+ end \ No newline at end of file
diff --git a/examples/how_do_i.nom b/examples/how_do_i.nom
index e91e9a1..01f2de4 100644
--- a/examples/how_do_i.nom
+++ b/examples/how_do_i.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
# How do I...
# Write a comment? Put a # and go till the end of the line
# How do I write a multi-line comment?
@@ -16,23 +16,23 @@ use "core"
say "Hello world!"
# How do I set a variable?
-%foobar <- 1
-%text <- "Hello world"
+%foobar = 1
+%text = "Hello world"
# Expressions that are more than just literal values require parentheses:
-%foobar <- (2 + 3)
-%one-two <- 12
-say %one-two
+%foobar = (2 + 3)
+%one_two = 12
+say %one_two
# How do I modify a variable?
-%foobar <- (%foobar + 1)
+%foobar = (%foobar + 1)
# Or, as a shorthand, you can do this to increment a variable:
-%foobar +<- 1
+%foobar += 1
# How do I define a mutli-line string?
# In Nomsu, "strings" are called "text", and multi-line text looks like:
-%mutli-text <- ".."
+%mutli_text = ".."
Start with "..", then put indented lines below it. The indented lines will not include
the indentation, except when the lines are indented more than 4 spaces relative
to the "..".
@@ -59,124 +59,100 @@ say ".."
If you need to split a long line without inserting a newline, you can end a line \
..with backslash and start the next line with two periods, like that.
- Similarly, you can put a long interpolated indented value like: \(..)
- 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9
- .. between a backslash and two periods.
+ Similarly, you can put a long interpolated indented value like: \(1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9) between a backslash and two periods.
-say "Single-line text can contain escape sequences like \", \\, \n, \065, and \x0A"
+say "Single-line text can contain escape sequences like \", \\, \n, A, and \n"
# How do I define a list?
-%my-list <- [1, 2, "hello"]
+%my_list = [1, 2, "hello"]
# Really long lists can use [..] followed by a bunch of indented values delimited
by commas and/or newlines
-%my-really-long-list <- [..]
- 1, 2, 3, 4
- 5, 6
- 7
- 8, 9, 10
+%my_really_long_list = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# How do I use a list?
-%my-list <- ["first item", "second item", "third item"]
+%my_list = ["first item", "second item", "third item"]
# Lists are 1-indexed because they're implemented as Lua tables, so this prints "first item"
-say %my-list.1
+say %my_list.1
# List entries can be modified like this:
-%my-list.1 <- "ONE!!!"
-say (length of %my-list)
+%my_list.1 = "ONE!!!"
+say (length of %my_list)
# How do I define a dictionary/hash map?
-%my-dict <- {x: 99, y: 101}
-%my-dict <- {..}
- x: 101, y: 2
- "99 bottles": 99
- 653: 292
+%my_dict = {x: 99, y: 101}
+%my_dict = {x: 101, y: 2, "99 bottles": 99, 653: 292}
# How do I use a dict?
# Dicts are also implemented as Lua tables, so they're accessed and modified the same way as lists
-say %my-dict.x
-%my-dict.x <- 9999
+say %my_dict.x
+%my_dict.x = 9999
# How do I do conditional branching?
-if (1 < 10):
- say "1 is indeed < 10"
-if (1 > 10):
- say "this won't print"
-..else:
- say "this will print"
+if (1 < 10): say "1 is indeed < 10"
+if (1 > 10): say "this won't print"
+..else: say "this will print"
+
# There's no "elseif", so for longer conditionals, a "when" branch is the best option
when:
* (3 > 6)
* (3 > 5)
- * (3 > 4):
- say "this won't print"
- * (3 > 3):
- say "this won't print"
- * (3 > 2):
- say "this will print"
- *else:
- say "this is the default case"
+ * (3 > 4): say "this won't print"
+ * (3 > 3): say "this won't print"
+ * (3 > 2): say "this will print"
+ *else: say "this is the default case"
# How do I do a switch statement?
when 3 = ?:
* 0
* 1
- * 2:
- say "this won't print"
- * 3:
- say "this will print"
- *else:
- say "this won't print"
+ * 2: say "this won't print"
+ * 3: say "this will print"
+ *else: say "this won't print"
# How do I loop over a list (a foreach loop)?
-%list <- [1, 2, 3]
-for %x in %list:
- say "For %x loop #\%x"
+%list = [1, 2, 3]
+for %x in %list: say "For %x loop #\%x"
# How do I loop over a number range?
# This is inclusive, so it will loop over 1,2, and 3
-for %i in 1 to 3:
- say "For %i in 1 to 3 loop #\%i"
+for %i in 1 to 3: say "For %i in 1 to 3 loop #\%i"
# This will print 0,2, and 4
-for %even in 0 to 5 by 2:
- say "Even #\%even"
-for %backwards in 3 to 1 by -1:
- say "Backwards #\%backwards"
+for %even in 0 to 5 by 2: say "Even #\%even"
+for %backwards in 3 to 1 by -1: say "Backwards #\%backwards"
# How do I do a 'while' loop?
-%x <- 1
+%x = 1
repeat while (%x <= 3):
say "repeat while loop #\%x"
- %x +<- 1
+ %x += 1
-%x <- 1
+%x = 1
repeat until (%x > 3):
say "repeat until loop #\%x"
- %x +<- 1
+ %x += 1
# How do I do an infinite loop?
-%x <- 1
+%x = 1
repeat:
say "repeat loop #\%x"
- %x +<- 1
- if (%x > 3):
- stop repeating
+ %x += 1
+ if (%x > 3): stop repeating
# How do I do a 'goto'?
do:
- %x <- 1
+ %x = 1
=== %again ===
say "GOTO loop #\%x"
- %x +<- 1
- if (%x <= 3):
- go to %again
+ %x += 1
+ if (%x <= 3): go to %again
say "finished going to"
@@ -191,24 +167,22 @@ action [say both %first and also %second]:
# Actions can use "return" to return a value early
action [first fibonacci above %n]:
- %f1 <- 0
- %f2 <- 1
+ %f1 = 0
+ %f2 = 1
repeat:
- %tmp <- (%f1 + %f2)
- %f1 <- %f2
- %f2 <- %tmp
- if (%f2 > %n):
- return %f2
+ %tmp = (%f1 + %f2)
+ %f1 = %f2
+ %f2 = %tmp
+ if (%f2 > %n): return %f2
say (first fibonacci above 10)
# Actions can have aliases, which may or may not have the arguments in different order
action [..]
- I hate %worse-things more than %better-things
- I think %worse-things are worse than %better-things
- I like %better-things more than %worse-things
-..:
- say "\(%better-things capitalized) rule and \%worse-things drool!"
+ I hate %worse_things more than %better_things
+ I think %worse_things are worse than %better_things
+ I like %better_things more than %worse_things
+..: say "\(%better_things capitalized) rule and \%worse_things drool!"
I like "dogs" more than "cats"
I think "chihuahuas" are worse than "corgis"
@@ -218,23 +192,23 @@ I think "chihuahuas" are worse than "corgis"
say both "Hello" and also "again!"
# Actions can even start with a parameter
-action [%what-she-said is what she said]:
- say %what-she-said
+action [%what_she_said is what she said]:
+ say %what_she_said
say "-- she said"
"Howdy pardner" is what she said
# The language only reserves []{}().,:;% as special characters, so actions
can have really funky names!
-action [>> %foo-bar $$$^ --> % @&_~-^-~_~-^ %1 !]:
- say %foo-bar
+action [>> %foo_bar $$$^ --> % @&_~-^-~_~-^ %1 !]:
+ say %foo_bar
say %
say %1
>> "wow" $$$^ --> "so flexible!" @&_~-^-~_~-^ "even numbers can be variables!" !
# There's also full unicode support
-%こんにちは <- "こんにちは"
+%こんにちは = "\227\129\147\227\130\147\227\129\171\227\129\161\227\129\175"
action [% と言う] "\%世界"
say (%こんにちは と言う)
@@ -251,26 +225,19 @@ say (1 ++ (2 * 3))
say (2 + 3)
# Or by (..) followed by an indented region
-say (..)
- 2 + 3
+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"
-
+say both "Very long first argument that needs its own line" and also "short second arg"
action [my favorite number] (21 + 2)
# This can be nested:
-say both (..)
- my favorite
- ..number
-..and also "foo"
+say both (my favorite number) and also "foo"
# Macros:
# The "lua> %" and "=lua %" macros can be used to write raw lua code:
action [say the time] (..)
- lua> ".."
- io.write("The OS time is: ", os.time(), "\\n");
+ lua> "io.write(\"The OS time is: \", os.time(), \"\\n\");"
say the time
say "Math expression result is: \(=lua "(1 + 2*3 + 3*4)^2")"
@@ -280,15 +247,11 @@ action [square root of %n] (=lua "math.sqrt(\%n)")
say "The square root of 2 is \(square root of 2)"
# Macros can be defined to transform one bit of nomsu code into another using "parse % as %":
-parse [if %condition is untrue %body] as (..)
- if (not %condition) %body
+parse [if %condition is untrue %body] as (if (not %condition) %body)
# Or to transform nomsu code into custom lua code using "compile % to %"
compile [if %condition on opposite day %body] to (..)
- Lua ".."
- if not \(%condition as lua expr) then
- \(%body as lua statements)
- end
+ Lua "if not \(%condition as lua expr) then\n \(%body as lua statements)\nend"
# Constants can be defined as macros
@@ -313,12 +276,12 @@ if (1 > (TWENTY)) on opposite day:
# How do I use an action as a value?
# Well... it's always *possible* to fall back to Lua behavior for something like this:
-action [best of %items according to %key-fn]:
- <- {%best: nil, %best-key: nil}
+action [best of %items according to %key_fn]:
+ set {%best: nil, %best_key: nil}
for %item in %items:
- %key <- (=lua "\%key-fn(\%item)")
- if ((%best is (nil)) or (%key > %best-key)):
- <- {%best: %item, %best-key: %key}
+ %key = (=lua "\%key_fn(\%item)")
+ if ((%best is (nil)) or (%key > %best_key)):
+ set {%best: %item, %best_key: %key}
return %best
@@ -328,13 +291,13 @@ say (best of [2, -3, 4, -8] according to ([%x] -> (%x * %x)))
one-off function to pass to another function and get called a bunch of times, you
could use a macro to generate a single block of code that inlines the expression you
want to use:
-parse [best of %items where %item-var has score %key-expr] as (..)
+parse [best of %items where %item_var has score %key_expr] as (..)
result of:
- <- {%best: nil, %best-key: nil}
- for %item-var in %items:
- %key <- %key-expr
- if ((%best is (nil)) or (%key > %best-key)):
- <- {%best: %item-var, %best-key: %key}
+ set {%best: nil, %best_key: nil}
+ for %item_var in %items:
+ %key = %key_expr
+ if ((%best is (nil)) or (%key > %best_key)):
+ set {%best: %item_var, %best_key: %key}
return %best
diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom
index a320b03..39bae68 100644
--- a/lib/consolecolor.nom
+++ b/lib/consolecolor.nom
@@ -1,11 +1,10 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file defines actions for ANSI console color escape codes.
use "core"
-
test: bright "\(green)Color test passed."
-%colors <- {..}
+%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
# There's some other codes, but they're not currently implemented
@@ -20,4 +19,4 @@ for %name = %colornum in %colors:
compile [\%name] to: Lua value (quote \(quote %escapecode))
compile [\%name %text] to
Lua value ".."
- (\\(quote \(quote %escapecode))..\\(%text as lua expr).."\\27[0m")
+ (\\(quote \(quote %escapecode))..\\(%text as lua expr).."\\27[0m") \ No newline at end of file
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index 542b2f2..283c5b4 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -1,9 +1,8 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file defines some actions for hashing files and looking up files by hash.
use "core"
-
action [file with hash %hash]:
lua> ".."
local Hash = require("openssl.digest")
@@ -19,10 +18,9 @@ action [file with hash %hash]:
end
action [hash %, sha1 %]:
- %hashlib <- (=lua "require('openssl.digest')")
- %hash <- (=lua "\%hashlib.new('sha1'):final(\%)")
+ %hashlib = (=lua "require('openssl.digest')")
+ %hash = (=lua "\%hashlib.new('sha1'):final(\%)")
return (..)
=lua "\%hash:gsub('.', function(c) return string.format('%02x', string.byte(c)) end)"
-parse [hash of file %filename] as (..)
- sha1 (=lua "io.open(\%filename):read('*a')")
+parse [hash of file %filename] as (sha1 (=lua "io.open(\%filename):read('*a')")) \ No newline at end of file
diff --git a/lib/object.nom b/lib/object.nom
index d41557b..cb5cd3c 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -1,33 +1,29 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains the implementation of an Object-Oriented programming system.
use "core"
-
compile [@, me] to (Lua value "self")
compile [method %actions %body] to:
- %lua <- (compile as (action %actions %body))
+ %lua = (compile as (action %actions %body))
add free vars ((% as lua id) for % in %actions) to %lua
declare locals in %lua
for % in %actions:
to %lua write "\nclass.\(% as lua id) = \(% as lua id)"
return (..)
- Lua ".."
- do -- Method: \(%actions.(1).stub)
- \%lua
- end
+ Lua "do -- Method: \(%actions.(1).stub)\n \%lua\nend"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse [as %instance %body] as (..)
result of:
- %old_self <- (me)
- (me) <- %instance
+ %old_self = (me)
+ (me) = %instance
try %body and if it barfs %msg:
- (me) <- %old_self
+ (me) = %old_self
barf %msg
- ..or if it succeeds: (me) <- %old_self
+ ..or if it succeeds: (me) = %old_self
compile [object %classname extends %parent %class_body] to (..)
Lua ".."
@@ -58,4 +54,4 @@ compile [object %classname extends %parent %class_body] to (..)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
parse [object %classname %class_body] as (..)
- object %classname extends (nil) %class_body
+ object %classname extends (nil) %class_body \ No newline at end of file
diff --git a/lib/os.nom b/lib/os.nom
index 8c6a153..57dac26 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file defines some actions that interact with the operating system and filesystem.
@@ -39,8 +39,5 @@ action [..]
..:
lua> "local file = io.open(\%filename, 'w')\nfile:write(\%text)\nfile:close()"
-action [line number of %pos in %str] (..)
- =lua "files.get_line_number(\%str, \%pos)"
-
-action [line %line_num in %str] (..)
- =lua "files.get_line(\%str, \%line_num)"
+action [line number of %pos in %str] (=lua "files.get_line_number(\%str, \%pos)")
+action [line %line_num in %str] (=lua "files.get_line(\%str, \%line_num)") \ No newline at end of file
diff --git a/lib/training_wheels.nom b/lib/training_wheels.nom
index ea13ac0..4c0b166 100644
--- a/lib/training_wheels.nom
+++ b/lib/training_wheels.nom
@@ -1,11 +1,10 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
#
This file contains a set of definitions that bring some familiar language features
from other languages into nomsu (e.g. "==" and "continue")
use "core"
-
-parse [%a = %b] as (%a <- %b)
+parse [%a == %b] as (%a = %b)
parse [%a == %b] as (%a is %b)
parse [%a ~= %b, %a != %b, %a <> %b] as (%a is not %b)
parse [%a === %b] as ((%a 's id) is (%b 's id))
@@ -21,26 +20,26 @@ parse [%a || %b] as (%a or %b)
parse [%a && %b] as (%a and %b)
parse [continue] as (do next)
parse [break] as (stop)
-parse [let %thing = %value in %action] as (with [%thing <- %value] %action)
+parse [let %thing = %value in %action] as (with [%thing = %value] %action)
parse [print %] as (say %)
parse [error!, panic!, fail!, abort!] as (barf!)
parse [error %, panic %, fail %, abort %] as (barf %)
parse [assert %condition %message] as (assume %condition or barf %message)
parse [%cond ? %if_true %if_false] as (%if_true if %cond else %if_false)
compile [function %args %body, lambda %args %body] to:
- %lua <- (Lua value "(function(")
+ %lua = (Lua value "(function(")
for %i = %arg in %args.value:
if (%i > 1): to %lua write ", "
to %lua write (%arg as lua expr)
to %lua write ")\n "
- %body <- (%body as lua)
+ %body = (%body as lua)
lua> "\%body:convert_to_statements('return ');"
for % in %args.value: lua> "\%body:remove_free_vars(\%);"
to %lua write %body
to %lua write "\nend)"
return %lua
-parse [function %name %args %body] as (%name <- (function %args %body))
+parse [function %name %args %body] as (%name = (function %args %body))
compile [call %fn %args] to (..)
- Lua value "\(%fn as lua expr)(unpack(\(%args as lua expr)))"
+ Lua value "\(%fn as lua expr)(unpack(\(%args as lua expr)))" \ No newline at end of file
diff --git a/lib/version.nom b/lib/version.nom
index 24ba7a0..952d940 100644
--- a/lib/version.nom
+++ b/lib/version.nom
@@ -1,3 +1,3 @@
-#!/usr/bin/env nomsu -V2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
# This file sets the current library version.
lua> "NOMSU_LIB_VERSION = 3" \ No newline at end of file
diff --git a/tests/collections.nom b/tests/collections.nom
index 9df9eba..cf60ebe 100644
--- a/tests/collections.nom
+++ b/tests/collections.nom
@@ -1,40 +1,37 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#..
Tests for the stuff defined in core/control_flow.nom
-
use "core"
-
-assume ((2nd to last in [1,2,3,4,5]) = 4)
-assume (3 is in [1,2,3,4,5])
-assume (99 isn't in [1,2,3])
-assume ({x:no} has key "x")
-assume ({x:no} doesn't have key "y")
-assume (not ({x:no} doesn't have key "x"))
-assume ((length of [1,2,3]) = 3)
-%list <- [1,2,3,4,5]
+assume ((2 nd to last in [1, 2, 3, 4, 5]) == 4)
+assume (3 is in [1, 2, 3, 4, 5])
+assume (99 isn't in [1, 2, 3])
+assume ({x: no} has key "x")
+assume ({x: no} doesn't have key "y")
+assume (not ({x: no} doesn't have key "x"))
+assume ((length of [1, 2, 3]) == 3)
+%list = [1, 2, 3, 4, 5]
append 6 to %list
-assume ((last in %list) = 6)
+assume ((last in %list) == 6)
pop from %list
-assume ((last in %list) = 5)
+assume ((last in %list) == 5)
remove index 1 from %list
-assume ((first in %list) = 2)
-assume (((% * %) for % in [1,2,3]) = [1,4,9])
-assume ((%k = (%v * %v) for %k = %v in {x:1,y:2,z:3}) = {x:1,y:4,z:9})
-assume ((%k for %k = %v in {x:1}) = ["x"])
-assume ((% = (% * %) for % in [1,2,3]) = {1:1,2:4,3:9})
-assume (([[1,2],[3,4]] flattened) = [1,2,3,4])
-assume ((entries in {x:1}) = [{key:"x",value:1}])
-assume ((keys in {x:1}) = ["x"])
-assume ((values in {x:1}) = [1])
-assume ((sorted [3,1,2]) = [1,2,3])
-%x <- [3,1,2]
+assume ((first in %list) == 2)
+assume (((% * %) for % in [1, 2, 3]) == [1, 4, 9])
+assume ((%k = (%v * %v) for %k = %v in {x: 1, y: 2, z: 3}) == {x: 1, y: 4, z: 9})
+assume ((%k for %k = %v in {x: 1}) == ["x"])
+assume ((% = (% * %) for % in [1, 2, 3]) == {1: 1, 2: 4, 3: 9})
+assume (([[1, 2], [3, 4]] flattened) == [1, 2, 3, 4])
+assume ((entries in {x: 1}) == [{key: "x", value: 1}])
+assume ((keys in {x: 1}) == ["x"])
+assume ((values in {x: 1}) == [1])
+assume ((sorted [3, 1, 2]) == [1, 2, 3])
+%x = [3, 1, 2]
sort %x
-assume (%x = [1,2,3])
-sort %x by % = (-%)
-assume (%x = [3,2,1])
-%keys <- {1:999,2:0,3:50}
+assume (%x == [1, 2, 3])
+sort %x by % = (- %)
+assume (%x == [3, 2, 1])
+%keys = {1: 999, 2: 0, 3: 50}
sort %x by % = %keys.%
-assume (%x = [2,3,1])
-assume ((unique [1,2,1,3,2,3]) = [1,2,3])
-
-say "Collections test passed."
+assume (%x == [2, 3, 1])
+assume ((unique [1, 2, 1, 3, 2, 3]) == [1, 2, 3])
+say "Collections test passed." \ No newline at end of file
diff --git a/tests/colors.nom b/tests/colors.nom
index 16610f4..d4d5ac5 100644
--- a/tests/colors.nom
+++ b/tests/colors.nom
@@ -1,3 +1,3 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
use "lib/consolecolor.nom"
-say: bright: green "Color test passed."
+say (bright (green "Color test passed.")) \ No newline at end of file
diff --git a/tests/control_flow.nom b/tests/control_flow.nom
index 62b59fa..1d223a4 100644
--- a/tests/control_flow.nom
+++ b/tests/control_flow.nom
@@ -1,192 +1,161 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#
Tests for the stuff defined in core/control_flow.nom
use "core"
-
do nothing
-
-action [test conditionals]
- if: yes
- %loc1 <- (yes)
- if: no
- barf "entered if 'no' conditional"
-
- unless: yes
- barf "entered unless 'yes' conditional"
-
- if: yes
- %loc2 <- (yes)
- ..else
- barf "entered if 'yes' else conditional"
-
- unless: no
- %loc3 <- (yes)
- ..else
- barf "entered unless 'no' else conditional"
-
-assume (all of [%loc1 = (nil), %loc2 = (nil), %loc3 = (nil)]) or barf "conditionals leaking locals"
-
-assume ((5 if (yes) else 1) = 5)
-assume ((5 if (no) else 1) = 1)
-action [return nil]: return (nil)
-assume (((return nil) if (yes) else 99) = (nil))
-
+action [test conditionals]:
+ if (yes): %loc1 = (yes)
+ if (no): barf "entered if 'no' conditional"
+ unless (yes): barf "entered unless 'yes' conditional"
+ if (yes): %loc2 = (yes)
+ ..else: barf "entered if 'yes' else conditional"
+
+ unless (no) (%loc3 = (yes)) else (barf "entered unless 'no' else conditional")
+
+assume (all of [%loc1 == (nil), %loc2 == (nil), %loc3 == (nil)]) or barf "conditionals leaking locals"
+assume ((5 if (yes) else 1) == 5)
+assume ((5 if (no) else 1) == 1)
+action [return nil] (return (nil))
+assume (((return nil) if (yes) else 99) == (nil))
go to %skip
barf "go-to failed."
--- %skip ---
-
-%tot <- 0
-for %x in [1,2,3]
- %tot +<- %x
-assume (%tot = 6) or barf "for-loop failed"
-
-%x <- 0
-repeat
- %x +<- 1
- if (%x = 3): stop repeating
+%tot = 0
+for %x in [1, 2, 3]: %tot += %x
+assume (%tot == 6) or barf "for-loop failed"
+%x = 0
+repeat:
+ %x += 1
+ if (%x == 3): stop repeating
if (%x > 3): barf "Failed to stop repeat loop"
-assume (%x = 3) or barf "Failed to repeat"
-
-%x <- 0
-repeat 5 times
- %x +<- 1
-assume (%x = 5) or barf "Failed to repeat 5 times"
-<- {%x:0,%y:0}
-for % in [1,2,3]
- repeat 5 times
+assume (%x == 3) or barf "Failed to repeat"
+%x = 0
+repeat 5 times: %x += 1
+assume (%x == 5) or barf "Failed to repeat 5 times"
+set {%x: 0, %y: 0}
+for % in [1, 2, 3]:
+ repeat 5 times:
do next repeat
- %x +<- 1
- %y +<- 1
-assume ([%x,%y] = [0,3]) or barf "Failed to continue repeat"
-
-<- {%x:0,%y:0}
-for % in [1,2,3]
- repeat 5 times
+ %x += 1
+
+ %y += 1
+
+assume ([%x, %y] == [0, 3]) or barf "Failed to continue repeat"
+set {%x: 0, %y: 0}
+for % in [1, 2, 3]:
+ repeat 5 times:
do next %
- %x +<- 1
- %y +<- 1
-assume ([%x,%y] = [0,0]) or barf "Failed to continue for"
-
-<- {%x:0,%y:0}
-for % in [1,2,3]
- repeat 5 times
+ %x += 1
+
+ %y += 1
+
+assume ([%x, %y] == [0, 0]) or barf "Failed to continue for"
+set {%x: 0, %y: 0}
+for % in [1, 2, 3]:
+ repeat 5 times:
stop repeating
- %x +<- 1
- %y +<- 1
-assume ([%x,%y] = [0,3]) or barf "Failed to stop repeat"
-
-<- {%x:0,%y:0}
-for % in [1,2,3]
- repeat 5 times
+ %x += 1
+
+ %y += 1
+
+assume ([%x, %y] == [0, 3]) or barf "Failed to stop repeat"
+set {%x: 0, %y: 0}
+for % in [1, 2, 3]:
+ repeat 5 times:
stop %
- %x +<- 1
- %y +<- 1
-assume ([%x,%y] = [0,0]) or barf "Failed to stop for"
-
-%x <- 0
-repeat while: %x < 10
- %x +<- 1
-assume (%x = 10) or barf "repeat-while failed"
-
-%x <- 0
-repeat until: %x = 10
- %x +<- 1
-assume (%x = 10) or barf "repeat-until failed"
-
-%x <- 0
-for %i in 1 to 3: %x +<- %i
-assume (%x = 6) or barf "Numeric for range failed"
-
-%x <- 0
-for %i in 3 to 1 via -1: %x +<- %i
-assume (%x = 6) or barf "backwards numeric for range failed"
-
-%result <- {}
-for %key = %value in {x:1,y:2}
- %result.("\%key\%key") <- (%value * 11)
-assume (%result = {xx:11,yy:22}) or barf "key/value iteration failed"
-
-for %key = %value in {x:1,y:2}
+ %x += 1
+
+ %y += 1
+
+assume ([%x, %y] == [0, 0]) or barf "Failed to stop for"
+%x = 0
+repeat while (%x < 10): %x += 1
+assume (%x == 10) or barf "repeat-while failed"
+%x = 0
+repeat until (%x == 10): %x += 1
+assume (%x == 10) or barf "repeat-until failed"
+%x = 0
+for %i in 1 to 3: %x += %i
+assume (%x == 6) or barf "Numeric for range failed"
+%x = 0
+for %i in 3 to 1 via -1: %x += %i
+assume (%x == 6) or barf "backwards numeric for range failed"
+%result = {}
+for %key = %value in {x: 1, y: 2}: %result."\%key\%key" = (%value * 11)
+assume (%result == {xx: 11, yy: 22}) or barf "key/value iteration failed"
+for %key = %value in {x: 1, y: 2}:
stop %key
barf "stopping key failed"
-for %key = %value in {x:1,y:2}
+for %key = %value in {x: 1, y: 2}:
stop %value
barf "stopping value failed"
-for %key = %value in {x:1}
+for %key = %value in {x: 1}:
stop %key
stop %value
do next %key
do next %value
-for %key = %value in {x:1,y:2}
+for %key = %value in {x: 1, y: 2}:
do next %key
barf "skipping key failed"
-for %key = %value in {x:1,y:2}
+for %key = %value in {x: 1, y: 2}:
do next %value
barf "skipping value failed"
-action [barfer]: barf "this should never be reached"
-when
- * (no): barf "'when' fail"
+action [barfer] (barf "this should never be reached")
+when:
+ * (no) (barf "'when' fail")
* (no)
- * (3 > 4): barf "'when' fail 2"
+ * (3 > 4) (barf "'when' fail 2")
* (yes)
- * (barfer): do nothing
- * (99 > 1): barf "Fell through incorrectly"
+ * (barfer) (do nothing)
+ * (99 > 1) (barf "Fell through incorrectly")
-%else_worked <- (no)
-when
- * (no): barf
- * else: %else_worked <- (yes)
-assume %else_worked or barf "when..else failed"
+%else_worked = (no)
+when:
+ * (no) (barf)
+ *else (%else_worked = (yes))
-action [test when scope]
- when
- * (yes): %leaked <- (yes)
+assume %else_worked or barf "when..else failed"
+action [test when scope] (when (* (yes) (%leaked = (yes))))
test when scope
assume (not %leaked) or barf "'when' is leaking locals"
-
-%when_worked <- (no)
-when 4 = ?
+%when_worked = (no)
+when 4 = ?:
* 1
- * 2: barf "'when = ?' fail"
+ * 2 (barf "'when = ?' fail")
* 3
* 4
- * (barfer): %when_worked <- (yes)
-assume %when_worked
+ * (barfer) (%when_worked = (yes))
-%when_worked <- (no)
-when 5 = ?
- * 6: barf
- * else: %when_worked <- (yes)
assume %when_worked
+%when_worked = (no)
+when 5 = ?:
+ * 6 (barf)
+ *else (%when_worked = (yes))
-%x <- 1
-do
- %x <- 2
-assume (%x = 2) or barf "'do' is redefining locals"
-
-assume
+assume %when_worked
+%x = 1
+do: %x = 2
+assume (%x == 2) or barf "'do' is redefining locals"
+assume (..)
(..)
- result of
- %n <- 0
- for % in [1,2,3]: %n +<- %
+ result of:
+ %n = 0
+ for % in [1, 2, 3]: %n += %
return %n
- ..= 6
-..or barf "'result of %' failed"
-
+ ..== 6
-%t <- [1,[2,[[3],4],5,[[[6]]]]]
-%flat <- []
-for % in recursive %t
- if: (type of %) is "table"
- for %2 in %: recurse % on %2
+%t = [1, [2, [[3], 4], 5, [[[6]]]]]
+%flat = []
+for % in recursive %t:
+ if ((type of %) is "table"): for %2 in %: recurse % on %2
..else: add % to %flat
-assume: (sorted %flat) = [1,2,3,4,5,6]
+assume ((sorted %flat) == [1, 2, 3, 4, 5, 6])
say "Control flow test passed."
diff --git a/tests/coroutines.nom b/tests/coroutines.nom
index 16ef100..54b233e 100644
--- a/tests/coroutines.nom
+++ b/tests/coroutines.nom
@@ -1,19 +1,10 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#
Tests for the stuff defined in core/control_flow.nom
use "core"
-
-%nums <- []
-%co <-
- coroutine
- -> 4
- -> 5
- repeat 3 times
- -> 6
-for % in coroutine %co
- add % to %nums
-
-assume (%nums = [4,5,6,6,6]) or barf "Coroutine iteration failed"
-
-say "Coroutines test passed."
+%nums = []
+%co = (coroutine (: -> 4; -> 5; repeat 3 times: -> 6))
+for % in coroutine %co (add % to %nums)
+assume (%nums == [4, 5, 6, 6, 6]) or barf "Coroutine iteration failed"
+say "Coroutines test passed." \ No newline at end of file
diff --git a/tests/errors.nom b/tests/errors.nom
index 7f52532..7f91c88 100644
--- a/tests/errors.nom
+++ b/tests/errors.nom
@@ -1,23 +1,16 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#
Tests for the stuff defined in core/errors.nom
-try: barf
-..and if it succeeds: barf "try failed."
-
-%worked <- (no)
-try: barf
-..and if it barfs: %worked <- (yes)
+try (barf) and if it succeeds (barf "try failed.")
+%worked = (no)
+try (barf) and if it barfs (%worked = (yes))
assume %worked or barf "try/catch failed"
+%x = 1
+try:
+ %x = 2
+ do (barf) then always (%x = 3)
+..and if it barfs (do nothing)
-%x <- 1
-try
- %x <- 2
- do
- barf
- ..then always
- %x <- 3
-..and if it barfs: do nothing
-assume (%x = 3) or barf "do/then always failed"
-
-say "Error handling test passed."
+assume (%x == 3) or barf "do/then always failed"
+say "Error handling test passed." \ No newline at end of file
diff --git a/tests/math.nom b/tests/math.nom
index 3764dee..7ddefba 100644
--- a/tests/math.nom
+++ b/tests/math.nom
@@ -1,22 +1,20 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#..
Tests for the stuff defined in core/control_flow.nom
-
use "core"
-
assume (all of [inf, pi, tau, golden ratio, e]) or barf "math constants failed"
-%nan <- (NaN)
+%nan = (NaN)
assume (%nan != %nan) or barf "NaN failed"
-assume (("5" as a number) = 5)
-assume
+assume (("5" as a number) == 5)
+assume (..)
all of [..]
- abs 5, |5|, sqrt 5, √(5), sine 5, cosine 5, tangent 5, arc sine 5, arc cosine 5,
- 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,
+ abs 5, | 5 |, sqrt 5, √ 5, sine 5, cosine 5, tangent 5, arc sine 5, arc cosine 5
+ 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"
-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"
-assume ((min of [3,-4,1,2] by % = (%*%)) = 1)
-assume ((max of [3,-4,1,2] by % = (%*%)) = -4)
-say "Math test passed"
+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"
+assume ((min of [3, -4, 1, 2] by % = (% * %)) == 1)
+assume ((max of [3, -4, 1, 2] by % = (% * %)) == -4)
+say "Math test passed" \ No newline at end of file
diff --git a/tests/metaprogramming.nom b/tests/metaprogramming.nom
index 083ddc7..d74542c 100644
--- a/tests/metaprogramming.nom
+++ b/tests/metaprogramming.nom
@@ -1,76 +1,71 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#
Tests for the stuff defined in core/metaprogramming.nom
use "core"
+compile [five] to (Lua value "5")
-compile [five] to: Lua value "5"
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-assume ((five) = 5) or barf "Compile to expression failed."
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+assume ((five) == 5) or barf "Compile to expression failed."
+compile [loc x] to (Lua "local _x = 99;")
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-compile [loc x] to: Lua "local _x = 99;"
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
lua> "do"
loc x
assume (%x is 99) or barf "Compile to statements with locals failed."
lua> "end"
assume (%x is (nil)) or barf "Failed to properly localize a variable."
+compile [asdf] to:
+ %tmp = ""
+ return (Lua %tmp)
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-compile [asdf] to
- %tmp <- ""
- return: Lua %tmp
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
asdf
assume (%tmp is (nil)) or barf "compile to is leaking variables"
-
-action [foo %x]
- %y <- (%x + 1)
+action [foo %x]:
+ %y = (%x + 1)
return %y
-assume ((foo 10) = 11) or barf "Action didn't work."
+
+assume ((foo 10) == 11) or barf "Action didn't work."
assume (%y is (nil)) or barf "Action leaked a local into globals."
+parse [baz %] as (foo %)
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+assume ((baz 10) == 11) or barf "Parse as action failed."
+parse [V] as (five)
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+assume ((V) == 5) or barf "Parse as compile action failed."
+parse [swap %x and %y] as (do (: %tmp = %x; %x = %y; %y = %tmp))
-parse [baz %] as: foo %
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-assume ((baz 10) = 11) or barf "Parse as action failed."
-
-parse [V] as: five
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-assume ((V) = 5) or barf "Parse as compile action failed."
-
-parse [swap %x and %y] as
- do
- %tmp <- %x
- %x <- %y
- %y <- %tmp
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-<- {%1:1, %2:2}
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+set {%1: 1, %2: 2}
swap %1 and %2
-assume ((%1 = 2) and (%2 = 1)) or barf "'parse % as %' failed on 'swap % and %'"
-<- {%tmp:1, %tmp2:2}
+assume ((%1 == 2) and (%2 == 1)) or barf "'parse % as %' failed on 'swap % and %'"
+set {%tmp: 1, %tmp2: 2}
swap %tmp and %tmp2
-assume ((%tmp = 2) and (%tmp2 = 1)) or barf "'parse % as %' variable mangling failed."
+assume ((%tmp == 2) and (%tmp2 == 1)) or barf "'parse % as %' variable mangling failed."
#
remove action (foo %)
try: foo 99
..and if it succeeds: barf "Failed to delete action"
-assume ((\(5 + 5) as value) = 10) or barf "%tree as value failed."
-
-assume ("\(\(foo %x) as nomsu)" = "foo %x") or barf "action source code failed."
-
-assume ("\(\%x as nomsu)" = "%x") or barf "var source code failed."
-
-assume ((type of {}) = "table") or barf "type of failed."
-
-assume ("\(\%x as lua identifier)" = "_x") or barf "converting to identifier failed."
-
-assume ((run "return 99") = 99) or barf "run % failed."
-
-%code <-: Lua "global_x = true;"
+assume ((\(5 + 5) as value) == 10) or barf "%tree as value failed."
+assume ("\(\(foo %x) as nomsu)" == "foo %x") or barf "action source code failed."
+assume ("\(\(%x) as nomsu)" == "%x") or barf "var source code failed."
+assume ((type of {}) == "table") or barf "type of failed."
+assume ("\(\(%x) as lua identifier)" == "_x") or barf "converting to identifier failed."
+assume ((run "return 99") == 99) or barf "run % failed."
+%code = (Lua "global_x = true;")
lua> %code
assume (=lua "global_x") or barf "Running lua from a variable failed."
-%code <-: Lua value "global_x"
+%code = (Lua value "global_x")
assume (=lua %code) or barf "Running lua from a variable failed."
-
say "Metaprogramming test passed."
diff --git a/tests/object.nom b/tests/object.nom
index 795d85e..30cf748 100644
--- a/tests/object.nom
+++ b/tests/object.nom
@@ -1,71 +1,46 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#
Tests for the object model defined in lib/object.nom
use "core"
use "lib/object.nom"
-
-object "Dog"
- (class Dog).genus <- "Canus"
- method [initialize %]
- %.barks or<- 0
-
- method [bark, woof]
- %barks <- ("Bark!" for % in 1 to ((me).barks))
- return: %barks joined with " "
-
- method [get pissed off]
- ((me).barks) +<- 1
-
-%d <-: new Dog {barks:2}
-as %d
- assume: (me) = %d
- assume: ((me).barks) = 2
- assume: (bark) = "Bark! Bark!"
- assume: (woof) = "Bark! Bark!"
+object "Dog":
+ (class Dog).genus = "Canus"
+ method [initialize %] (%.barks or= 0)
+ method [bark, woof]:
+ %barks = ("Bark!" for % in 1 to (me).barks)
+ return (%barks joined with " ")
+
+ method [get pissed off] ((me).barks += 1)
+
+%d = (new Dog {barks: 2})
+as %d:
+ assume ((me) == %d)
+ assume ((me).barks == 2)
+ assume ((bark) == "Bark! Bark!")
+ assume ((woof) == "Bark! Bark!")
get pissed off
- assume: ((me).barks) = 3
- assume: (bark) = "Bark! Bark! Bark!"
- assume: (me).genus = "Canus"
-assume: "\(%d.class)" = "Dog"
-assume: %d.genus = "Canus"
-assume: %d.barks = 3
-
-as: new Dog
- assume: ((me).barks) = 0
- ..or barf "Default initializer failed"
-
-as: new Dog {barks:1}
- assume: (bark) = "Bark!"
-
-action [foo]
- as: new Dog {barks:23}
- return: (me).barks
-
-assume: (foo) = 23
-..or barf: "Oops, \(foo) != 23"
-
-as: new Dog {barks:101}
- try: as (new Dog {barks:8}) (barf)
- ..and if it succeeds: barf
-
- assume: (me).barks = 101
- ..or barf "Error in nested 'as % %' failed to properly reset 'self'"
-
-
-object "Corgi" extends: class Dog
- method [sploot]
- "splooted"
-
-%corg <- (new Corgi)
-assume: %corg.barks = 0
-as: new Corgi {barks:1}
- assume: (sploot) = "splooted"
- ..or barf "subclass method failed"
-
- assume: (bark) = "Bark!"
- ..or barf "inheritance failed"
-
- assume: (woof) = "Bark!"
-
-say "Object test passed."
+ assume ((me).barks == 3)
+ assume ((bark) == "Bark! Bark! Bark!")
+ assume ((me).genus == "Canus")
+
+assume ("\(%d.class)" == "Dog")
+assume (%d.genus == "Canus")
+assume (%d.barks == 3)
+as (new Dog) (assume ((me).barks == 0) or barf "Default initializer failed")
+as (new Dog {barks: 1}) (assume ((bark) == "Bark!"))
+action [foo] (as (new Dog {barks: 23}) (return (me).barks))
+assume ((foo) == 23) or barf "Oops, \(foo) != 23"
+as (new Dog {barks: 101}):
+ try (as (new Dog {barks: 8}) (barf)) and if it succeeds (barf)
+ assume ((me).barks == 101) or barf "Error in nested 'as % %' failed to properly reset 'self'"
+
+object "Corgi" extends (class Dog) (method [sploot] "splooted")
+%corg = (new Corgi)
+assume (%corg.barks == 0)
+as (new Corgi {barks: 1}):
+ assume ((sploot) == "splooted") or barf "subclass method failed"
+ assume ((bark) == "Bark!") or barf "inheritance failed"
+ assume ((woof) == "Bark!")
+
+say "Object test passed." \ No newline at end of file
diff --git a/tests/operators.nom b/tests/operators.nom
index 375a80a..0ab44c1 100644
--- a/tests/operators.nom
+++ b/tests/operators.nom
@@ -1,54 +1,52 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#..
Tests for the stuff defined in core/operators.nom
-
use "core"
-
-<-{%x:10,%y:20}
-assume ((%x = 10) and (%y = 20)) or barf "mutli-assignment failed."
-<-{%x:%y, %y:%x}
-assume ((%y = 10) and (%x = 20)) or barf "swapping vars failed."
-
-% <- [%x < %y, %x <= %y, %x > %y, %x >= %y, %x = %y, %x is %y, %x != %y, %x isn't %y, %x is not %y]
+set {%x: 10, %y: 20}
+assume ((%x == 10) and (%y == 20)) or barf "mutli-assignment failed."
+set {%x: %y, %y: %x}
+assume ((%y == 10) and (%x == 20)) or barf "swapping vars failed."
+% = [..]
+ %x < %y, %x <= %y, %x > %y, %x >= %y, %x == %y, %x is %y, %x != %y, %x isn't %y
+ %x is not %y
assume ({} is {}) or barf "Equality check failed."
-assume (({}'s id) is not ({}'s id)) or barf "Identity check failed."
+assume (({} 's id) is not ({} 's id)) or barf "Identity check failed."
+set {%foozle: "outer", %y: "outer"}
+action [set global x local y]:
+ external %foozle = "inner"
+ %y = "inner"
-<-{%foozle:"outer",%y:"outer"}
-action [set global x local y]
- external %foozle <- "inner"
- %y <- "inner"
set global x local y
-assume ((%foozle = "inner") and (%y = "outer")) or barf "external failed."
+assume ((%foozle == "inner") and (%y == "outer")) or barf "external failed."
+set {%foozle: "outer", %y: "outer"}
+action [set global x local y] (..)
+ with external [%foozle]:
+ %foozle = "inner"
+ %y = "inner"
-<-{%foozle:"outer",%y:"outer"}
-action [set global x local y]
- with external [%foozle]
- %foozle <- "inner"
- %y <- "inner"
set global x local y
-assume ((%foozle = "inner") and (%y = "outer")) or barf "'with external' failed."
-
-<-{%x:1,%y:2}
-with {%z:nil, %x:999}
- %z <- 999
- assume (%z = 999) or barf "'with' failed."
- assume (%x = 999) or barf "'with' assignment failed."
-assume (%x = 1) or barf "'with' scoping failed"
-assume (%z = (nil)) or barf "'with' scoping failed"
+assume ((%foozle == "inner") and (%y == "outer")) or barf "'with external' failed."
+set {%x: 1, %y: 2}
+with {%z: nil, %x: 999}:
+ %z = 999
+ assume (%z == 999) or barf "'with' failed."
+ assume (%x == 999) or barf "'with' assignment failed."
-assume ((1 + 2*3 - 4/2^2) = 6) or barf "math expressions not working properly"
-assume ((5 wrapped around 2) = 1) or barf "mod not working"
+assume (%x == 1) or barf "'with' scoping failed"
+assume (%z == (nil)) or barf "'with' scoping failed"
+assume ((1 + 2 * 3 - 4 / 2 ^ 2) == 6) or barf "math expressions not working properly"
+assume ((5 wrapped around 2) == 1) or barf "mod not working"
assume (1 <= 2 < 3) or barf "chained operator fail."
-%value <- -999
-action [flipflop]
- external %value <- (-%value)
+%value = -999
+action [flipflop]:
+ external %value = (- %value)
return %value
+
assume (not (1 < (flipflop) < 1)) or barf "3-way inequality evaluated middle term twice"
-assume (((yes) and (yes)) = (yes))
-action [barfer]
- barf "short circuiting failed"
-assume (((no) and (barfer)) = (no))
+assume (((yes) and (yes)) == (yes))
+action [barfer] (barf "short circuiting failed")
+assume (((no) and (barfer)) == (no))
assume ((no) or (yes))
assume ((yes) or (barfer))
@@ -62,15 +60,13 @@ assume ((yes) or (barfer))
assume ((2>>>1) = 1)
#.. Ugh, Lua is stupid when it comes to bitwise arithmetic on negative numbers, so I'm
skipping the tests for those.
-
-assume ((-(5)) = -5)
-assume ((not (yes)) = (no))
-%x <- 1
-%x +<- 1
-assume (%x = 2) or barf "+<- failed"
-%x *<- 2
-assume (%x = 4) or barf "*<- failed"
+assume ((- 5) == -5)
+assume ((not (yes)) == (no))
+%x = 1
+%x += 1
+assume (%x == 2) or barf "+<- failed"
+%x *= 2
+assume (%x == 4) or barf "*<- failed"
wrap %x around 3
-assume (%x = 1) or barf "wrap around failed"
-
+assume (%x == 1) or barf "wrap around failed"
say "Operator test passed."
diff --git a/tests/os.nom b/tests/os.nom
index efc6e56..cbda5b3 100644
--- a/tests/os.nom
+++ b/tests/os.nom
@@ -1,16 +1,12 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#
Tests for the stuff defined in lib/os.nom
use "core"
use "lib/os.nom"
-
-%lines <-: lines in: read file "tests/os.nom"
-assume: %lines.3 = " Tests for the stuff defined in lib/os.nom"
-
-%n <- 0
-for file %f in "core"
- %n +<- 1
+%lines = (lines in (read file "tests/os.nom"))
+assume (%lines.3 == " Tests for the stuff defined in lib/os.nom")
+%n = 0
+for file %f in "core" (%n += 1)
assume (%n > 0) or barf "Failed to walk the 'core' directory"
-
-say "OS test passed."
+say "OS test passed." \ No newline at end of file
diff --git a/tests/scopes.nom b/tests/scopes.nom
index ffda7f6..a882dcb 100644
--- a/tests/scopes.nom
+++ b/tests/scopes.nom
@@ -1,17 +1,15 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
use "core"
+%x = "outer"
+with local %x:
+ %x = "inner"
+ assume (%x == "inner")
-%x <- "outer"
-with local %x
- %x <- "inner"
- assume: %x = "inner"
-assume: %x = "outer"
-
+assume (%x == "outer")
action [foo] "outer foo"
-with local [action: foo]
+with local [action (foo)]:
action [foo] "inner foo"
- assume: (foo) = "inner foo"
-assume: (foo) = "outer foo"
-
+ assume ((foo) == "inner foo")
-say "Scopes test passed."
+assume ((foo) == "outer foo")
+say "Scopes test passed." \ No newline at end of file
diff --git a/tests/text.nom b/tests/text.nom
index 57480d8..316b343 100644
--- a/tests/text.nom
+++ b/tests/text.nom
@@ -1,56 +1,49 @@
-#!/usr/bin/env nomsu -V1
+#!/usr/bin/env nomsu -V2.3.4.3
#..
Tests for the stuff defined in core/text.nom
-
use "core"
-
-assume ((["x","y"] joined with ",") = "x,y") or barf "joined with failed"
-assume ((["x","y"] joined) = "xy") or barf "joined failed"
-assume (("asdf" capitalized) = "Asdf") or barf "capitalized failed"
-assume (("asdf" with "X" instead of "s") = "aXdf") or barf "substitution failed"
-assume ("\n" = (newline)) or barf "Text literals failed."
-assume (("x" + "y") = "xy")
-assume ((lines in "one\ntwo") = ["one", "two"])
-
-parse [アクション %spec %body] as: action %spec %body
-
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-
-%こんにちは <- "こんにちは"
-アクション [% と言う]
- "\(%)世界"
-
-assume ((%こんにちは と言う) = "こんにちは世界") or barf "Unicode doesn't work"
-
-%s <- ".."
- one two\nthree\
- ..four
-assume (%s = "one two\\nthreefour") or barf "%s = \(quote %s), not \(quote "one two\\nthreefour")"
-%s <- ".."
- list:\[..]
- 1,2,3
- ..
-assume (%s = "list:[1, 2, 3]")
-
-assume
- ".."
- foo = \
- 1 + 2
- ..!
- ..= "foo = 3!"
-
-assume
- ".."
- one\"\n"two
- ..= "one\ntwo"
-
-assume
- ".."
- no\
- #comment
- #
- block comment
- ..gap
- ..= "nogap"
-
-say "Text test passed."
+assume ((["x", "y"] joined with ",") == "x,y") or barf "joined with failed"
+assume ((["x", "y"] joined) == "xy") or barf "joined failed"
+assume (("asdf" capitalized) == "Asdf") or barf "capitalized failed"
+assume (("asdf" with "X" instead of "s") == "aXdf") or barf "substitution failed"
+assume (..)
+ "\n" == (newline)
+..or barf "Text literals failed."
+
+assume (("x" + "y") == "xy")
+assume (..)
+ (..)
+ lines in "one\ntwo"
+ ..== ["one", "two"]
+
+parse [アクション %spec %body] as (action %spec %body)
+
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+%こんにちは = "\227\129\147\227\130\147\227\129\171\227\129\161\227\129\175"
+アクション [% と言う] "\(%)\228\184\150\231\149\140"
+assume (..)
+ (%こんにちは と言う) == ".."
+ こんにちは世界
+..or barf "Unicode doesn't work"
+
+%s = "one two\\nthreefour"
+assume (..)
+ %s == "one two\\nthreefour"
+..or barf "%s = \(quote %s), not \(quote "one two\\nthreefour")"
+
+%s = "list:\[1, 2, 3]"
+assume (%s == "list:[1, 2, 3]")
+assume ("foo = \(1 + 2)!" == "foo = 3!")
+assume (..)
+ "one\ntwo"
+ ..== "one\ntwo"
+
+assume ("nogap" == "nogap")
+#comment
+#
+ block comment
+
+
+
+say "Text test passed." \ No newline at end of file
diff --git a/tools/autoformat.nom b/tools/autoformat.nom
index 6a117ec..7126608 100644
--- a/tools/autoformat.nom
+++ b/tools/autoformat.nom
@@ -1,7 +1,6 @@
-#!/usr/bin/env nomsu -V 2.2.4.3
+#!/usr/bin/env nomsu -V2.3.4.3
use "core"
use "lib/os.nom"
-
for %path in (=lua "arg"):
for file %filename in %path:
- say ((parse (read file %filename) from %filename) as nomsu)
+ say ((parse (read file %filename) from %filename) as nomsu) \ No newline at end of file
diff --git a/tools/upgrade.nom b/tools/upgrade.nom
index 26b01bd..14f7ee0 100644
--- a/tools/upgrade.nom
+++ b/tools/upgrade.nom
@@ -1,19 +1,19 @@
-#!/usr/bin/env Nomsu -V 2.2.4.3
+#!/usr/bin/env Nomsu -V2.3.4.3
use "core"
use "compatibility"
use "lib/os.nom"
-%args <- (command line args)
-%inplace <- (no)
+%args = (command line args)
+%inplace = (no)
if (%args.1 is "-i"):
- %inplace <- (yes)
+ %inplace = (yes)
remove index 1 from %args
for %path in %args:
- if (%path is "-i"): %inplace <- (yes)
+ if (%path is "-i"): %inplace = (yes)
for file %filename in %path:
- %tree <- (parse (read file %filename) from %filename)
- %tree <- (%tree upgraded from %tree.version to (Nomsu version))
- %text <- "#!/usr/bin/env nomsu -V\(Nomsu version)\n\(%tree as nomsu)"
+ %tree = (parse (read file %filename) from %filename)
+ %tree = (%tree upgraded from %tree.version to (Nomsu version))
+ %text = "#!/usr/bin/env nomsu -V\(Nomsu version)\n\(%tree as nomsu)"
if %inplace:
write %text to file %filename
..else: