aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/collections.nom11
-rw-r--r--core/control_flow.nom3
-rw-r--r--core/text.nom3
3 files changed, 17 insertions, 0 deletions
diff --git a/core/collections.nom b/core/collections.nom
index 367356b..94fc02c 100644
--- a/core/collections.nom
+++ b/core/collections.nom
@@ -182,6 +182,15 @@ compile [%dict with fallback %key -> %value] to
end})
# Sorting
+test
+ %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}
+ sort %x by % = %keys.%
+ assume: %x = [2,3,1]
compile [sort %items] to: Lua "table.sort(\(%items as lua expr));"
parse [..]
sort %items by %item = %key_expr
@@ -193,6 +202,7 @@ parse [..]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+test: assume: (sorted [3,1,2]) = [1,2,3]
action [%items sorted, sorted %items]
%copy <- (% for % in %items)
sort %copy
@@ -206,6 +216,7 @@ parse [..]
sort %copy by %item = %key
return %copy
+test: assume: (unique [1,2,1,3,2,3]) = [1,2,3]
action [unique %items]
%unique <- []
%seen <- {}
diff --git a/core/control_flow.nom b/core/control_flow.nom
index 61438d1..4733168 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -8,14 +8,17 @@ use "core/operators.nom"
use "core/errors.nom"
# No-Op
+test: do nothing
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
+test: unless (yes): barf "conditional fail"
parse [unless %condition %unless_body] as: if (not %condition) %unless_body
compile [if %condition %if_body else %else_body, unless %condition %else_body else %if_body] to
diff --git a/core/text.nom b/core/text.nom
index 37b8082..d09e6b5 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -44,6 +44,9 @@ compile [%expr for %match where %text matches %patt] to
return ret
end)()
+compile [%text matches %pattern] to
+ Lua value "(\(%text as lua expr):match(\(%pattern as lua expr)) and true or false)"
+
# Text literals
lua> ".."
do