aboutsummaryrefslogtreecommitdiff
path: root/nomsu_tree.lua
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-05-30 17:20:22 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-05-30 17:21:19 -0700
commitb53516c47c0dd1f9325f9f721f561487510cca98 (patch)
tree92961e19bc94eec3ab8b0f19357c57399c205b7d /nomsu_tree.lua
parent5637676bc45ce9aa3015726485f63a2a5745a45a (diff)
Simplified and correctified lib/object (though the codegen still need
streamlining), added a .stub member to Action trees, and switched Source's repr to be @filename[start:stop] instead of "filename[start:stop]"
Diffstat (limited to 'nomsu_tree.lua')
-rw-r--r--nomsu_tree.lua74
1 files changed, 41 insertions, 33 deletions
diff --git a/nomsu_tree.lua b/nomsu_tree.lua
index dee5cc2..9245509 100644
--- a/nomsu_tree.lua
+++ b/nomsu_tree.lua
@@ -25,7 +25,7 @@ Tree = function(name, kind, methods)
do
methods.type = name
methods.name = name
- methods.__new = function(self, value, source)
+ methods.__new = methods.__new or function(self, value, source)
assert(source)
if type(source) == 'string' then
source = Source:from_string(source)
@@ -93,10 +93,18 @@ Tree = function(name, kind, methods)
end
end
end
- Types[name] = immutable({
- "value",
- "source"
- }, methods)
+ if name == "Action" then
+ Types[name] = immutable({
+ "value",
+ "source",
+ "stub"
+ }, methods)
+ else
+ Types[name] = immutable({
+ "value",
+ "source"
+ }, methods)
+ end
end
Tree("Block", 'multi')
Tree("EscapedNomsu", 'multi')
@@ -109,35 +117,35 @@ Tree("Number", 'single')
Tree("Comment", 'single')
Tree("Var", 'single')
Tree("Action", 'multi', {
- get_stub = function(self, include_names)
- if include_names == nil then
- include_names = false
- end
- if include_names then
- return concat((function()
- local _accum_0 = { }
- local _len_0 = 1
- local _list_0 = self.value
- for _index_0 = 1, #_list_0 do
- local a = _list_0[_index_0]
- _accum_0[_len_0] = type(a) == "string" and a or "%" .. tostring(a.value)
- _len_0 = _len_0 + 1
- end
- return _accum_0
- end)(), " ")
- else
- return concat((function()
- local _accum_0 = { }
- local _len_0 = 1
- local _list_0 = self.value
- for _index_0 = 1, #_list_0 do
- local a = _list_0[_index_0]
- _accum_0[_len_0] = type(a) == "string" and a or "%"
- _len_0 = _len_0 + 1
- end
- return _accum_0
- end)(), " ")
+ __new = function(self, value, source)
+ assert(source)
+ if type(source) == 'string' then
+ source = Source:from_string(source)
end
+ local stub = concat((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ for _index_0 = 1, #value do
+ local a = value[_index_0]
+ _accum_0[_len_0] = type(a) == "string" and a or "%"
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)(), " ")
+ return value, source, stub
+ end,
+ get_spec = function(self)
+ return concat((function()
+ local _accum_0 = { }
+ local _len_0 = 1
+ local _list_0 = self.value
+ for _index_0 = 1, #_list_0 do
+ local a = _list_0[_index_0]
+ _accum_0[_len_0] = type(a) == "string" and a or "%" .. tostring(a.value)
+ _len_0 = _len_0 + 1
+ end
+ return _accum_0
+ end)(), " ")
end
})
return Types