From 4fd6d817c87fe3927c48a3c47440c92adb35065e Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 24 Jun 2018 23:21:07 -0700 Subject: [PATCH] Reducing imports. --- parser.lua | 22 +++++++++++++++++----- parser.moon | 9 +++++---- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/parser.lua b/parser.lua index e54ad6b..f856c88 100644 --- a/parser.lua +++ b/parser.lua @@ -1,9 +1,8 @@ local lpeg = require('lpeg') local re = require('re') lpeg.setmaxstack(10000) -local P, R, V, S, Cg, C, Cp, B, Cmt, Carg -P, R, V, S, Cg, C, Cp, B, Cmt, Carg = lpeg.P, lpeg.R, lpeg.V, lpeg.S, lpeg.Cg, lpeg.C, lpeg.Cp, lpeg.B, lpeg.Cmt, lpeg.Carg -local utils = require('utils') +local P, R, S, C, Cmt, Carg +P, R, S, C, Cmt, Carg = lpeg.P, lpeg.R, lpeg.S, lpeg.C, lpeg.Cmt, lpeg.Carg local match, sub do local _obj_0 = string @@ -66,7 +65,11 @@ do if seen_errors[start_pos] then return true end - if utils.size(seen_errors) >= 10 then + local num_errors = 0 + for _ in pairs(seen_errors) do + num_errors = num_errors + 1 + end + if num_errors >= 10 then seen_errors[start_pos + 1] = colored.bright(colored.yellow(colored.onred("Too many errors, canceling parsing..."))) return #src + 1 end @@ -164,7 +167,16 @@ Parser.parse = function(nomsu_code, source) tree = nil end if next(userdata.errors) then - local keys = utils.keys(userdata.errors) + local keys + do + local _accum_0 = { } + local _len_0 = 1 + for k, v in pairs(userdata.errors) do + _accum_0[_len_0] = k + _len_0 = _len_0 + 1 + end + keys = _accum_0 + end table.sort(keys) local errors do diff --git a/parser.moon b/parser.moon index e7ee809..d8bd834 100644 --- a/parser.moon +++ b/parser.moon @@ -2,8 +2,7 @@ lpeg = require 'lpeg' re = require 're' lpeg.setmaxstack 10000 -{:P,:R,:V,:S,:Cg,:C,:Cp,:B,:Cmt,:Carg} = lpeg -utils = require 'utils' +{:P,:R,:S,:C,:Cmt,:Carg} = lpeg {:match, :sub} = string {:NomsuCode, :LuaCode, :Source} = require "code_obj" AST = require "nomsu_tree" @@ -51,7 +50,9 @@ NOMSU_DEFS = with {} seen_errors = userdata.errors if seen_errors[start_pos] return true - if utils.size(seen_errors) >= 10 + num_errors = 0 + for _ in pairs(seen_errors) do num_errors += 1 + if num_errors >= 10 seen_errors[start_pos+1] = colored.bright colored.yellow colored.onred "Too many errors, canceling parsing..." return #src+1 err_pos = start_pos @@ -122,7 +123,7 @@ Parser.parse = (nomsu_code, source=nil)-> tree = nil if next(userdata.errors) - keys = utils.keys(userdata.errors) + keys = [k for k,v in pairs(userdata.errors)] table.sort(keys) errors = [userdata.errors[k] for k in *keys] error("Errors occurred while parsing:\n\n"..table.concat(errors, "\n\n"), 0)