aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-01-01 17:15:51 -0800
committerBruce Hill <bruce@bruce-hill.com>2019-01-01 17:17:23 -0800
commit3e89092833a6d407e711fe4ae5f44474ff34cf64 (patch)
tree5ffe2df86f648b604347b59999992d74f71a796c /lib
parente68eb04d690454428216a0f0f1b11399feeb7dc1 (diff)
Some changes to the error API, a fix for statement block parsing, and
replacing ((foo 1 baz)'s meaning) with $(foo 1 baz).
Diffstat (limited to 'lib')
-rw-r--r--lib/base64.nom2
-rw-r--r--lib/consolecolor.nom2
-rw-r--r--lib/file_hash.nom17
-rw-r--r--lib/object.nom14
-rw-r--r--lib/os.nom13
-rw-r--r--lib/things.nom23
6 files changed, 42 insertions, 29 deletions
diff --git a/lib/base64.nom b/lib/base64.nom
index f0c40b2..54f785f 100644
--- a/lib/base64.nom
+++ b/lib/base64.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V6.13.12.8
+#!/usr/bin/env nomsu -V6.14
#
This file defines actions for encoding/decoding base 64, as specified in:
https://tools.ietf.org/html/rfc4648
diff --git a/lib/consolecolor.nom b/lib/consolecolor.nom
index 6c5e176..db29b9f 100644
--- a/lib/consolecolor.nom
+++ b/lib/consolecolor.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V6.13.12.8
+#!/usr/bin/env nomsu -V6.14
#
This file defines actions for ANSI console color escape codes.
diff --git a/lib/file_hash.nom b/lib/file_hash.nom
index a708249..ec39e29 100644
--- a/lib/file_hash.nom
+++ b/lib/file_hash.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V6.13.12.8
+#!/usr/bin/env nomsu -V6.14
#
This file defines some actions for hashing files and looking up files by hash.
@@ -10,11 +10,12 @@ use "lib/base64.nom"
lua> "local \$use_sha1, \$hashlib = pcall(require, 'openssl.digest')"
test:
assume (hash "hello world") == (hash "hello world")
- assume ((hash "hello world") != (hash "goodbye")) or barf ("
- Hash collision:
- (hash "hello world") = \(hash "hello world")
- (hash "goodbye") = \(hash "goodbye")
- ")
+ if ((hash "hello world") == (hash "goodbye")):
+ fail ("
+ Hash collision:
+ (hash "hello world") = \(hash "hello world")
+ (hash "goodbye") = \(hash "goodbye")
+ ")
assume
(
@@ -24,8 +25,8 @@ test:
")
) != "inf"
- assume ((hash "\000") != (hash "\000\000\000\000\000")) or barf
- "Incorrect hashing of null strings"
+ if ((hash "\000") == (hash "\000\000\000\000\000")):
+ fail "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 fa746b6..13a9ec5 100644
--- a/lib/object.nom
+++ b/lib/object.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V6.13.12.8
+#!/usr/bin/env nomsu -V6.14
#
This file contains the implementation of an Object-Oriented programming system.
@@ -37,7 +37,9 @@ test:
assume ($d.genus == "Canus")
assume ($d.barks == 3)
$d2 = (Dog {})
- assume ($d2.barks == 0) or barf "Default initializer failed"
+ unless ($d2.barks == 0):
+ fail "Default initializer failed"
+
with [$d = (Dog {.barks = 1})]:
assume (($d, bark) == "Bark!")
@@ -50,8 +52,12 @@ test:
$corg = (Corgi {})
assume ($corg.barks == 0)
with [$d = (Corgi {.barks = 1})]:
- assume (($d, sploot) == "splooted") or barf "subclass method failed"
- assume (($d, bark) == "Yip!") or barf "inheritance failed"
+ unless (($d, sploot) == "splooted"):
+ fail "subclass method failed"
+
+ unless (($d, bark) == "Yip!"):
+ fail "inheritance failed"
+
assume (($d, woof) == "Yip!")
with [$d = (Dog {.barks = 2})]:
diff --git a/lib/os.nom b/lib/os.nom
index 8c05836..2e4cd86 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V6.13.12.8
+#!/usr/bin/env nomsu -V6.14
#
This file defines some actions that interact with the operating system and filesystem.
@@ -33,7 +33,9 @@ externally [
write to file $filename $text, to file $filename write $text
write $text to file $filename
] all mean:
- assume ($filename != "stdin") or barf "Cannot write to stdin"
+ unless ($filename != "stdin"):
+ fail "Cannot write to stdin"
+
lua> ("
local file = io.open(\$filename, 'w')
file:write(\$text)
@@ -45,10 +47,9 @@ externally (source lines of $tree) means:
$file = (read file $source.filename)
return
[
- :
- for $ in ($file, line number at $source.start) to
- $file, line number at $source.stop
- ..: add ($file, line $)
+ : for $ in ($file, line number at $source.start) to
+ $file, line number at $source.stop
+ ..: add ($file, line $)
], joined with "\n"
externally (spoof file $text) means ($Files.spoof $text)
diff --git a/lib/things.nom b/lib/things.nom
index 2820328..32942d9 100644
--- a/lib/things.nom
+++ b/lib/things.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V6.13.12.8
+#!/usr/bin/env nomsu -V6.14
#
A library for simple object oriented programming.
@@ -30,7 +30,9 @@ test:
assume ($d.genus == "Canus")
assume ($d.barks == 3)
$d2 = (a Dog)
- assume ($d2.barks == 0) or barf "Default initializer failed"
+ unless ($d2.barks == 0):
+ fail "Default initializer failed"
+
with [$d = (a Dog with {.barks = 1})]:
assume (($d, bark) == "Bark!")
@@ -47,8 +49,12 @@ test:
assume ($corg.barks == 0)
assume "\$corg" == "Dogloaf {barks: 0}"
with [$d = (a Corgi with {.barks = 1})]:
- assume (($d, sploot) == "sploooot") or barf "subclass method failed"
- assume (($d, bark) == "Yip!") or barf "inheritance failed"
+ unless (($d, sploot) == "sploooot"):
+ fail "subclass method failed"
+
+ unless (($d, bark) == "Yip!"):
+ fail "inheritance failed"
+
assume (($d, woof) == "Yip!")
with [$d = (a Dog with {.barks = 2})]:
@@ -87,9 +93,8 @@ $METAMETHOD_MAP = {
.size = "__len", .iterate = "__ipairs", ."iterate all" = "__pairs"
}
-(($ as text like a dict)'s meaning) = ({}'s metatable).__tostring
-externally (a class named $classname with $members ((initialize $it)'s meaning))
-..means:
+$($ as text like a dict) = ({}'s metatable).__tostring
+externally (a class named $classname with $members $(initialize $)) means:
$class = {.__type = $classname}
$class.__index = $class
$class.class = $class
@@ -103,7 +108,7 @@ externally (a class named $classname with $members ((initialize $it)'s meaning))
if $members.$key:
rawset $its $key $value
..else:
- barf "Cannot set \$key, it's not one of the allowed member fields."
+ fail "Cannot set \$key, it's not one of the allowed member fields."
set $class's metatable to {
.__tostring = ($class -> $class.__type)
@@ -116,7 +121,7 @@ externally (a class named $classname with $members ((initialize $it)'s meaning))
return $initial_values
}
- if ((initialize)'s meaning):
+ if $(initialize $):
initialize $class
for $stub = $metamethod in $METAMETHOD_MAP:
if $class.($stub, as lua id):