diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-12-31 11:11:59 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-12-31 11:11:59 +0800 |
commit | bf8399c9057927d6746b47915a7b79c62d1082bd (patch) | |
tree | 08b6258daddc8307e98308128e404d4b9b29bb33 /server/src/parser/ast.lua | |
parent | 0245eb9245d7ff8509822f5b505d542b925b6c7e (diff) | |
download | lua-language-server-bf8399c9057927d6746b47915a7b79c62d1082bd.zip |
更新语法检查
Diffstat (limited to 'server/src/parser/ast.lua')
-rw-r--r-- | server/src/parser/ast.lua | 59 |
1 files changed, 58 insertions, 1 deletions
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index de305ca3..6a26f46b 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -1,9 +1,13 @@ local tonumber = tonumber local string_char = string.char local utf8_char = utf8.char +local type = type local Errs local function pushError(err) + 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 @@ -290,6 +294,59 @@ local defs = { return first end end, + ExpList = function (start, ...) + local args = {...} + local max = #args + local finish = args[max] - 1 + local exps = { + type = 'list', + start = start, + finish = finish, + } + local wantExp = true + for i = 1, max-1 do + local arg = args[i] + local isExp = type(arg) == 'table' + if wantExp and not isExp then + pushError { + type = 'MISS_EXP', + start = start, + finish = arg - 1, + } + elseif not wantExp and isExp then + pushError { + type = 'MISS_SYMBOL', + start = start, + finish = arg.start-1, + info = { + symbol = ',', + } + } + end + if isExp then + exps[#exps+1] = arg + wantExp = false + start = arg.finish + 1 + else + wantExp = true + start = arg + end + end + if wantExp then + pushError { + type = 'MISS_EXP', + start = start, + finish = finish, + } + end + if #exps == 0 then + return nil + elseif #exps == 1 then + return exps[1] + else + return exps + end + end, Nothing = function () return nil end, @@ -577,7 +634,7 @@ local defs = { pushError { type = 'MUST_X16', start = pos, - finish = math.max(pos + #str - 1, pos), + finish = pos + #str - 1, } end, MissAssign = function (pos) |