aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-09-26 12:45:08 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-09-26 12:45:19 -0700
commit692fae5416ce1f2702b599ffb27b2e3d2235eba7 (patch)
tree12ae256ef5606251bc013935390fdef7e737d79d /core
parent28d0792e69bbb9c467c616eb3dc89a60085c35f2 (diff)
Incremental fixes and more nomnom ports.
Diffstat (limited to 'core')
-rw-r--r--core/math.nom26
-rw-r--r--core/metaprogramming.nom11
2 files changed, 30 insertions, 7 deletions
diff --git a/core/math.nom b/core/math.nom
index d6ddbce..5daa2d8 100644
--- a/core/math.nom
+++ b/core/math.nom
@@ -89,6 +89,32 @@ compile [sum of %items, sum %items] to:
%clauses = ((% as lua expr) for % in %items)
return (Lua value "(\(%clauses::joined with " + "))")
+parse [if all of %items %body, if all of %items then %body] as (..)
+ if (all of %items) %body
+parse [unless all of %items %body, unless all of %items then %body] as (..)
+ if (not (all of %items)) %body
+parse [if any of %items %body, if any of %items then %body] as (..)
+ if (any of %items) %body
+parse [unless any of %items %body, unless any of %items then %body] as (..)
+ if (not (any of %items)) %body
+parse [if none of %items %body, if none of %items then %body] as (..)
+ if (not (any of %items)) %body
+parse [unless none of %items %body, unless none of %items then %body] as (..)
+ if (any of %items) %body
+
+parse [if all of %items %body else %else, if all of %items then %body else %else] as (..)
+ if (all of %items) %body else %else
+parse [unless all of %items %body else %else, unless all of %items then %body else %else] as (..)
+ if (not (all of %items)) %body else %else
+parse [if any of %items %body else %else, if any of %items then %body else %else] as (..)
+ if (any of %items) %body else %else
+parse [unless any of %items %body else %else, unless any of %items then %body else %else] as (..)
+ if (not (any of %items)) %body else %else
+parse [if none of %items %body else %else, if none of %items then %body else %else] as (..)
+ if (not (any of %items)) %body else %else
+parse [unless none of %items %body else %else, unless none of %items then %body else %else] as (..)
+ if (any of %items) %body else %else
+
compile [product of %items, product %items] to:
unless (%items.type is "List"):
return (Lua value "utils.product(\(%items as lua expr))")
diff --git a/core/metaprogramming.nom b/core/metaprogramming.nom
index 1503905..8b75ccd 100644
--- a/core/metaprogramming.nom
+++ b/core/metaprogramming.nom
@@ -184,14 +184,14 @@ compile [parse %actions as %body] to (..)
i = i + 1
elseif k == "source" then
ret[#ret+1] = k.."= "..tostring(v):as_lua()
- elseif type(k) == 'string' and k:match("[_a-zA-Z][_a-zA-Z0-9]*") then
+ elseif lua_type_of_1(k) == 'string' and k:match("[_a-zA-Z][_a-zA-Z0-9]*") then
ret[#ret+1] = k.."= "..make_tree(v)
else
ret[#ret+1] = "["..make_tree(k).."]= "..make_tree(v)
end
end
return t.type.."{"..table.concat(ret, ", ").."}"
- elseif type(t) == 'number' then
+ elseif lua_type_of_1(t) == 'number' then
return tostring(t)
else
return t:as_lua()
@@ -231,12 +231,12 @@ compile [%tree as inline nomsu] to (..)
action [%var as lua identifier, %var as lua id] (..)
lua> "\
- ..if type(\%var) == 'string' then return \%var:as_lua_id()
+ ..if lua_type_of_1(\%var) == 'string' then return \%var:as_lua_id()
elseif AST.is_syntax_tree(\%var, 'Var') then return \%var[1]:as_lua_id()
elseif AST.is_syntax_tree(\%var) then
local lua = \(%var as lua expr)
if not tostring(lua):match("^[_a-zA-Z][_a-zA-Z0-9]*$") then
- \(compile error at %var "This is not a valid Lua identifier.")
+ compile_error_at_1_2(\%var, "This is not a valid Lua identifier.")
end
return lua
else error("Unknown type: "..tostring(\%var))
@@ -328,9 +328,6 @@ test:
assume ("" is text)
assume ("" isn't a "Dict")
-%dict_mt = (=lua "getmetatable(\{})")
-%list_mt = (=lua "getmetatable(\[])")
-
action [% is text] (=lua "\(lua type of %) == 'string'")
action [% is not text, % isn't text] (=lua "\(lua type of %) ~= 'string'")
action [type of %]: