summaryrefslogtreecommitdiff
path: root/server/src/parser
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2018-12-31 11:11:59 +0800
committer最萌小汐 <sumneko@hotmail.com>2018-12-31 11:11:59 +0800
commitbf8399c9057927d6746b47915a7b79c62d1082bd (patch)
tree08b6258daddc8307e98308128e404d4b9b29bb33 /server/src/parser
parent0245eb9245d7ff8509822f5b505d542b925b6c7e (diff)
downloadlua-language-server-bf8399c9057927d6746b47915a7b79c62d1082bd.zip
更新语法检查
Diffstat (limited to 'server/src/parser')
-rw-r--r--server/src/parser/ast.lua59
-rw-r--r--server/src/parser/grammar.lua12
2 files changed, 64 insertions, 7 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)
diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua
index bee5d8e1..a840a7a0 100644
--- a/server/src/parser/grammar.lua
+++ b/server/src/parser/grammar.lua
@@ -75,6 +75,7 @@ local function errorpos(pos, err)
return {
type = 'UNKNOWN',
start = pos,
+ finish = pos,
err = err,
}
end
@@ -193,7 +194,7 @@ TOCLOSE <- Sp '*toclose'
DirtyAssign <- ASSIGN / {} -> MissAssign
DirtyBR <- BR / {} -> MissBR
DirtyTR <- TR / {} -> MissTR
-DirtyPR <- TR / {} -> MissPR
+DirtyPR <- PR / {} -> MissPR
]]
grammar 'Nil' [[
@@ -288,14 +289,13 @@ Suffix <- DOT MustName
/ Sp ({} Table {}) -> Call
/ Sp ({} String {}) -> Call
/ Sp ({} BL DirtyExp (BR / Sp) {}) -> Index
- / Sp ({} PL ExpList (PR / Sp) {}) -> Call
+ / Sp ({} PL ExpList DirtyPR {}) -> Call
DirtyExp <- Exp
/ {} -> DirtyExp
-ExpList <- (COMMA DirtyExp)+
- -> List
- / (Exp (COMMA DirtyExp)*)?
- -> List
+ExpList <- Sp ({} (!%nl (COMMA {} / Exp))+ {})
+ -> ExpList
+ / %nil
NameList <- (COMMA MustName)+
-> List
/ (Name (COMMA MustName)*)