aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bitbucket@bruce-hill.com>2018-07-22 13:48:44 -0700
committerBruce Hill <bitbucket@bruce-hill.com>2018-07-22 13:48:44 -0700
commit01d5f810ed7fd6e9b261b1fe793f8666970b2068 (patch)
tree1b8ff8f15c8bd940e724ad32dd7bc9c8cd1115d6
parente408891abf96cf1a89feeef2e91ffbefd6cc5937 (diff)
Committing built lua files.
-rw-r--r--nomsu_tree.lua11
-rw-r--r--parser.lua4
2 files changed, 14 insertions, 1 deletions
diff --git a/nomsu_tree.lua b/nomsu_tree.lua
index bbb12ab..64b4efc 100644
--- a/nomsu_tree.lua
+++ b/nomsu_tree.lua
@@ -100,6 +100,17 @@ for _index_0 = 1, #types do
end
return replacement
end
+ cls.__eq = function(self, other)
+ if type(self) ~= type(other) or #self ~= #other or getmetatable(self) ~= getmetatable(other) then
+ return false
+ end
+ for i = 1, #self do
+ if self[i] ~= other[i] then
+ return false
+ end
+ end
+ return true
+ end
end
AST[name] = setmetatable(cls, {
__tostring = function(self)
diff --git a/parser.lua b/parser.lua
index 327424f..2a260ba 100644
--- a/parser.lua
+++ b/parser.lua
@@ -74,12 +74,13 @@ do
local err_line = files.get_line(src, line_no)
local next_line = files.get_line(src, line_no + 1)
local i = err_pos - files.get_line_starts(src)[line_no]
+ local j = i + (end_pos - start_pos)
local pointer = ("-"):rep(i) .. "^"
err_msg = colored.bright(colored.yellow(colored.onred((err_msg or "Parse error") .. " at " .. tostring(userdata.source.filename) .. ":" .. tostring(line_no) .. ":")))
if #prev_line > 0 then
err_msg = err_msg .. ("\n" .. colored.dim(prev_line))
end
- err_line = colored.white(err_line:sub(1, i)) .. colored.bright(colored.red(err_line:sub(i + 1, i + 1))) .. colored.dim(err_line:sub(i + 2, -1))
+ err_line = colored.white(err_line:sub(1, i)) .. colored.bright(colored.red(err_line:sub(i + 1, j + 1))) .. colored.dim(err_line:sub(j + 2, -1))
err_msg = err_msg .. "\n" .. tostring(err_line) .. "\n" .. tostring(colored.red(pointer))
if #next_line > 0 then
err_msg = err_msg .. ("\n" .. colored.dim(next_line))
@@ -150,6 +151,7 @@ Parser.parse = function(nomsu_code, source, version)
end
source = source or nomsu_code.source
nomsu_code = tostring(nomsu_code)
+ source = source or Source("string: " .. nomsu_code, 1, #nomsu_code)
version = version or nomsu_code:match("^#![^\n]*nomsu[ ]+-V[ ]*([0-9.]+)")
local syntax_version = version and tonumber(version:match("^[0-9]+")) or Parser.version
local userdata = {