diff options
Diffstat (limited to 'script/core')
-rw-r--r-- | script/core/noder.lua | 46 | ||||
-rw-r--r-- | script/core/searcher.lua | 66 |
2 files changed, 68 insertions, 44 deletions
diff --git a/script/core/noder.lua b/script/core/noder.lua index ad593718..15e5428c 100644 --- a/script/core/noder.lua +++ b/script/core/noder.lua @@ -3,9 +3,21 @@ local guide = require 'parser.guide' local collector = require 'core.collector' local files = require 'files' -local tconcat = table.concat -local ssub = string.sub -local sformat = string.format +local tostring = tostring +local error = error +local ipairs = ipairs +local type = type +local next = next +local log = log +local ssub = string.sub +local sformat = string.format +local sgsub = string.gsub +local smatch = string.match +local tracy = tracy + +--require 'tracy'.enable() + +_ENV = nil local SPLIT_CHAR = '\x1F' local LAST_REGEX = SPLIT_CHAR .. '[^' .. SPLIT_CHAR .. ']*$' @@ -628,7 +640,7 @@ local function bindValue(noders, source, id) reject = 'set', }) -- 参数/call禁止反向查找赋值 - local valueType = valueID:match '^(.-:).' + local valueType = smatch(valueID, '^(.-:).') if not valueType then return end @@ -716,7 +728,7 @@ local function compileCallReturn(noders, call, sourceID, returnIndex) if field then return true end - return id:sub(1, 2) ~= 'f:' + return ssub(id, 1, 2) ~= 'f:' end, filterValid = function (id, field) return not field @@ -953,11 +965,11 @@ compileNodeMap = util.switch() : case 'doc.see' : call(function (noders, id, source) local nameID = getID(source.name) - local classID = nameID:gsub('^dsn:', 'dn:') + local classID = sgsub(nameID, '^dsn:', 'dn:') pushForward(noders, nameID, classID) if source.field then local fieldID = getID(source.field) - local fieldClassID = fieldID:gsub('^dsn:', 'dn:') + local fieldClassID = sgsub(fieldID, '^dsn:', 'dn:') pushForward(noders, fieldID, fieldClassID) end end) @@ -1239,7 +1251,7 @@ end ---@param id string ---@return string function m.getFirstID(id) - local firstID, count = id:match(FIRST_REGEX) + local firstID, count = smatch(id, FIRST_REGEX) if count == 0 then return nil end @@ -1253,7 +1265,7 @@ end ---@param id string ---@return string function m.getHeadID(id) - local headID, count = id:match(HEAD_REGEX) + local headID, count = smatch(id, HEAD_REGEX) if count == 0 then return nil end @@ -1267,7 +1279,7 @@ end ---@param id string ---@return string function m.getLastID(id) - local lastID, count = id:gsub(LAST_REGEX, '') + local lastID, count = sgsub(id, LAST_REGEX, '') if count == 0 then return nil end @@ -1284,7 +1296,7 @@ function m.getIDLength(id) if not id then return 0 end - local _, count = id:gsub(SPLIT_CHAR, SPLIT_CHAR) + local _, count = sgsub(id, SPLIT_CHAR, SPLIT_CHAR) return count + 1 end @@ -1296,11 +1308,11 @@ function m.hasField(id) if firstID == id or not firstID then return false end - local nextChar = id:sub(#firstID + 1, #firstID + 1) + local nextChar = ssub(id, #firstID + 1, #firstID + 1) if nextChar ~= SPLIT_CHAR then return false end - local next2Char = id:sub(#firstID + 2, #firstID + 2) + local next2Char = ssub(id, #firstID + 2, #firstID + 2) if next2Char == RETURN_INDEX or next2Char == PARAM_INDEX then return false @@ -1313,7 +1325,7 @@ end ---@return uri? string ---@return string id function m.getUriAndID(id) - local uri, newID = id:match(URI_REGEX) + local uri, newID = smatch(id, URI_REGEX) return uri, newID end @@ -1323,10 +1335,10 @@ function m.isCommonField(field) if not field then return false end - if field:sub(1, #RETURN_INDEX) == RETURN_INDEX then + if ssub(field, 1, #RETURN_INDEX) == RETURN_INDEX then return false end - if field:sub(1, #PARAM_INDEX) == PARAM_INDEX then + if ssub(field, 1, #PARAM_INDEX) == PARAM_INDEX then return false end return true @@ -1413,6 +1425,4 @@ files.watch(function (ev, uri) end end) -require 'tracy'.enable() - return m diff --git a/script/core/searcher.lua b/script/core/searcher.lua index 50b26d23..583186b5 100644 --- a/script/core/searcher.lua +++ b/script/core/searcher.lua @@ -6,6 +6,23 @@ local ws = require 'workspace' local vm = require 'vm.vm' local collector = require 'core.collector' +local TRACE = TRACE +local FOOTPRINT = FOOTPRINT +local TEST = TEST +local log = log +local select = select +local tostring = tostring +local ipairs = ipairs +local pairs = pairs +local error = error +local type = type +local tconcat = table.concat +local ssub = string.sub +local sfind = string.find +local sformat = string.format + +_ENV = nil + local ignoredSources = { ['int:'] = true, ['num:'] = true, @@ -220,7 +237,7 @@ local function footprint(status, ...) for i = 1, n do strs[i] = tostring(select(i, ...)) end - status.footprint[#status.footprint+1] = table.concat(strs, '\t', 1, n) + status.footprint[#status.footprint+1] = tconcat(strs, '\t', 1, n) end end @@ -258,14 +275,14 @@ local function stop(status, msg) if TEST then if FOOTPRINT then log.debug(status.mode) - log.debug(table.concat(status.footprint, '\n')) + log.debug(tconcat(status.footprint, '\n')) end error(msg) else log.warn(msg) if FOOTPRINT then log.debug(status.mode) - log.debug(table.concat(status.footprint, '\n')) + log.debug(tconcat(status.footprint, '\n')) end return end @@ -295,7 +312,7 @@ local function checkSLock(status, slock, id, field) if cmark[right] then return false end - field = field:sub(1, - #lastID - 1) + field = ssub(field, 1, - #lastID - 1) end return true end @@ -304,7 +321,7 @@ local function isCallID(field) if not field then return false end - if field:sub(1, 2) == noder.RETURN_INDEX then + if ssub(field, 1, 2) == noder.RETURN_INDEX then return true end return false @@ -358,7 +375,7 @@ function m.searchRefsByID(status, uri, expect, mode) if leftID == id then return end - rightID = id:sub(#leftID + 1) + rightID = ssub(id, #leftID + 1) search(leftID, rightID) local isCall = isCallID(firstID) if isCall then @@ -433,7 +450,7 @@ function m.searchRefsByID(status, uri, expect, mode) if source.special ~= '_G' then return end - local newID = 'g:' .. field:sub(2) + local newID = 'g:' .. ssub(field, 2) searchID(newID) end @@ -633,7 +650,7 @@ function m.searchRefsByID(status, uri, expect, mode) local function checkRequire(requireName, field) local tid = 'mainreturn' .. (field or '') local uris = ws.findUrisByRequirePath(requireName) - footprint(status, ('require %q:\n%s'):format(requireName, table.concat(uris, '\n'))) + footprint(status, 'require:', requireName) for _, ruri in ipairs(uris) do if not files.eq(uri, ruri) then crossSearch(status, ruri, tid, mode, uri) @@ -642,14 +659,14 @@ function m.searchRefsByID(status, uri, expect, mode) end local function searchGlobal(id, node, field) - if id:sub(1, 2) ~= 'g:' then + if ssub(id, 1, 2) ~= 'g:' then return end if checkLock(status, id, field) then return end local tid = id .. (field or '') - footprint(status, ('checkGlobal:%s + %s'):format(id, field, tid)) + footprint(status, 'checkGlobal:', id, field) local crossed = {} if mode == 'def' or mode == 'alldef' @@ -680,7 +697,7 @@ function m.searchRefsByID(status, uri, expect, mode) end local function searchClass(id, node, field) - if id:sub(1, 3) ~= 'dn:' then + if ssub(id, 1, 3) ~= 'dn:' then return end if checkLock(status, id, field) then @@ -706,10 +723,7 @@ function m.searchRefsByID(status, uri, expect, mode) local calls = vm.getLinksTo(uri) for _, call in ipairs(calls) do local curi = guide.getUri(call) - local cid = ('%s%s'):format( - noder.getID(call), - field or '' - ) + local cid = noder.getID(call) .. (field or '') if not files.eq(curi, uri) then crossSearch(status, curi, cid, mode, uri) end @@ -720,7 +734,7 @@ function m.searchRefsByID(status, uri, expect, mode) local locked = elock[id] if locked and field then if #locked <= #field then - if field:sub(-#locked) == locked then + if ssub(field, -#locked) == locked then footprint(status, 'elocked:', id, locked, field) return false end @@ -783,7 +797,7 @@ function m.searchRefsByID(status, uri, expect, mode) if not lastID then return end - local originField = id:sub(#lastID + 1) + local originField = ssub(id, #lastID + 1) if originField == noder.TABLE_KEY or originField == noder.WEAK_TABLE_KEY then return @@ -800,7 +814,7 @@ function m.searchRefsByID(status, uri, expect, mode) if not lastID then return end - local originField = id:sub(#lastID + 1) + local originField = ssub(id, #lastID + 1) if originField == noder.WEAK_TABLE_KEY then local newID = lastID .. noder.TABLE_KEY local newNode = noder.getNodeByID(root, newID) @@ -934,8 +948,8 @@ local function searchAllGlobalByUri(status, mode, uri, fullID) else for id, node in pairs(noders) do if node.source - and id:sub(1, 2) == 'g:' - and not id:find(noder.SPLIT_CHAR) then + and ssub(id, 1, 2) == 'g:' + and not sfind(id, noder.SPLIT_CHAR) then for source in noder.eachSource(node) do m.pushResult(status, mode, source) end @@ -961,9 +975,9 @@ function m.findGlobals(uri, mode, name) if name then local fullID if type(name) == 'string' then - fullID = ('%s%s%s'):format('g:', noder.STRING_CHAR, name) + fullID = sformat('%s%s%s', 'g:', noder.STRING_CHAR, name) else - fullID = ('%s%s%s'):format('g:', '', name) + fullID = sformat('%s%s%s', 'g:', '', name) end searchAllGlobalByUri(status, mode, uri, fullID) else @@ -1026,9 +1040,9 @@ function m.searchFields(status, source, mode, field) if source.special == '_G' then local fullID if type(field) == 'string' then - fullID = ('%s%s%s'):format('g:', noder.STRING_CHAR, field) + fullID = sformat('%s%s%s', 'g:', noder.STRING_CHAR, field) else - fullID = ('%s%s%s'):format('g:', '', field) + fullID = sformat('%s%s%s', 'g:', '', field) end if checkCache(status, uri, fullID, mode) then return @@ -1037,9 +1051,9 @@ function m.searchFields(status, source, mode, field) else local fullID if type(field) == 'string' then - fullID = ('%s%s%s'):format(id, noder.STRING_FIELD, field) + fullID = sformat('%s%s%s', id, noder.STRING_FIELD, field) else - fullID = ('%s%s%s'):format(id, noder.SPLIT_CHAR, field) + fullID = sformat('%s%s%s', id, noder.SPLIT_CHAR, field) end if checkCache(status, uri, fullID, mode) then return |