From 60fd4db0e553208b5a7b68e167517424f4dea3c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 25 Jan 2019 16:43:09 +0800 Subject: =?UTF-8?q?=E6=9B=B4=E6=96=B0=E8=AF=AD=E6=B3=95=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/src/parser/ast.lua | 33 ++++++++++++++++++++------------- 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 -- cgit v1.2.3