From 742544183f0b20856eef6a8a3c0302f3fa12ec0a 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, 20 Nov 2018 14:11:15 +0800 Subject: =?UTF-8?q?=E8=BD=AC=E5=88=B0=E5=AE=9E=E7=8E=B0=E6=94=AF=E6=8C=81?= =?UTF-8?q?=E7=8C=9C=E6=B5=8B=E9=80=BB=E8=BE=91=E5=88=86=E6=94=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/matcher/implementation.lua | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'src') diff --git a/src/matcher/implementation.lua b/src/matcher/implementation.lua index 3e823d5b..4431d2ed 100644 --- a/src/matcher/implementation.lua +++ b/src/matcher/implementation.lua @@ -6,6 +6,7 @@ local scopes local result local namePos local colonPos +local maybeCount local DUMMY_TABLE = {} @@ -24,6 +25,14 @@ local function logicGet() return scope and scope.logicId end +local function maybePush() + maybeCount = maybeCount + 1 +end + +local function maybePop() + maybeCount = maybeCount - 1 +end + local function scopeInit() scopes = {{}} end @@ -61,6 +70,7 @@ end local function globalSet(obj) obj.logicId = logicGet() obj.scopeId = #scopes + obj.maybeId = maybeCount local name = obj[1] for i = #scopes, 1, -1 do local scope = scopes[i] @@ -97,6 +107,9 @@ local function checkImplementation(name, p) goto CONTINUE end result[#result+1] = {start, finish} + if obj.maybeId and obj.maybeId > maybeCount then + goto CONTINUE + end do break end ::CONTINUE:: end @@ -232,6 +245,7 @@ end function defs.IfDef() logicPush() + maybePush() scopePush() end @@ -259,15 +273,18 @@ end function defs.EndIf() logicFlush() + maybePop() end function defs.LoopDef(name) + maybePush() scopePush() scopeSet(name) end function defs.Loop() scopePop() + maybePop() end function defs.LoopStart(name, exp) @@ -283,6 +300,7 @@ function defs.SimpleList(...) end function defs.InDef(names) + maybePush() scopePush() for _, name in ipairs(names) do scopeSet(name) @@ -291,27 +309,33 @@ end function defs.In() scopePop() + maybePop() end function defs.WhileDef() + maybePush() scopePush() end function defs.While() scopePop() + maybePop() end function defs.RepeatDef() + maybePush() scopePush() end function defs.Until() scopePop() + maybePop() end return function (buf, pos_) pos = pos_ result = nil + maybeCount = 0 scopeInit() local suc, err = parser.grammar(buf, 'Lua', defs) -- cgit v1.2.3