aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-09 17:13:40 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-09 17:14:05 -0700
commit85ef9534e370e08105b0a190d1f27cc56992a73c (patch)
tree064c4be1976195197b32b2bc331b7bc4da1d77a3
parentcb1c3106f8d6517bb80d1deed6d21cb4f0a10bec (diff)
Added pattern matching for text, and comprehension versions of that and
file walking.
-rw-r--r--core/text.nom18
-rw-r--r--lib/os.nom10
2 files changed, 28 insertions, 0 deletions
diff --git a/core/text.nom b/core/text.nom
index 840a596..37b8082 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -26,6 +26,24 @@ action [lines in %text, lines of %text]
end
return result
+compile [for %match where %text matches %patt %body] to
+ Lua ".."
+ for \(%match as lua expr) in \(%text as lua expr):gmatch(\(%patt as lua expr)) do
+ \(%body as lua statements)
+ \(compile as: === next %match ===)
+ end
+ \(compile as: === stop %match ===)
+
+compile [%expr for %match where %text matches %patt] to
+ Lua value ".."
+ (function()
+ local ret = list{}
+ for \(%match as lua expr) in \(%text as lua expr):gmatch(\(%patt as lua expr)) do
+ ret[#ret+1] = \(%expr as lua statements)
+ end
+ return ret
+ end)()
+
# Text literals
lua> ".."
do
diff --git a/lib/os.nom b/lib/os.nom
index 25b47b6..ee8b79b 100644
--- a/lib/os.nom
+++ b/lib/os.nom
@@ -23,6 +23,16 @@ compile [for file %f in %path %body] to
end
\(compile as: === stop %f ===)
+compile [%expr for file %f in %path] to
+ Lua value ".."
+ (function()
+ local ret = list{}
+ for \(%f as lua expr) in files.walk(\(%path as lua expr)) do
+ ret[#ret+1] = \(%expr as lua statements)
+ end
+ return ret
+ end)()
+
action [write to file %filename %text, to file %filename write %text]
lua> ".."
local file = io.open(\%filename, 'w')