diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2018-11-21 18:30:08 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2018-11-21 18:30:08 +0800 |
commit | 48cdcc1436a81b2890220bae74266d455c6c5dc1 (patch) | |
tree | e6ea106dd114efb65bdb8a9bbbc16ab030d136cc /server/src/matcher | |
parent | b614e7117cc49a4f78913ffae81b82d2b3fa3bae (diff) | |
download | lua-language-server-48cdcc1436a81b2890220bae74266d455c6c5dc1.zip |
支持字面量
Diffstat (limited to 'server/src/matcher')
-rw-r--r-- | server/src/matcher/definition.lua | 70 |
1 files changed, 59 insertions, 11 deletions
diff --git a/server/src/matcher/definition.lua b/server/src/matcher/definition.lua index 09081cdb..a8f99a18 100644 --- a/server/src/matcher/definition.lua +++ b/server/src/matcher/definition.lua @@ -5,6 +5,7 @@ local defs = {} local scopes local result local namePos +local nameFinishPos local colonPos local DUMMY_TABLE = {} @@ -100,8 +101,10 @@ end local function checkName(obj) local name = obj[1] - local p = obj[2] - if pos < p or pos > p + #name then + local start = obj[2] + local str = obj.string or name + local finish = obj[3] or (start + #str) + if pos < start or pos > finish then return end result = { @@ -118,8 +121,10 @@ local function checkSimple(simple) local obj = simple[i] if obj.type == 'name' then local name = obj[1] - local p = obj[2] - if pos >= p and pos <= p + #name then + local start = obj[2] + local str = obj.string or name + local finish = obj[3] or (start + #str) + if pos >= start and pos <= finish then result = { type = 'simple', table = scopeGetSimple(simple, i-1), @@ -135,17 +140,48 @@ function defs.NamePos(p) end function defs.Name(str) - local obj = {str, namePos, type = 'name'} + local obj = {'STRING|' .. str, namePos, string = str, type = 'name'} checkName(obj) return obj end +function defs.TRUE(p) + local obj = {'true', p, type = 'name'} + return obj +end + +function defs.FALSE(p) + local obj = {'false', p, type = 'name'} + return obj +end + +function defs.NumberPos(p) + namePos = p +end + +function defs.Number(str) + local dump = ('%q'):format(tonumber(str)) + local obj = {'NUMBER|' .. dump, namePos, string = str, type = 'name'} + return obj +end + +function defs.String(start, str, finish) + local obj = { + 'STRING|' .. str, + start, + finish-1, + string = str, + type = 'name' + } + return obj +end + function defs.DOTSPos(p) namePos = p end -function defs.DOTS(str) - local obj = {str, namePos, type = 'name'} +function defs.DOTS() + local obj = {'...', namePos, type = 'name'} checkName(obj) return obj end @@ -206,7 +242,13 @@ function defs.FunctionDef(simple, args) if #simple > 0 then local name = simple[#simple] if name.colon then - scopeLocal {'self', name.colon, name.colon, type = 'name'} + scopeLocal { + 'STRING|self', + name.colon, + name.colon, + string = 'self', + type = 'name' + } end end for _, arg in ipairs(args) do @@ -229,7 +271,13 @@ function defs.FunctionLoc(simple, args) if #simple > 0 then local name = simple[#simple] if name.colon then - scopeLocal {'self', name.colon, name.colon, type = 'name'} + scopeLocal { + 'STRING|self', + name.colon, + name.colon, + string = 'self', + type = 'name' + } end end for _, arg in ipairs(args) do @@ -341,12 +389,12 @@ local function parseResult(callback) return end - local name, start, finish = obj[1], obj[2], obj[3] + local str, start, finish = (obj.string or obj[1]), obj[2], obj[3] if not start then return end if not finish then - finish = start + #name - 1 + finish = start + #str - 1 end callback(start, finish) end |