diff options
Diffstat (limited to 'script/parser/guide.lua')
-rw-r--r-- | script/parser/guide.lua | 105 |
1 files changed, 60 insertions, 45 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 2369e84f..a838a42e 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -1,34 +1,8 @@ -local util = require 'utility' local error = error local type = type -local next = next -local tostring = tostring -local print = print -local ipairs = ipairs -local tableInsert = table.insert -local tableUnpack = table.unpack -local tableRemove = table.remove -local tableMove = table.move -local tableSort = table.sort -local tableConcat = table.concat -local mathType = math.type -local pairs = pairs -local setmetatable = setmetatable -local assert = assert -local select = select -local osClock = os.clock -local tonumber = tonumber -local tointeger = math.tointeger -local DEVELOP = _G.DEVELOP -local log = log -local _G = _G ---@class parser.guide.object -local function logWarn(...) - log.warn(...) -end - ---@class guide ---@field debugMode boolean local m = {} @@ -102,7 +76,7 @@ m.childMap = { ['doc.type.array'] = {'node'}, ['doc.type.table'] = {'node', 'key', 'value', 'comment'}, ['doc.type.function'] = {'#args', '#returns', 'comment'}, - ['doc.type.typeliteral'] = {'node'}, + ['doc.type.literal'] = {'node'}, ['doc.type.arg'] = {'extends'}, ['doc.overload'] = {'overload', 'comment'}, ['doc.see'] = {'name', 'field'}, @@ -123,20 +97,6 @@ m.actionMap = { ['funcargs'] = {'#'}, } -local TypeSort = { - ['boolean'] = 1, - ['string'] = 2, - ['integer'] = 3, - ['number'] = 4, - ['table'] = 5, - ['function'] = 6, - ['true'] = 101, - ['false'] = 102, - ['nil'] = 999, -} - -local NIL = setmetatable({'<nil>'}, { __tostring = function () return 'nil' end }) - --- 是否是字面量 ---@param obj parser.guide.object ---@return boolean @@ -293,10 +253,19 @@ end ---@param obj parser.guide.object ---@return parser.guide.object function m.getRoot(obj) + local source = obj + if source._root then + return source._root + end for _ = 1, 1000 do if obj.type == 'main' then + source._root = obj return obj end + if obj._root then + source._root = obj._root + return source._root + end local parent = obj.parent if not parent then return nil @@ -501,8 +470,8 @@ function m.addChilds(list, obj, map) for i = 1, #keys do local key = keys[i] if key == '#' then - for i = 1, #obj do - list[#list+1] = obj[i] + for j = 1, #obj do + list[#list+1] = obj[j] end elseif obj[key] then list[#list+1] = obj[key] @@ -510,8 +479,8 @@ function m.addChilds(list, obj, map) and key:sub(1, 1) == '#' then key = key:sub(2) if obj[key] then - for i = 1, #obj[key] do - list[#list+1] = obj[key][i] + for j = 1, #obj[key] do + list[#list+1] = obj[key][j] end end end @@ -718,4 +687,50 @@ function m.lineData(lines, row) return lines[row] end +function m.isSet(source) + local tp = source.type + if tp == 'setglobal' + or tp == 'local' + or tp == 'setlocal' + or tp == 'setfield' + or tp == 'setmethod' + or tp == 'setindex' + or tp == 'tablefield' + or tp == 'tableindex' then + return true + end + if tp == 'call' then + local special = m.getSpecial(source.node) + if special == 'rawset' then + return true + end + end + return false +end + +function m.isGet(source) + local tp = source.type + if tp == 'getglobal' + or tp == 'getlocal' + or tp == 'getfield' + or tp == 'getmethod' + or tp == 'getindex' then + return true + end + if tp == 'call' then + local special = m.getSpecial(source.node) + if special == 'rawget' then + return true + end + end + return false +end + +function m.getSpecial(source) + if not source then + return nil + end + return source.special +end + return m |