diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2019-01-25 16:43:09 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2019-01-25 16:43:09 +0800 |
commit | 60fd4db0e553208b5a7b68e167517424f4dea3c4 (patch) | |
tree | 48df54f95444057087290801d7d78eb49b520995 | |
parent | 1df57357aece99476057b7a904930e7d26335f2c (diff) | |
download | lua-language-server-60fd4db0e553208b5a7b68e167517424f4dea3c4.zip |
更新语法解析
-rw-r--r-- | server/src/parser/ast.lua | 33 | ||||
-rw-r--r-- | server/src/parser/grammar.lua | 10 |
2 files changed, 25 insertions, 18 deletions
diff --git a/server/src/parser/ast.lua b/server/src/parser/ast.lua index 48d9eb3b..645d10e9 100644 --- a/server/src/parser/ast.lua +++ b/server/src/parser/ast.lua @@ -729,17 +729,24 @@ local Defs = { BreakEnd = function () State.Break = State.Break - 1 end, - Return = function (exp) - if exp == nil or exp == '' then + Return = function (start, exp, finish) + if not finish then + finish = exp exp = { - type = 'return' + type = 'return', + start = start, + finish = finish - 1, } else if exp.type == 'list' then exp.type = 'return' + exp.start = start + exp.finish = finish - 1 else exp = { type = 'return', + start = start, + finish = finish - 1, [1] = exp, } end @@ -1166,20 +1173,20 @@ local Defs = { } return exp end, - ActionAfterReturn = function (start, ...) - if not start or start == '' then - return + AfterReturn = function (rtn, ...) + if not ... then + return rtn + end + local action = select(-1, ...) + if not action then + return rtn end - local actions = table.pack(...) - local max = actions.n - local finish = actions[max] - actions[max] = nil pushError { type = 'ACTION_AFTER_RETURN', - start = start, - finish = finish - 1, + start = rtn.start, + finish = rtn.finish, } - return table.unpack(actions) + return rtn, action end, } diff --git a/server/src/parser/grammar.lua b/server/src/parser/grammar.lua index cd6be11d..17ac4faf 100644 --- a/server/src/parser/grammar.lua +++ b/server/src/parser/grammar.lua @@ -401,11 +401,11 @@ Break <- BREAK {} -> Break BreakStart <- {} -> BreakStart BreakEnd <- {} -> BreakEnd -Return <- RETURN MustExpList? - -> Return (Semicolon / ActionAfterReturn)* -ActionAfterReturn - <- (Sp {} (!END !UNTIL !ELSEIF !ELSE Action)+ {}) - -> ActionAfterReturn +Return <- (ReturnBody Semicolon* AfterReturn?) + -> AfterReturn +ReturnBody <- Sp ({} RETURN MustExpList? {}) + -> Return +AfterReturn <- Sp !END !UNTIL !ELSEIF !ELSE Action Label <- LABEL MustName -> Label DirtyLabel |