aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-04-25 17:43:48 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-04-25 17:44:24 -0700
commit4e821308af654706b8bda5f3d00dce7a933d9942 (patch)
tree674f4eea13cd7475a14344132ec6f12937ac9a96 /core
parent5d59d510cd6fdc8553250e5ec10f19a285e8878c (diff)
Overhauling parsing of Blocks (can no longer contain only one statement)
Diffstat (limited to 'core')
-rw-r--r--core/control_flow.nom8
-rw-r--r--core/math.nom2
-rw-r--r--core/metaprogramming.nom3
3 files changed, 7 insertions, 6 deletions
diff --git a/core/control_flow.nom b/core/control_flow.nom
index b51ecdf..d3d18ac 100644
--- a/core/control_flow.nom
+++ b/core/control_flow.nom
@@ -261,7 +261,9 @@ immediately
%fallthroughs <- []
%is_first <- (yes)
%seen_else <- (no)
- for %func_call in %body.value
+ %branches <-
+ %body.value if (%body.type = "Block") else [%body]
+ for %func_call in %branches
assume (%func_call.type is "Action") or barf ".."
Invalid format for 'when' statement. Only '*' blocks are allowed.
%tokens <- %func_call.value
@@ -308,7 +310,9 @@ immediately
%fallthroughs <- []
%is_first <- (yes)
%seen_else <- (no)
- for %func_call in %body.value
+ %branches <-
+ %body.value if (%body.type = "Block") else [%body]
+ for %func_call in %branches
assume (%func_call.type is "Action") or barf ".."
Invalid format for 'when' statement. Only '*' blocks are allowed.
%tokens <- %func_call.value
diff --git a/core/math.nom b/core/math.nom
index 75e41b4..ad419fa 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -90,6 +90,6 @@ parse [seed random] as: seed random with (=lua "os.time()")
compile [random number, random, rand] to: Lua value "math.random()"
compile [random int %n, random integer %n, randint %n] to: Lua value "math.random(\(%n as lua expr))"
compile [random from %low to %high, random number from %low to %high, rand %low %high] to
- "math.random(\(%low as lua expr), \(%high as lua expr))"
+ Lua value "math.random(\(%low as lua expr), \(%high as lua expr))"
action [random choice from %elements, random choice %elements, random %elements]
=lua "\%elements[math.random(#\%elements)]"
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 9722afd..f6f202f 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -22,9 +22,6 @@ immediately
for i,tok in ipairs(\%actions.value[1].value) do
if tok.type == "Var" then args[#args+1] = nomsu:var_to_lua_identifier(tok.value); end
end
- if \%lua.type == "Text" then
- error("Invalid type for 'compile % to %', expected a dict with expr/statements, but got text.", 0);
- end
for i, arg in ipairs(args) do
lua:append(", ");
lua:append(arg);