From eb05f7ac0f85d034c20e29f68b12d84fa7436601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 13 Dec 2022 21:00:38 +0800 Subject: stash --- script/parser/compile.lua | 45 ++++++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 17 deletions(-) (limited to 'script/parser/compile.lua') diff --git a/script/parser/compile.lua b/script/parser/compile.lua index b8040382..73aef048 100644 --- a/script/parser/compile.lua +++ b/script/parser/compile.lua @@ -3136,6 +3136,22 @@ local function parseGoTo() return action end +local function parseFilter() + local exp = parseExp() + if exp then + local filter = { + type = 'filter', + start = exp.start, + finish = exp.finish, + exp = exp, + } + exp.parent = filter + return filter + else + missExp() + end +end + local function parseIfBlock(parent) local ifLeft = getPosition(Tokens[Index], 'left') local ifRight = getPosition(Tokens[Index] + 1, 'right') @@ -3151,13 +3167,11 @@ local function parseIfBlock(parent) } } skipSpace() - local filter = parseExp() + local filter = parseFilter() if filter then ifblock.filter = filter ifblock.finish = filter.finish filter.parent = ifblock - else - missExp() end skipSpace() local thenToken = Tokens[Index + 1] @@ -3210,13 +3224,11 @@ local function parseElseIfBlock(parent) } Index = Index + 2 skipSpace() - local filter = parseExp() + local filter = parseFilter() if filter then elseifblock.filter = filter elseifblock.finish = filter.finish filter.parent = elseifblock - else - missExp() end skipSpace() local thenToken = Tokens[Index + 1] @@ -3524,15 +3536,16 @@ local function parseWhile() skipSpace() local nextToken = Tokens[Index + 1] - local filter = nextToken ~= 'do' - and nextToken ~= 'then' - and parseExp() - if filter then - action.filter = filter - action.finish = filter.finish - filter.parent = action - else + if nextToken == 'do' + or nextToken == 'then' then missExp() + else + local filter = parseFilter() + if filter then + action.filter = filter + action.finish = filter.finish + filter.parent = action + end end skipSpace() @@ -3611,12 +3624,10 @@ local function parseRepeat() Index = Index + 2 skipSpace() - local filter = parseExp() + local filter = parseFilter() if filter then action.filter = filter filter.parent = action - else - missExp() end else -- cgit v1.2.3