aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2018-09-28 22:15:24 -0700
committerBruce Hill <bruce@bruce-hill.com>2018-09-28 22:15:24 -0700
commitb7e768a2f826f6643e47b35272dbb35136d489b6 (patch)
treeaeec27649aabbc02dd0101b8a03be8976e73c08d
parent63d8b1cd3f34b15bf86210b99209e8b57e7019bb (diff)
Rebuild.
-rw-r--r--code_obj.lua29
-rw-r--r--containers.lua2
-rw-r--r--syntax_tree.lua3
3 files changed, 18 insertions, 16 deletions
diff --git a/code_obj.lua b/code_obj.lua
index 577eaf3..a8d7adf 100644
--- a/code_obj.lua
+++ b/code_obj.lua
@@ -78,7 +78,7 @@ do
local _class_0
local _base_0 = {
is_code = true,
- __tostring = function(self)
+ as_smext = function(self)
if self.__str == nil then
local buff, indent = { }, 0
local match, gsub, rep
@@ -95,7 +95,7 @@ do
end
end
else
- b = tostring(b)
+ b = b:as_smext()
if indent > 0 then
b = gsub(b, "\n", "\n" .. rep(" ", indent))
end
@@ -106,6 +106,9 @@ do
end
return self.__str
end,
+ __tostring = function(self)
+ return self:as_smext()
+ end,
as_lua = function(self)
return tostring(self.__class.__name) .. "(" .. tostring(concat({
tostring(self.source):as_lua(),
@@ -123,13 +126,13 @@ do
}, ", ")) .. ")"
end,
__len = function(self)
- return #tostring(self)
+ return #self:as_smext()
end,
match = function(self, ...)
- return tostring(self):match(...)
+ return self:as_smext():match(...)
end,
gmatch = function(self, ...)
- return tostring(self):gmatch(...)
+ return self:as_smext():gmatch(...)
end,
dirty = function(self)
self.__str = nil
@@ -155,9 +158,6 @@ do
if b.is_code then
b.dirty = error
end
- if type(b) ~= 'string' and not (type(b) == 'table' and b.is_code) then
- b = b:as_lua()
- end
bits[#bits + 1] = b
_continue_0 = true
until true
@@ -169,7 +169,7 @@ do
end,
trailing_line_len = function(self)
if self._trailing_line_len == nil then
- self._trailing_line_len = #tostring(self):match("[^\n]*$")
+ self._trailing_line_len = #self:as_smext():match("[^\n]*$")
end
return self._trailing_line_len
end,
@@ -212,7 +212,9 @@ do
if b.is_code then
b.dirty = error
end
- b = tostring(b)
+ if not (type(b) == 'string') then
+ b = b:as_smext()
+ end
local line = match(b, "\n([^\n]*)$")
if line then
line_len = #line
@@ -233,9 +235,6 @@ do
if b.is_code then
b.dirty = error
end
- if type(b) ~= 'string' and not (type(b) == 'table' and b.is_code) then
- b = b:as_lua()
- end
bits[i] = b
end
return self:dirty()
@@ -253,7 +252,6 @@ do
if type(self.source) == 'string' then
self.source = Source:from_string(self.source)
end
- assert(self.source and Source:is_instance(self.source), "Source has the wrong type")
return self:append(...)
end,
__base = _base_0,
@@ -402,8 +400,9 @@ do
end
else
walk(b, pos)
+ b = b:as_smext()
end
- pos = pos + #tostring(b)
+ pos = pos + #b
end
end
walk(self, 1)
diff --git a/containers.lua b/containers.lua
index ab632c4..b51b133 100644
--- a/containers.lua
+++ b/containers.lua
@@ -216,6 +216,8 @@ local _list_mt = {
return rawset(self, k, v)
end
}
+_list_mt.__index.as_lua = _list_mt.as_lua
+_list_mt.__index.as_nomsu = _list_mt.as_nomsu
List = function(t)
return setmetatable(t, _list_mt)
end
diff --git a/syntax_tree.lua b/syntax_tree.lua
index afdb631..851711a 100644
--- a/syntax_tree.lua
+++ b/syntax_tree.lua
@@ -11,7 +11,7 @@ AST.is_syntax_tree = function(n, t)
if t == nil then
t = nil
end
- return type(n) == 'table' and getmetatable(n) and AST[n.type] == getmetatable(n) and (t == nil or n.type == t)
+ return type(n) == 'table' and getmetatable(n) and getmetatable(n).__type == "Syntax Tree" and (t == nil or n.type == t)
end
local as_lua
as_lua = function(self)
@@ -54,6 +54,7 @@ for _index_0 = 1, #types do
cls.__index = cls
cls.__name = name
cls.type = name
+ cls.__type = "Syntax Tree"
cls.is_instance = function(self, x)
return getmetatable(x) == self
end