diff options
Diffstat (limited to 'server-beta/src/parser')
-rw-r--r-- | server-beta/src/parser/ast.lua | 25 | ||||
-rw-r--r-- | server-beta/src/parser/guide.lua | 3 | ||||
-rw-r--r-- | server-beta/src/parser/parse.lua | 8 |
3 files changed, 36 insertions, 0 deletions
diff --git a/server-beta/src/parser/ast.lua b/server-beta/src/parser/ast.lua index 04148da0..953cac67 100644 --- a/server-beta/src/parser/ast.lua +++ b/server-beta/src/parser/ast.lua @@ -13,6 +13,7 @@ _ENV = nil local State local PushError +local PushDiag -- goto 单独处理 local RESERVED = { @@ -1025,6 +1026,17 @@ local Defs = { key.range = key.value.finish end end + if values then + for i = #keys+1, #values do + local value = values[i] + PushDiag('redundant-value', { + start = value.start, + finish = value.finish, + max = #keys, + passed = #values, + }) + end + end return tableUnpack(keys) end, LocalAttr = function (attrs) @@ -1079,6 +1091,17 @@ local Defs = { local value = getValue(values, i) createLocal(key, finish, value, attrs) end + if values then + for i = #keys+1, #values do + local value = values[i] + PushDiag('redundant-value', { + start = value.start, + finish = value.finish, + max = #keys, + passed = #values, + }) + end + end return tableUnpack(keys) end, Do = function (start, actions, finish) @@ -1619,12 +1642,14 @@ local Defs = { local function init(state) State = state PushError = state.pushError + PushDiag = state.pushDiag emmy.init(State) end local function close() State = nil PushError = nil + PushDiag = nil end return { diff --git a/server-beta/src/parser/guide.lua b/server-beta/src/parser/guide.lua index 952fa3c6..f4fd387c 100644 --- a/server-beta/src/parser/guide.lua +++ b/server-beta/src/parser/guide.lua @@ -320,6 +320,9 @@ function m.eachSourceType(ast, type, callback) end mark[source] = true local tp = source.type + if not tp then + return + end local myCache = cache[tp] if not myCache then myCache = {} diff --git a/server-beta/src/parser/parse.lua b/server-beta/src/parser/parse.lua index 0fd64e80..bbc01b10 100644 --- a/server-beta/src/parser/parse.lua +++ b/server-beta/src/parser/parse.lua @@ -2,12 +2,14 @@ local ast = require 'parser.ast' return function (self, lua, mode, version) local errs = {} + local diags = {} local state = { version = version, lua = lua, emmy = {}, root = {}, errs = errs, + diags = diags, pushError = function (err) if err.finish < err.start then err.finish = err.start @@ -22,6 +24,12 @@ return function (self, lua, mode, version) errs[#errs+1] = err return err end, + pushDiag = function (code, info) + if not diags[code] then + diags[code] = {} + end + diags[code][#diags[code]+1] = info + end } ast.init(state) local suc, res, err = xpcall(self.grammar, debug.traceback, self, lua, mode) |