summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2021-09-23 19:17:13 +0800
committer最萌小汐 <sumneko@hotmail.com>2021-09-23 19:17:13 +0800
commit127f0c549bb46d218e4b81db6c4ffd40394927ae (patch)
tree055331938bc317493e5b724f6ff07d3f08f941ce
parent48fe9fdd2071da918d3c7f0011f0e8c56b865b9f (diff)
downloadlua-language-server-127f0c549bb46d218e4b81db6c4ffd40394927ae.zip
update parser
-rw-r--r--script/parser/newparser.lua43
1 files changed, 30 insertions, 13 deletions
diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua
index 957d98e8..e4210d0f 100644
--- a/script/parser/newparser.lua
+++ b/script/parser/newparser.lua
@@ -192,7 +192,6 @@ local ChunkFinishMap = {
['else'] = true,
['elseif'] = true,
['in'] = true,
- ['do'] = true,
['then'] = true,
['until'] = true,
[';'] = true,
@@ -201,6 +200,22 @@ local ChunkFinishMap = {
['}'] = true,
}
+local ListFinishMap = {
+ ['end'] = true,
+ ['else'] = true,
+ ['elseif'] = true,
+ ['in'] = true,
+ ['then'] = true,
+ ['do'] = true,
+ ['until'] = true,
+ ['for'] = true,
+ ['if'] = true,
+ ['local'] = true,
+ ['repeat'] = true,
+ ['return'] = true,
+ ['while'] = true,
+}
+
local State, Lua, Line, LineOffset, Chunk, Tokens, Index, LastTokenFinish, Mode, LocalCount
local LocalLimit = 200
@@ -1367,7 +1382,7 @@ local function parseExpList(mini)
if not token then
break
end
- if ChunkFinishMap[token] then
+ if ListFinishMap[token] then
break
end
if token == ',' then
@@ -1395,7 +1410,8 @@ local function parseExpList(mini)
and nextToken ~= 'function'
and nextToken ~= 'true'
and nextToken ~= 'false'
- and nextToken ~= 'nil' then
+ and nextToken ~= 'nil'
+ and nextToken ~= 'not' then
break
end
end
@@ -1820,7 +1836,9 @@ local function parseVarargs()
break
end
end
- if not varargs.node and Mode == 'Lua' then
+ if not varargs.node
+ and Mode == 'Lua'
+ and Chunk[#Chunk].type ~= 'main' then
pushError {
type = 'UNEXPECT_DOTS',
start = varargs.start,
@@ -1931,8 +1949,7 @@ local function isChunkFinishToken(token)
if tp == 'for'
or tp == 'in'
or tp == 'loop' then
- return token == 'do'
- or token == 'end'
+ return token == 'end'
end
if tp == 'if'
or tp == 'ifblock'
@@ -1943,7 +1960,7 @@ local function isChunkFinishToken(token)
or token == 'else'
or token == 'elseif'
end
- return token ~= 'do'
+ return true
end
local function parseActions()
@@ -2226,16 +2243,13 @@ local function parseExpUnit()
return nil
end
-local function parseUnaryOP(level)
+local function parseUnaryOP()
local token = Tokens[Index + 1]
local symbol = UnarySymbol[token] and token or UnaryAlias[token]
if not symbol then
return nil
end
local myLevel = UnarySymbol[symbol]
- if level and myLevel < level then
- return nil
- end
local op = {
type = symbol,
start = getPosition(Tokens[Index], 'left'),
@@ -2324,7 +2338,7 @@ end
function parseExp(asAction, level)
local exp
- local uop, uopLevel = parseUnaryOP(level)
+ local uop, uopLevel = parseUnaryOP()
if uop then
skipSpace()
local child = parseExp(asAction, uopLevel)
@@ -3249,7 +3263,10 @@ local function parseWhile()
Index = Index + 2
skipSpace()
- local filter = parseExp()
+ local nextToken = Tokens[Index + 1]
+ local filter = nextToken ~= 'do'
+ and nextToken ~= 'then'
+ and parseExp()
if filter then
action.filter = filter
action.finish = filter.finish