From 2a29458c86628a2af20da4ebeb39a8f81d4ea53a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 14 Sep 2021 16:59:55 +0800 Subject: update parser --- script/parser/parse.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'script/parser/parse.lua') diff --git a/script/parser/parse.lua b/script/parser/parse.lua index 9b8d5496..e7c7d177 100644 --- a/script/parser/parse.lua +++ b/script/parser/parse.lua @@ -1,6 +1,7 @@ -local ast = require 'parser.ast' +local ast = require 'parser.ast' +local grammar = require 'parser.grammar' -return function (self, lua, mode, version, options) +local function buildState(lua, version, options) local errs = {} local diags = {} local comms = {} @@ -36,9 +37,19 @@ return function (self, lua, mode, version, options) comms[#comms+1] = comment end } + if version == 'Lua 5.1' or version == 'LuaJIT' then + state.ENVMode = '@fenv' + else + state.ENVMode = '_ENV' + end + return state +end + +return function (lua, mode, version, options) + local state = buildState(lua, version, options) local clock = os.clock() ast.init(state) - local suc, res, err = xpcall(self.grammar, debug.traceback, self, lua, mode) + local suc, res, err = xpcall(grammar, debug.traceback, lua, mode) ast.close() if not suc then return nil, res -- cgit v1.2.3