From b45a90132438bb2d84b7376066e5ff409833a13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 18 Sep 2021 17:28:21 +0800 Subject: update --- script/parser/guide.lua | 2 +- script/parser/newparser.lua | 41 +++++++++++++++++++++++------------------ 2 files changed, 24 insertions(+), 19 deletions(-) (limited to 'script/parser') diff --git a/script/parser/guide.lua b/script/parser/guide.lua index af623753..4a0ca21f 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -781,7 +781,7 @@ function m.offsetToPosition(state, offset) end break end - local start = lines[row] + local start = lines[row] - 1 if start > offset then right = row else diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index e0144dcd..99518261 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -207,21 +207,7 @@ local LocalLimit = 200 local parseExp, parseAction -local function pushError(err) - local errs = State.errs - if err.finish < err.start then - err.finish = err.start - end - local last = errs[#errs] - if last then - if last.start <= err.start and last.finish >= err.finish then - return - end - end - err.level = err.level or 'error' - errs[#errs+1] = err - return err -end +local pushError local function addSpecial(name, obj) local root = State.ast @@ -3537,7 +3523,7 @@ local function initState(lua, version, options) Chunk = {} Tokens = tokens(lua) Index = 1 - State = { + local state = { version = version, lua = lua, ast = {}, @@ -3549,11 +3535,30 @@ local function initState(lua, version, options) }, options = options or {}, } + State = state if version == 'Lua 5.1' or version == 'LuaJIT' then - State.ENVMode = '@fenv' + state.ENVMode = '@fenv' else - State.ENVMode = '_ENV' + state.ENVMode = '_ENV' end + + pushError = function (err) + local errs = state.errs + if err.finish < err.start then + err.finish = err.start + end + local last = errs[#errs] + if last then + if last.start <= err.start and last.finish >= err.finish then + return + end + end + err.level = err.level or 'error' + errs[#errs+1] = err + return err + end + + state.pushError = pushError end return function (lua, mode, version, options) -- cgit v1.2.3