diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-02-09 13:54:51 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-02-09 13:54:51 +0800 |
commit | 45a52fda6c95c90debbbca48fa0a9b259973d402 (patch) | |
tree | cebe914a5f7dccd956a15cfb5cbe4f7bd2429679 /script | |
parent | d45931530be1a75d22ff675cd6e53535d9842d70 (diff) | |
download | lua-language-server-45a52fda6c95c90debbbca48fa0a9b259973d402.zip |
update parser
don't match `local if`, this can lead to unbalanced `end` counts
Diffstat (limited to 'script')
-rw-r--r-- | script/parser/newparser.lua | 28 |
1 files changed, 23 insertions, 5 deletions
diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index 83bf9e86..e4884212 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -200,6 +200,21 @@ local ChunkFinishMap = { ['}'] = true, } +local ChunkStartMap = { + ['do'] = true, + ['else'] = true, + ['elseif'] = true, + ['for'] = true, + ['function'] = true, + ['if'] = true, + ['local'] = true, + ['repeat'] = true, + ['return'] = true, + ['then'] = true, + ['until'] = true, + ['while'] = true, +} + local ListFinishMap = { ['end'] = true, ['else'] = true, @@ -1354,7 +1369,7 @@ local function isKeyWord(word) return false end -local function parseName() +local function parseName(asAction) local word = peekWord() if not word then return nil @@ -1362,6 +1377,9 @@ local function parseName() if ChunkFinishMap[word] then return nil end + if asAction and ChunkStartMap[word] then + return nil + end local startPos = getPosition(Tokens[Index], 'left') local finishPos = getPosition(Tokens[Index] + #word - 1, 'right') Index = Index + 2 @@ -1400,7 +1418,7 @@ local function parseNameOrList() end Index = Index + 2 skipSpace() - local name = parseName() + local name = parseName(true) if not name then missName() break @@ -1760,7 +1778,7 @@ local function parseSimple(node, funcName) } Index = Index + 2 skipSpace() - local field = parseName() + local field = parseName(true) local getfield = { type = 'getfield', start = node.start, @@ -1790,7 +1808,7 @@ local function parseSimple(node, funcName) } Index = Index + 2 skipSpace() - local method = parseName() + local method = parseName(true) local getmethod = { type = 'getmethod', start = node.start, @@ -2864,7 +2882,7 @@ local function parseLocal() end end - local name = parseName() + local name = parseName(true) if not name then missName() return nil |