diff options
-rw-r--r-- | script/core/generic.lua | 6 | ||||
-rw-r--r-- | script/core/linker.lua | 90 | ||||
-rw-r--r-- | script/core/searcher.lua | 5 | ||||
-rw-r--r-- | test/references/init.lua | 2 |
4 files changed, 48 insertions, 55 deletions
diff --git a/script/core/generic.lua b/script/core/generic.lua index 214a8938..16840b9c 100644 --- a/script/core/generic.lua +++ b/script/core/generic.lua @@ -96,7 +96,7 @@ local function createValue(closure, proto, callback, road) end if proto.type == 'doc.type.array' then if road then - road[#road+1] = linker.SPLIT_CHAR + road[#road+1] = linker.ANY_FIELD end local node = createValue(closure, proto.node, callback, road) if road then @@ -110,11 +110,11 @@ local function createValue(closure, proto, callback, road) return value end if proto.type == 'doc.type.table' then - road[#road+1] = linker.SPLIT_CHAR .. linker.TABLE_KEY_CHAR + road[#road+1] = linker.TABLE_KEY local tkey = createValue(closure, proto.tkey, callback, road) road[#road] = nil - road[#road+1] = linker.SPLIT_CHAR + road[#road+1] = linker.ANY_FIELD local tvalue = createValue(closure, proto.tvalue, callback, road) road[#road] = nil diff --git a/script/core/linker.lua b/script/core/linker.lua index 079c2aa4..1bd47d3c 100644 --- a/script/core/linker.lua +++ b/script/core/linker.lua @@ -2,14 +2,16 @@ local util = require 'utility' local guide = require 'parser.guide' local Linkers -local LastIDCache = {} -local FirstIDCache = {} -local SPLIT_CHAR = '\x1F' -local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$' -local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*' -local RETURN_INDEX_CHAR = '#' -local PARAM_INDEX_CHAR = '@' -local TABLE_KEY_CHAR = '<' +local LastIDCache = {} +local FirstIDCache = {} +local SPLIT_CHAR = '\x1F' +local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$' +local FIRST_REGEX = '^[^' .. SPLIT_CHAR .. ']*' +local ANY_FIELD_CHAR = '*' +local RETURN_INDEX = SPLIT_CHAR .. '#' +local PARAM_INDEX = SPLIT_CHAR .. '@' +local TABLE_KEY = SPLIT_CHAR .. '<' +local ANY_FIELD = SPLIT_CHAR .. ANY_FIELD_CHAR ---创建source的链接信息 ---@param id string @@ -67,22 +69,22 @@ local function getKey(source) or source.type == 'getindex' then local index = source.index if not index then - return '', source.node + return ANY_FIELD_CHAR, source.node end if index.type == 'string' then return ('%q'):format(index[1] or ''), source.node else - return '', source.node + return ANY_FIELD_CHAR, source.node end elseif source.type == 'tableindex' then local index = source.index if not index then - return '', source.parent + return ANY_FIELD_CHAR, source.parent end if index.type == 'string' then return ('%q'):format(index[1] or ''), source.parent else - return '', source.parent + return ANY_FIELD_CHAR, source.parent end elseif source.type == 'table' then return source.start, nil @@ -105,7 +107,7 @@ local function getKey(source) elseif source.type == '...' then return source.start, nil elseif source.type == 'select' then - return ('%d%s%s%d'):format(source.start, SPLIT_CHAR, RETURN_INDEX_CHAR, source.index) + return ('%d%s%d'):format(source.start, RETURN_INDEX, source.index) elseif source.type == 'call' then local node = source.node if node.special == 'rawget' @@ -338,10 +340,11 @@ end local m = {} -m.SPLIT_CHAR = SPLIT_CHAR -m.RETURN_INDEX_CHAR = RETURN_INDEX_CHAR -m.PARAM_INDEX_CHAR = PARAM_INDEX_CHAR -m.TABLE_KEY_CHAR = TABLE_KEY_CHAR +m.SPLIT_CHAR = SPLIT_CHAR +m.RETURN_INDEX = RETURN_INDEX +m.PARAM_INDEX = PARAM_INDEX +m.TABLE_KEY = TABLE_KEY +m.ANY_FIELD = ANY_FIELD ---添加关联单元 ---@param source parser.guide.object @@ -461,10 +464,9 @@ function m.compileLink(source) end getLink(id).call = source -- 将 call 映射到 node#1 上 - local callID = ('%s%s%s%s'):format( + local callID = ('%s%s%s'):format( nodeID, - SPLIT_CHAR, - RETURN_INDEX_CHAR, + RETURN_INDEX, 1 ) pushForward(id, callID) @@ -497,10 +499,9 @@ function m.compileLink(source) return end -- 将call的返回值接收映射到函数返回值上 - local callXID = ('%s%s%s%s'):format( + local callXID = ('%s%s%s'):format( nodeID, - SPLIT_CHAR, - RETURN_INDEX_CHAR, + RETURN_INDEX, source.index ) pushForward(id, callXID) @@ -516,10 +517,9 @@ function m.compileLink(source) if not funcID then return end - local funcXID = ('%s%s%s%s'):format( + local funcXID = ('%s%s%s'):format( funcID, - SPLIT_CHAR, - RETURN_INDEX_CHAR, + RETURN_INDEX, index ) pushForward(id, funcXID) @@ -530,10 +530,9 @@ function m.compileLink(source) if source.type == 'doc.type.function' then if source.returns then for index, rtn in ipairs(source.returns) do - local returnID = ('%s%s%s%s'):format( + local returnID = ('%s%s%s'):format( id, - SPLIT_CHAR, - RETURN_INDEX_CHAR, + RETURN_INDEX, index ) pushForward(returnID, getID(rtn)) @@ -542,17 +541,16 @@ function m.compileLink(source) end if source.type == 'doc.type.table' then if source.tkey then - local keyID = ('%s%s%s'):format( + local keyID = ('%s%s'):format( id, - SPLIT_CHAR, - TABLE_KEY_CHAR + TABLE_KEY ) pushForward(keyID, getID(source.tkey)) end if source.tvalue then local valueID = ('%s%s'):format( id, - SPLIT_CHAR + ANY_FIELD ) pushForward(valueID, getID(source.tvalue)) end @@ -561,7 +559,7 @@ function m.compileLink(source) if source.node then local nodeID = ('%s%s'):format( id, - SPLIT_CHAR + ANY_FIELD ) pushForward(nodeID, getID(source.node)) end @@ -580,10 +578,9 @@ function m.compileLink(source) end end for index, rtnObjs in ipairs(returns) do - local returnID = ('%s%s%s%s'):format( + local returnID = ('%s%s%s'):format( id, - SPLIT_CHAR, - RETURN_INDEX_CHAR, + RETURN_INDEX, index ) for _, rtnObj in ipairs(rtnObjs) do @@ -600,10 +597,9 @@ function m.compileLink(source) for _, doc in ipairs(source.bindDocs) do if doc.type == 'doc.return' then for _, rtn in ipairs(doc.returns) do - local fullID = ('%s%s%s%s'):format( + local fullID = ('%s%s%s'):format( id, - SPLIT_CHAR, - RETURN_INDEX_CHAR, + RETURN_INDEX, rtn.returnIndex ) pushForward(fullID, getID(rtn)) @@ -636,10 +632,9 @@ function m.compileLink(source) end if source.type == 'generic.closure' then for i, rtn in ipairs(source.returns) do - local closureID = ('%s%s%s%s'):format( + local closureID = ('%s%s%s'):format( id, - SPLIT_CHAR, - RETURN_INDEX_CHAR, + RETURN_INDEX, i ) local returnID = getID(rtn) @@ -669,23 +664,22 @@ function m.compileLink(source) if proto.type == 'doc.type.array' then local nodeID = ('%s%s'):format( id, - SPLIT_CHAR + ANY_FIELD ) pushForward(nodeID, getID(source.node)) end if proto.type == 'doc.type.table' then if source.tkey then - local keyID = ('%s%s%s'):format( + local keyID = ('%s%s'):format( id, - SPLIT_CHAR, - TABLE_KEY_CHAR + TABLE_KEY ) pushForward(keyID, getID(source.tkey)) end if source.tvalue then local valueID = ('%s%s'):format( id, - SPLIT_CHAR + ANY_FIELD ) pushForward(valueID, getID(source.tvalue)) end diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 97e1a7b8..10a6a537 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -242,15 +242,14 @@ function m.searchRefsByID(status, uri, expect, mode) if not parentID then return end - search(parentID, linker.SPLIT_CHAR .. linker.RETURN_INDEX_CHAR .. returnIndex) + search(parentID, linker.RETURN_INDEX .. returnIndex) end local function isCallID(field) if not field then return false end - if field:sub(1, 1) == linker.SPLIT_CHAR - and field:sub(2, 2) == linker.RETURN_INDEX_CHAR then + if field:sub(1, 2) == linker.RETURN_INDEX then return true end return false diff --git a/test/references/init.lua b/test/references/init.lua index f6785984..9ac96464 100644 --- a/test/references/init.lua +++ b/test/references/init.lua @@ -176,7 +176,7 @@ local y = f()() TEST [[ local t = {} t.<?x?> = 1 -t[a.b.x] = 1 +t[a.b.c] = 1 ]] TEST [[ |