diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-09-06 17:23:15 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-09-06 17:23:15 +0800 |
commit | b54172d818b88c41cfdc2c88f00e9caec1dea202 (patch) | |
tree | 7ccedfbe139f958e977e991d187a615099a42524 /script/parser/compile.lua | |
parent | 7047393031801c91c8d0cf78a77c91e5a6f64114 (diff) | |
download | lua-language-server-b54172d818b88c41cfdc2c88f00e9caec1dea202.zip |
fix #1526
Diffstat (limited to 'script/parser/compile.lua')
-rw-r--r-- | script/parser/compile.lua | 109 |
1 files changed, 44 insertions, 65 deletions
diff --git a/script/parser/compile.lua b/script/parser/compile.lua index 33ac4d69..9724a74f 100644 --- a/script/parser/compile.lua +++ b/script/parser/compile.lua @@ -1444,68 +1444,6 @@ local function parseNameOrList(parent) return list or first end -local function dropTail() - local token = Tokens[Index + 1] - if token ~= '?' - and token ~= ':' then - return - end - local pl, pt, pp = 0, 0, 0 - while true do - local token = Tokens[Index + 1] - if not token then - break - end - if NLMap[token] then - break - end - if token == ',' then - if pl > 0 - or pt > 0 - or pp > 0 then - goto CONTINUE - else - break - end - end - if token == '<' then - pl = pl + 1 - goto CONTINUE - end - if token == '{' then - pt = pt + 1 - goto CONTINUE - end - if token == '(' then - pp = pp + 1 - goto CONTINUE - end - if token == '>' then - if pl <= 0 then - break - end - pl = pl - 1 - goto CONTINUE - end - if token == '}' then - if pt <= 0 then - break - end - pt = pt - 1 - goto CONTINUE - end - if token == ')' then - if pp <= 0 then - break - end - pp = pp - 1 - goto CONTINUE - end - ::CONTINUE:: - Index = Index + 2 - end -end - local function parseExpList(mini) local list local wantSep = false @@ -1552,7 +1490,6 @@ local function parseExpList(mini) if not exp then break end - dropTail() if wantSep then missSymbol(',', list[#list].finish, exp.start) end @@ -2379,6 +2316,27 @@ local function parseFunction(isLocal, isAction) return func end +local function pushErrorNeedParen(source) + pushError { + type = 'NEED_PAREN', + start = source.start, + finish = source.finish, + fix = { + title = 'FIX_ADD_PAREN', + { + start = source.start, + finish = source.start, + text = '(', + }, + { + start = source.finish, + finish = source.finish, + text = ')', + } + } + } +end + local function parseExpUnit() local token = Tokens[Index + 1] if token == '(' then @@ -2393,17 +2351,38 @@ local function parseExpUnit() if token == '{' then local table = parseTable() + if not table then + return nil + end + local exp = parseSimple(table, false) + if exp ~= table then + pushErrorNeedParen(table) + end return table end if CharMapStrSH[token] then local string = parseShortString() - return string + if not string then + return nil + end + local exp = parseSimple(string, false) + if exp ~= string then + pushErrorNeedParen(string) + end + return exp end if CharMapStrLH[token] then local string = parseLongString() - return string + if not string then + return nil + end + local exp = parseSimple(string, false) + if exp ~= string then + pushErrorNeedParen(string) + end + return exp end local number = parseNumber() |