aboutsummaryrefslogtreecommitdiff
path: root/lib/core
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2019-03-27 15:22:46 -0700
committerBruce Hill <bruce@bruce-hill.com>2019-03-27 15:22:46 -0700
commita1849da175765350e013bdeecfa4e0ad3c066937 (patch)
tree616a115790271757148044e2b3228fb715c00726 /lib/core
parentbb07e6724118c431c3beed4060776678128905a1 (diff)
Autoformat (mostly just to do with the new
blank-line-after-end-of-multi-indent-block rule
Diffstat (limited to 'lib/core')
-rw-r--r--lib/core/collections.nom3
-rw-r--r--lib/core/control_flow.nom3
-rw-r--r--lib/core/coroutines.nom3
-rw-r--r--lib/core/errors.nom5
-rw-r--r--lib/core/id.nom1
-rw-r--r--lib/core/init.nom1
-rw-r--r--lib/core/io.nom1
-rw-r--r--lib/core/math.nom6
-rw-r--r--lib/core/metaprogramming.nom3
-rw-r--r--lib/core/operators.nom7
-rw-r--r--lib/core/text.nom1
-rw-r--r--lib/core/things.nom3
-rw-r--r--lib/core/time.nom5
13 files changed, 24 insertions, 18 deletions
diff --git a/lib/core/collections.nom b/lib/core/collections.nom
index e9da70c..1b7dadb 100644
--- a/lib/core/collections.nom
+++ b/lib/core/collections.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file contains code that supports manipulating and using collections like lists
and dictionaries.
@@ -163,6 +162,7 @@ external:
unless $seen.$:
$unique, add $
$seen.$ = (yes)
+
return $unique
### Ranges:
@@ -196,6 +196,7 @@ $range_mt = {
..else:
if ($i < $self.last):
return (nil)
+
return $i
return $range_mt.$key
diff --git a/lib/core/control_flow.nom b/lib/core/control_flow.nom
index 4dfe5f8..ca2450b 100644
--- a/lib/core/control_flow.nom
+++ b/lib/core/control_flow.nom
@@ -218,6 +218,7 @@ test:
..else:
$loop =
Lua "for _i,\($value as lua identifier) in _ipairs(\($iterable as lua expr)) do"
+
--- (loop set) ---
### TODO: don't always wrap in block
@@ -276,6 +277,7 @@ test:
$nums, add $inner
if ($inner == 5):
stop $outer
+
assume ($nums == [1, -2, 3, -2, 3, 4, 3, 4, 5])
### repeat $n times is a shorthand:
@@ -454,6 +456,7 @@ test:
recurse $ on $2
..else:
$flat, add $
+
assume (sorted $flat) == [1, 2, 3, 4, 5, 6]
### Recurion control flow
diff --git a/lib/core/coroutines.nom b/lib/core/coroutines.nom
index a11d6ee..3102d70 100644
--- a/lib/core/coroutines.nom
+++ b/lib/core/coroutines.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file defines the code that creates and manipulates coroutines
@@ -16,6 +15,7 @@ test:
yield 5
repeat 3 times:
yield 6
+
$nums = []
for $ in (coroutine from $fn): $nums, add $
assume ($nums == [4, 5, 6, 6, 6])
@@ -27,6 +27,7 @@ test:
$d.x += 1
yield
$d.x += 1
+
repeat while ((coroutine status of $co) != "dead"): resume $co
assume $d.x == 3
$(co) = (coroutine: yield 5)
diff --git a/lib/core/errors.nom b/lib/core/errors.nom
index 0b5479d..ef5412e 100644
--- a/lib/core/errors.nom
+++ b/lib/core/errors.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file contains basic error reporting code
@@ -27,6 +26,7 @@ use "core/control_flow"
end
end
")
+
if ($condition.type == "Action"):
when $condition.stub is:
"1 ==":
@@ -132,6 +132,7 @@ test:
$fallback_lua, prepend "\n\$msg_lua = _result[2]\n"
if ($msg_lua, text, is lua id):
$fallback_lua, add free vars [($msg_lua, text)]
+
$fallback_lua, prepend "-- Failure:\n"
return Lua ("
do
@@ -191,4 +192,4 @@ test:
if not _results[1] then error(_results[2], 0) end
if not _fell_through then return table.unpack(_results, 2) end
end
-")
+") \ No newline at end of file
diff --git a/lib/core/id.nom b/lib/core/id.nom
index 7324eea..2a1e8a3 100644
--- a/lib/core/id.nom
+++ b/lib/core/id.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
A simple UUID function based on RFC 4122: http://www.ietf.org/rfc/rfc4122.txt
diff --git a/lib/core/init.nom b/lib/core/init.nom
index 84fd3cd..bf5852a 100644
--- a/lib/core/init.nom
+++ b/lib/core/init.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
### Export everything
export "core/metaprogramming"
export "core/operators"
diff --git a/lib/core/io.nom b/lib/core/io.nom
index c4f74d9..43960ce 100644
--- a/lib/core/io.nom
+++ b/lib/core/io.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file contains basic input/output code
diff --git a/lib/core/math.nom b/lib/core/math.nom
index 9b53385..945ad13 100644
--- a/lib/core/math.nom
+++ b/lib/core/math.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file defines some common math literals and functions
@@ -19,6 +18,7 @@ external:
$nan = (NaN)
unless ($nan != $nan):
fail "NaN failed"
+
[infinity, inf] all compile to "math.huge"
[not a number, NaN, nan] all compile to "(0/0)"
[pi, Pi, PI] all compile to "math.pi"
@@ -73,12 +73,14 @@ external:
for $ in $items:
unless $:
return (no)
+
return (yes)
[not all of $items, not all $items] all parse as (not (all of $items))
[any of $items, any $items] all mean:
for $ in $items:
if $:
return (yes)
+
return (no)
[none of $items, none $items] all parse as (not (any of $items))
@@ -123,6 +125,7 @@ external:
if (($best == (nil)) or ($key < $best_key)):
$best = $item
$best_key = $key
+
return $best
(max of $items by $item = $value_expr) parses as
@@ -134,6 +137,7 @@ external:
if (($best == (nil)) or ($key > $best_key)):
$best = $item
$best_key = $key
+
return $best
test:
diff --git a/lib/core/metaprogramming.nom b/lib/core/metaprogramming.nom
index bd0b6d7..a9649c6 100644
--- a/lib/core/metaprogramming.nom
+++ b/lib/core/metaprogramming.nom
@@ -248,6 +248,7 @@ test:
with external [$x]:
$x = "inner"
$y = "inner"
+
set external x local y
unless (($x == "inner") and ($y == "outer")):
fail "'with external' failed."
@@ -516,4 +517,4 @@ test:
($tree with $t -> $replacement) parses as ($tree, with ($t -> $replacement))
[tree $tree with vars $replacements, $tree with vars $replacements] all parse as
$tree, with $replacements
-($tree has subtree $match_tree) parses as ($tree, contains $match_tree)
+($tree has subtree $match_tree) parses as ($tree, contains $match_tree) \ No newline at end of file
diff --git a/lib/core/operators.nom b/lib/core/operators.nom
index dbc0b18..229d846 100644
--- a/lib/core/operators.nom
+++ b/lib/core/operators.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file contains definitions of operators like "+" and "and".
@@ -136,6 +135,7 @@ test:
unless ($calls == 1):
fail "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)
@@ -213,7 +213,7 @@ lua> "end"
### Unary operators
test:
- assume (-(5) == -5)
+ assume ((- 5) == -5)
assume ((not (yes)) == (no))
-$ compiles to "(-(\($ as lua expr)))"
(not $) compiles to "(not \($ as lua expr))"
@@ -246,6 +246,7 @@ test:
wrap $x around 3
unless ($x == 1):
fail "wrap around failed"
+
($var += $) parses as ($var = (($var or 0) + $))
($var -= $) parses as ($var = (($var or 0) - $))
($var *= $) parses as ($var = (($var or 1) * $))
@@ -253,4 +254,4 @@ test:
($var ^= $) parses as ($var = ($var ^ $))
($var and= $) parses as ($var = ($var and $))
($var or= $) parses as ($var = ($var or $))
-(wrap $var around $) parses as ($var = ($var wrapped around $))
+(wrap $var around $) parses as ($var = ($var wrapped around $)) \ No newline at end of file
diff --git a/lib/core/text.nom b/lib/core/text.nom
index 42f2e41..38025da 100644
--- a/lib/core/text.nom
+++ b/lib/core/text.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file contains some definitions of text escape sequences, including ANSI console
color codes.
diff --git a/lib/core/things.nom b/lib/core/things.nom
index 42e4c62..a76a917 100644
--- a/lib/core/things.nom
+++ b/lib/core/things.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
A library for simple object oriented programming.
@@ -122,4 +121,4 @@ external:
")
$lua, add free vars [$class_id]
- return $lua
+ return $lua \ No newline at end of file
diff --git a/lib/core/time.nom b/lib/core/time.nom
index 88241d6..aa59d7a 100644
--- a/lib/core/time.nom
+++ b/lib/core/time.nom
@@ -1,5 +1,4 @@
#!/usr/bin/env nomsu -V7.0.0
-
###
This file defines time-related actions.
@@ -37,7 +36,7 @@ external:
if ($other is "a Time"):
return ($os.difftime $self ($os.time $other))
return (a Time ($os.date "*t" ($self - $other, rounded)))
-
+
($self, <$other) means (($self, since epoch) < ($other, since epoch))
($self, <=$other) means (($self, since epoch) <= ($other, since epoch))
($self, as text) means ($os.date "%I:%M%p %a %b %e %Y" ($os.time $self))
@@ -51,4 +50,4 @@ external:
### Lua does not come with a sleep() function, only an os.clock() function,
so this busy-loop is necessary for cross-platform compatibility.
$deadline = (($os.clock()) + $t)
- repeat while (($os.clock()) < $deadline): do nothing
+ repeat while (($os.clock()) < $deadline): do nothing \ No newline at end of file