aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-20 17:56:06 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-20 17:56:15 -0700
commit24b8649c3391e35104a492d8546ce197cbdc5068 (patch)
treec9d5476b2c893f14558f2e48847bc779c4bce402
parent568e21dc29d72fad3d8b09ec8dd53f845bb93463 (diff)
Tweaks to the API for text matching.
-rw-r--r--compatibility/2.4.nom56
-rw-r--r--compatibility/compatibility.nom4
-rw-r--r--core/metaprogramming.nom4
-rw-r--r--core/text.nom6
4 files changed, 63 insertions, 7 deletions
diff --git a/compatibility/2.4.nom b/compatibility/2.4.nom
new file mode 100644
index 0000000..ae0cfba
--- /dev/null
+++ b/compatibility/2.4.nom
@@ -0,0 +1,56 @@
+#!/usr/bin/env nomsu -V2.4
+use "core"
+use "compatibility/compatibility.nom"
+
+upgrade %tree to "2.4" as:
+ unless (%tree is "Action" syntax tree): return
+ if %tree.stub is:
+ "when %":
+ %conditions = []
+ %new_lines = []
+ %body = ((%tree.2 upgraded) if (%tree.2 is "Block" syntax tree) else [%tree.2 upgraded])
+ for %line in %body:
+ if:
+ (not (%line is syntax tree)):
+ compile error at %tree.source "WUT: %s"
+ (not (%line is "Action" syntax tree)):
+ add %line to %new_lines
+ (%line.stub is "* %"):
+ add %line.2 to %conditions
+ (%line.stub == "* else %"):
+ add (\(else %block) with vars {block:%line.3}) to %new_lines
+ (%line.stub != "* % %"):
+ add %line to %new_lines
+ else:
+ add %line.2 to %conditions
+ %action = %line.3
+ unless (%action is "Block" syntax tree):
+ %action = (=lua "Block(\%action.source, \%action)")
+ add %action to %conditions
+ add (=lua "Action(\%conditions[1].source, unpack(\%conditions))") to %new_lines
+ %conditions = []
+ return (\(if %body) with vars {body:=lua "Block(\%tree[2].source, unpack(\%new_lines))"})
+
+ "when % is ? %" "when % = ? %":
+ %values = []
+ %new_lines = []
+ %body = ((%tree.5 upgraded) if (%tree.5 is "Block" syntax tree) else [%tree.5 upgraded])
+ for %line in %body:
+ if:
+ (not (%line is "Action" syntax tree)):
+ add %line to %new_lines
+ (%line.stub is "* %"):
+ add %line.2 to %values
+ (%line.stub == "* else %"):
+ add (\(else %block) with vars {block:%line.3}) to %new_lines
+ (%line.stub != "* % %"):
+ add %line to %new_lines
+ else:
+ add %line.2 to %values
+ %action = %line.3
+ unless (%action is "Block" syntax tree):
+ %action = (=lua "Block(\%action.source, \%action)")
+ add %action to %values
+ add (=lua "Action(\%values[1].source, unpack(\%values))") to %new_lines
+ %values = []
+ return (\(if %var is %body) with vars {var: %tree.2 upgraded, body:=lua "Block(\%tree[5].source, unpack(\%new_lines))"})
diff --git a/compatibility/compatibility.nom b/compatibility/compatibility.nom
index c5ac55f..87ba321 100644
--- a/compatibility/compatibility.nom
+++ b/compatibility/compatibility.nom
@@ -1,4 +1,4 @@
-#!/usr/bin/env nomsu -V2.3.4.3
+#!/usr/bin/env nomsu -V2.5
use "core"
use "lib/os.nom"
@@ -42,7 +42,7 @@ action [..]
%tree upgraded from %start_version to %end_version
%tree upgraded to %end_version from %start_version
..:
- local action [%ver as list] ((% as number) for % where %ver matches "[0-9]+")
+ local action [%ver as list] ((% as number) for % in %ver matching "[0-9]+")
%versions = {}
for %v = % in %UPGRADES: %versions.%v = (yes)
for %v = % in %ACTION_UPGRADES: %versions.%v = (yes)
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 028a914..9e51d7d 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -3,7 +3,7 @@
This File contains actions for making actions and compile-time actions and some helper
functions to make that easier.
-lua> "NOMSU_CORE_VERSION = 4"
+lua> "NOMSU_CORE_VERSION = 5"
lua> ".."
nomsu.COMPILE_ACTIONS["% -> %"] = function(nomsu, tree, \%args, \%body)
local lua = LuaCode.Value(tree.source, "function(")
@@ -240,4 +240,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) \ No newline at end of file
+ \(Nomsu syntax version).\(core version).\(Nomsu compiler version).\(lib version)
diff --git a/core/text.nom b/core/text.nom
index 30eab50..dc67ec5 100644
--- a/core/text.nom
+++ b/core/text.nom
@@ -30,7 +30,7 @@ action [lines in %text, lines of %text] (..)
end
return result
-compile [for %match where %text matches %patt %body] to (..)
+compile [for %match in %text matching %patt %body] to (..)
Lua ".."
for \(%match as lua expr) in \(%text as lua expr):gmatch(\(%patt as lua expr)) do
\(%body as lua statements)
@@ -38,7 +38,7 @@ compile [for %match where %text matches %patt %body] to (..)
end
\(compile as (===stop %match ===))
-compile [%expr for %match where %text matches %patt] to (..)
+compile [%expr for %match in %text matching %patt] to (..)
Lua value ".."
(function()
local ret = list{}
@@ -66,4 +66,4 @@ lua> ".."
return LuaCode.Value(tree.source, lua)
end
end
- end \ No newline at end of file
+ end