aboutsummaryrefslogtreecommitdiff
path: root/nomsu_tree.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-03 21:55:46 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-03 21:55:58 -0700
commit2abaf67b66c6a967ee51e59c7802534b07706b6b (patch)
treeb6b102485472278e2958ea31eaa4ed1278ace9be /nomsu_tree.lua
parent36ead4d82bdb058229271fb742f659d47c5c48a3 (diff)
Fix for compile lib putting the files in the wrong place.
Diffstat (limited to 'nomsu_tree.lua')
-rw-r--r--nomsu_tree.lua143
1 files changed, 123 insertions, 20 deletions
diff --git a/nomsu_tree.lua b/nomsu_tree.lua
index 92871e5..5b24b75 100644
--- a/nomsu_tree.lua
+++ b/nomsu_tree.lua
@@ -93,6 +93,19 @@ Tree("File", {
end
end
return nomsu
+ end,
+ map = function(self, fn)
+ return fn(self) or self:with_value(Tuple(unpack((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local v = _list_0[_index_0]
+ _accum_0[_len_0] = v:map(fn)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())))
end
})
Tree("Nomsu", {
@@ -109,6 +122,9 @@ Tree("Nomsu", {
return nomsu and Nomsu(self.source, "\\:\n ", nomsu)
end
return nomsu and Nomsu(self.source, "\\(", nomsu, ")")
+ end,
+ map = function(self, fn)
+ return fn(self) or self:with_value(self.value:map(fn))
end
})
Tree("Block", {
@@ -151,15 +167,27 @@ Tree("Block", {
end
end
return nomsu
+ end,
+ map = function(self, fn)
+ return fn(self) or self:with_value(Tuple(unpack((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local v = _list_0[_index_0]
+ _accum_0[_len_0] = v:map(fn)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())))
end
})
local math_expression = re.compile([[ ([+-] " ")* "%" (" " [*/^+-] (" " [+-])* " %")+ !. ]])
Tree("Action", {
as_lua = function(self, nomsu)
local stub = self:get_stub()
- local action = rawget(nomsu.environment.ACTIONS, stub)
- local metadata = nomsu.action_metadata[action]
- if metadata and metadata.compile_time then
+ local macro = nomsu.environment.MACROS[stub]
+ if macro then
local args
do
local _accum_0 = { }
@@ -174,26 +202,23 @@ Tree("Action", {
end
args = _accum_0
end
- if metadata.arg_orders then
- local new_args
- do
- local _accum_0 = { }
- local _len_0 = 1
- local _list_0 = metadata.arg_orders[stub]
- for _index_0 = 1, #_list_0 do
- local p = _list_0[_index_0]
- _accum_0[_len_0] = args[p - 1]
- _len_0 = _len_0 + 1
- end
- new_args = _accum_0
+ do
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = nomsu.environment.ARG_ORDERS[macro][stub]
+ for _index_0 = 1, #_list_0 do
+ local p = _list_0[_index_0]
+ _accum_0[_len_0] = args[p - 1]
+ _len_0 = _len_0 + 1
end
- args = new_args
+ args = _accum_0
end
- local ret = action(self, unpack(args))
+ local ret = macro(self, unpack(args))
return ret
end
+ local action = rawget(nomsu.environment.ACTIONS, stub)
local lua = Lua.Value(self.source)
- if not metadata and math_expression:match(stub) then
+ if not action and math_expression:match(stub) then
for i, tok in ipairs(self.value) do
if tok.type == "Word" then
lua:append(tok.value)
@@ -234,11 +259,11 @@ Tree("Action", {
break
end
end
- if metadata and metadata.arg_orders then
+ if action then
do
local _accum_0 = { }
local _len_0 = 1
- local _list_0 = metadata.arg_orders[stub]
+ local _list_0 = nomsu.environment.ARG_ORDERS[action][stub]
for _index_0 = 1, #_list_0 do
local p = _list_0[_index_0]
_accum_0[_len_0] = args[p]
@@ -375,6 +400,19 @@ Tree("Action", {
end
return nomsu
end
+ end,
+ map = function(self, fn)
+ return fn(self) or self:with_value(Tuple(unpack((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local v = _list_0[_index_0]
+ _accum_0[_len_0] = v:map(fn)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())))
end
})
Tree("Text", {
@@ -482,6 +520,19 @@ Tree("Text", {
end
return nomsu
end
+ end,
+ map = function(self, fn)
+ return fn(self) or self:with_value(Tuple(unpack((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local v = _list_0[_index_0]
+ _accum_0[_len_0] = type(v) == 'string' and v or v:map(fn)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())))
end
})
Tree("List", {
@@ -568,6 +619,19 @@ Tree("List", {
end
return nomsu
end
+ end,
+ map = function(self, fn)
+ return fn(self) or self:with_value(Tuple(unpack((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local v = _list_0[_index_0]
+ _accum_0[_len_0] = v:map(fn)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())))
end
})
Tree("Dict", {
@@ -685,6 +749,20 @@ Tree("Dict", {
end
return nomsu
end
+ end,
+ map = function(self, fn)
+ local DictEntry = Types.DictEntry
+ return fn(self) or self:with_value(Tuple(unpack((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local e = _list_0[_index_0]
+ _accum_0[_len_0] = DictEntry(e.key:map(fn), e.value:map(fn))
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())))
end
})
Tree("IndexChain", {
@@ -741,6 +819,19 @@ Tree("IndexChain", {
nomsu:append(bit_nomsu)
end
return nomsu
+ end,
+ map = function(self, fn)
+ return fn(self) or self:with_value(Tuple(unpack((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local v = _list_0[_index_0]
+ _accum_0[_len_0] = v:map(fn)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)())))
end
})
Tree("Number", {
@@ -752,6 +843,9 @@ Tree("Number", {
inline = false
end
return Nomsu(self.source, tostring(self.value))
+ end,
+ map = function(self, fn)
+ return fn(self) or self
end
})
Tree("Var", {
@@ -770,6 +864,9 @@ Tree("Var", {
inline = false
end
return Nomsu(self.source, "%", self.value)
+ end,
+ map = function(self, fn)
+ return fn(self) or self
end
})
Tree("Word", {
@@ -781,6 +878,9 @@ Tree("Word", {
inline = false
end
return Nomsu(self.source, self.value)
+ end,
+ map = function(self, fn)
+ return fn(self) or self
end
})
Tree("Comment", {
@@ -799,6 +899,9 @@ Tree("Comment", {
else
return Nomsu(self.source, "#", self.value)
end
+ end,
+ map = function(self, fn)
+ return fn(self) or self
end
})
return Types