From 656fb65304e97dab47a4932331de5eda19cb764b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Tue, 20 Oct 2020 21:05:43 +0800 Subject: =?UTF-8?q?=E5=9F=BA=E7=A1=80=E7=9A=84=20doc.class=20=E4=B8=8E=20d?= =?UTF-8?q?oc.type=20=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script-beta/parser/guide.lua | 49 ++++++++++++++++++++++++++++++++++++++++++- script-beta/parser/luadoc.lua | 11 ++++++++-- 2 files changed, 57 insertions(+), 3 deletions(-) (limited to 'script-beta/parser') diff --git a/script-beta/parser/guide.lua b/script-beta/parser/guide.lua index 1ae96097..cab37dc1 100644 --- a/script-beta/parser/guide.lua +++ b/script-beta/parser/guide.lua @@ -205,6 +205,18 @@ function m.getBreakBlock(obj) error('guide.getBreakBlock overstack') end +--- 寻找doc的主体 +function m.getDocState(obj) + for _ = 1, 1000 do + local parent = obj.parent + if parent.type == 'doc' then + return obj + end + obj = parent + end + error('guide.getDocState overstack') +end + --- 寻找根区块 function m.getRoot(obj) for _ = 1, 1000 do @@ -1378,6 +1390,39 @@ function m.checkSameSimpleInSpecialBranch(status, obj, start, queue) end end +function m.checkSameSimpleByBindDocs(status, obj, start, queue) + if not obj.bindDocs then + return + end + local results = {} + for _, doc in ipairs(obj.bindDocs) do + if doc.type == 'doc.class' then + results = stepRefOfDocType(status, doc.class, 'ref') + elseif doc.type == 'doc.type' then + for _, piece in ipairs(doc.types) do + local pieceResult = stepRefOfDocType(status, piece, 'ref') + for _, res in ipairs(pieceResult) do + results[#results+1] = res + end + end + end + end + local mark = {} + for _, res in ipairs(results) do + local ref = m.getDocState(res) + if not mark[ref] then + mark[ref] = true + if ref.bind then + queue[#queue+1] = { + obj = ref.bind, + start = start, + force = true, + } + end + end + end +end + function m.checkSameSimpleInArg1OfSetMetaTable(status, obj, start, queue) local args = obj.parent if not args or args.type ~= 'callargs' then @@ -1846,8 +1891,10 @@ function m.checkSameSimple(status, simple, data, mode, results, queue) m.checkSameSimpleInArg1OfSetMetaTable(status, ref, i, queue) -- 检查自己作为 setmetatable 调用的情况 m.checkSameSimpleInValueOfCallMetaTable(status, ref, i, queue) - -- 检查自己是特殊分支的情况 + -- 检查自己是特殊变量的分支的情况 m.checkSameSimpleInSpecialBranch(status, ref, i, queue) + -- 检查 doc + m.checkSameSimpleByBindDocs(status, ref, i, queue) if cmode == 'ref' and not status.simple then -- 检查形如 { a = f } 的情况 m.checkSameSimpleAsTableField(status, ref, i, queue) diff --git a/script-beta/parser/luadoc.lua b/script-beta/parser/luadoc.lua index 121b25eb..e2aa950d 100644 --- a/script-beta/parser/luadoc.lua +++ b/script-beta/parser/luadoc.lua @@ -705,7 +705,10 @@ local function bindDoc(state, lns, binded) or src.type == 'tablefield' or src.type == 'tableindex' or src.type == 'function' then - src.docs = binded + src.bindDocs = binded + for _, doc in ipairs(binded) do + doc.bind = src + end end end) end @@ -715,7 +718,7 @@ local function bindDocs(state) local binded for _, doc in ipairs(state.ast.docs) do if not isNextLine(lns, binded, doc) then - bindDoc(state, binded) + bindDoc(state, lns, binded) binded = {} end binded[#binded+1] = doc @@ -750,5 +753,9 @@ return function (_, state) end end + if #ast.docs == 0 then + return + end + bindDocs(state) end -- cgit v1.2.3