Skip to content

Commit 45a52fd

Browse files
committed
update parser
don't match `local if`, this can lead to unbalanced `end` counts
1 parent d459315 commit 45a52fd

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

Diff for: script/parser/newparser.lua

+23-5
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,21 @@ local ChunkFinishMap = {
200200
['}'] = true,
201201
}
202202

203+
local ChunkStartMap = {
204+
['do'] = true,
205+
['else'] = true,
206+
['elseif'] = true,
207+
['for'] = true,
208+
['function'] = true,
209+
['if'] = true,
210+
['local'] = true,
211+
['repeat'] = true,
212+
['return'] = true,
213+
['then'] = true,
214+
['until'] = true,
215+
['while'] = true,
216+
}
217+
203218
local ListFinishMap = {
204219
['end'] = true,
205220
['else'] = true,
@@ -1354,14 +1369,17 @@ local function isKeyWord(word)
13541369
return false
13551370
end
13561371

1357-
local function parseName()
1372+
local function parseName(asAction)
13581373
local word = peekWord()
13591374
if not word then
13601375
return nil
13611376
end
13621377
if ChunkFinishMap[word] then
13631378
return nil
13641379
end
1380+
if asAction and ChunkStartMap[word] then
1381+
return nil
1382+
end
13651383
local startPos = getPosition(Tokens[Index], 'left')
13661384
local finishPos = getPosition(Tokens[Index] + #word - 1, 'right')
13671385
Index = Index + 2
@@ -1400,7 +1418,7 @@ local function parseNameOrList()
14001418
end
14011419
Index = Index + 2
14021420
skipSpace()
1403-
local name = parseName()
1421+
local name = parseName(true)
14041422
if not name then
14051423
missName()
14061424
break
@@ -1760,7 +1778,7 @@ local function parseSimple(node, funcName)
17601778
}
17611779
Index = Index + 2
17621780
skipSpace()
1763-
local field = parseName()
1781+
local field = parseName(true)
17641782
local getfield = {
17651783
type = 'getfield',
17661784
start = node.start,
@@ -1790,7 +1808,7 @@ local function parseSimple(node, funcName)
17901808
}
17911809
Index = Index + 2
17921810
skipSpace()
1793-
local method = parseName()
1811+
local method = parseName(true)
17941812
local getmethod = {
17951813
type = 'getmethod',
17961814
start = node.start,
@@ -2864,7 +2882,7 @@ local function parseLocal()
28642882
end
28652883
end
28662884

2867-
local name = parseName()
2885+
local name = parseName(true)
28682886
if not name then
28692887
missName()
28702888
return nil

0 commit comments

Comments
 (0)