diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-01-07 17:54:12 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-01-07 17:54:12 +0800 |
commit | 66efb393005836da8d94b2aeef9ab7204915b493 (patch) | |
tree | 88431eb0a327cd4e1ef9d6e9f3318712579ae4a6 | |
parent | 6194e11b4153a4fba16a5ba15876581b8d3cde43 (diff) | |
download | lua-language-server-66efb393005836da8d94b2aeef9ab7204915b493.zip |
update semantic-tokens
-rw-r--r-- | script/core/semantic-tokens.lua | 63 | ||||
-rw-r--r-- | script/parser/newparser.lua | 50 |
2 files changed, 107 insertions, 6 deletions
diff --git a/script/core/semantic-tokens.lua b/script/core/semantic-tokens.lua index 40e7af18..da3396ce 100644 --- a/script/core/semantic-tokens.lua +++ b/script/core/semantic-tokens.lua @@ -205,7 +205,7 @@ local Care = util.switch() start = source.start, finish = source.finish, type = define.TokenTypes.variable, - modifieres = define.TokenModifiers.static, + modifieres = define.TokenModifiers.readonly, } return elseif name == 'close' then @@ -277,6 +277,67 @@ local Care = util.switch() type = define.TokenTypes.keyword, } end) + : case 'binary' + : case 'unary' + : call(function (source, options, results) + results[#results+1] = { + start = source.op.start, + finish = source.op.finish, + type = define.TokenTypes.operator, + } + end) + : case 'boolean' + : case 'nil' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.variable, + modifieres = define.TokenModifiers.readonly, + } + end) + : case 'string' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.string, + } + local escs = source.escs + if escs then + for i = 1, #escs, 3 do + local mod + if escs[i + 2] == 'err' then + mod = define.TokenModifiers.deprecated + else + mod = define.TokenModifiers.modification + end + results[#results+1] = { + start = escs[i], + finish = escs[i + 1], + type = define.TokenTypes.string, + modifieres = mod, + } + end + end + end) + : case 'integer' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.number, + modifieres = define.TokenModifiers.static, + } + end) + : case 'number' + : call(function (source, options, results) + results[#results+1] = { + start = source.start, + finish = source.finish, + type = define.TokenTypes.number, + } + end) : case 'doc.return.name' : call(function (source, options, results) results[#results+1] = { diff --git a/script/parser/newparser.lua b/script/parser/newparser.lua index b7868646..33187ee2 100644 --- a/script/parser/newparser.lua +++ b/script/parser/newparser.lua @@ -926,6 +926,7 @@ local function parseShortString() Index = Index + 2 local stringIndex = 0 local currentOffset = startOffset + 1 + local escs = {} while true do local token = Tokens[Index + 1] if token == mark then @@ -954,13 +955,18 @@ local function parseShortString() if not Tokens[Index] then goto CONTINUE end + local escLeft = getPosition(currentOffset, 'left') -- has space? if Tokens[Index] - currentOffset > 1 then + local right = getPosition(currentOffset + 1, 'right') pushError { type = 'ERR_ESC', - start = getPosition(currentOffset, 'left'), - finish = getPosition(currentOffset + 1, 'right'), + start = escLeft, + finish = right, } + escs[#escs+1] = escLeft + escs[#escs+1] = right + escs[#escs+1] = 'err' goto CONTINUE end local nextToken = ssub(Tokens[Index + 1], 1, 1) @@ -969,6 +975,9 @@ local function parseShortString() stringPool[stringIndex] = EscMap[nextToken] currentOffset = Tokens[Index] + #nextToken Index = Index + 2 + escs[#escs+1] = escLeft + escs[#escs+1] = escLeft + 2 + escs[#escs+1] = 'normal' goto CONTINUE end if nextToken == mark then @@ -976,12 +985,18 @@ local function parseShortString() stringPool[stringIndex] = mark currentOffset = Tokens[Index] + #nextToken Index = Index + 2 + escs[#escs+1] = escLeft + escs[#escs+1] = escLeft + 2 + escs[#escs+1] = 'normal' goto CONTINUE end if nextToken == 'z' then Index = Index + 2 repeat until not skipNL() currentOffset = Tokens[Index] + escs[#escs+1] = escLeft + escs[#escs+1] = escLeft + 2 + escs[#escs+1] = 'normal' goto CONTINUE end if CharMapNumber[nextToken] then @@ -991,13 +1006,21 @@ local function parseShortString() end currentOffset = Tokens[Index] + #numbers fastForwardToken(currentOffset) + local right = getPosition(currentOffset - 1, 'right') local byte = tointeger(numbers) if byte <= 255 then stringIndex = stringIndex + 1 stringPool[stringIndex] = schar(byte) else - -- TODO pushError + pushError { + type = 'ERR_ESC', + start = escLeft, + finish = right, + } end + escs[#escs+1] = escLeft + escs[#escs+1] = right + escs[#escs+1] = 'byte' goto CONTINUE end if nextToken == 'x' then @@ -1016,6 +1039,10 @@ local function parseShortString() finish = getPosition(currentOffset + 1, 'right'), } end + local right = getPosition(currentOffset + 1, 'right') + escs[#escs+1] = escLeft + escs[#escs+1] = right + escs[#escs+1] = 'byte' if State.version == 'Lua 5.1' then pushError { type = 'ERR_ESC', @@ -1038,6 +1065,10 @@ local function parseShortString() end currentOffset = newOffset fastForwardToken(currentOffset - 1) + local right = getPosition(currentOffset + 1, 'right') + escs[#escs+1] = escLeft + escs[#escs+1] = right + escs[#escs+1] = 'unicode' goto CONTINUE end if NLMap[nextToken] then @@ -1045,13 +1076,21 @@ local function parseShortString() stringPool[stringIndex] = '\n' currentOffset = Tokens[Index] + #nextToken skipNL() + local right = getPosition(currentOffset + 1, 'right') + escs[#escs+1] = escLeft + escs[#escs+1] = right + escs[#escs+1] = 'normal' goto CONTINUE end + local right = getPosition(currentOffset + 1, 'right') pushError { type = 'ERR_ESC', - start = getPosition(currentOffset, 'left'), - finish = getPosition(currentOffset + 1, 'right'), + start = escLeft, + finish = right, } + escs[#escs+1] = escLeft + escs[#escs+1] = right + escs[#escs+1] = 'err' end Index = Index + 2 ::CONTINUE:: @@ -1061,6 +1100,7 @@ local function parseShortString() type = 'string', start = startPos, finish = lastRightPosition(), + escs = #escs > 0 and escs or nil, [1] = stringResult, [2] = mark, } |