From 1407055930f23b06fbe9a6cc29cc9e54b1356783 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Sat, 16 Apr 2022 03:32:43 +0800 Subject: fix definition of `table` --- script/parser/guide.lua | 2 +- script/parser/luadoc.lua | 91 +++++++++++++++++++++++++++++------------------- 2 files changed, 56 insertions(+), 37 deletions(-) (limited to 'script/parser') diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 884a5271..0ece65fc 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -123,7 +123,6 @@ local childMap = { ['doc'] = {'#'}, ['doc.class'] = {'class', '#extends', '#signs', 'comment'}, ['doc.type'] = {'#types', 'name', 'comment'}, - ['doc.type.name'] = {'#signs'}, ['doc.alias'] = {'alias', 'extends', 'comment'}, ['doc.param'] = {'param', 'extends', 'comment'}, ['doc.return'] = {'#returns', 'comment'}, @@ -137,6 +136,7 @@ local childMap = { ['doc.type.literal'] = {'node'}, ['doc.type.arg'] = {'name', 'extends'}, ['doc.type.field'] = {'name', 'extends'}, + ['doc.type.sign'] = {'node', '#signs'}, ['doc.overload'] = {'overload', 'comment'}, ['doc.see'] = {'name', 'field'}, ['doc.version'] = {'#versions'}, diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 22a2df1b..1d8d7c42 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -309,34 +309,21 @@ local function parseTable(parent) return typeUnit end -local function parseSigns(parent, mode) +local function parseSigns(parent) if not checkToken('symbol', '<', 1) then return nil end nextToken() local signs = {} while true do - local sign - if mode == 'name' then - sign = parseName('doc.generic.name', parent) - if not sign then - pushWarning { - type = 'LUADOC_MISS_SIGN_NAME', - start = getFinish(), - finish = getFinish(), - } - break - end - elseif mode == 'type' then - sign = parseType(parent) - if not sign then - pushWarning { - type = 'LUADOC_MISS_TYPE_NAME', - start = getFinish(), - finish = getFinish(), - } - break - end + local sign = parseName('doc.generic.name', parent) + if not sign then + pushWarning { + type = 'LUADOC_MISS_SIGN_NAME', + start = getFinish(), + finish = getFinish(), + } + break end signs[#signs+1] = sign if checkToken('symbol', ',', 1) then @@ -345,17 +332,7 @@ local function parseSigns(parent, mode) break end end - if not checkToken('symbol', '>', 1) then - pushWarning { - type = 'LUADOC_MISS_SYMBOL', - start = getFinish(), - finish = getFinish(), - symbol = { - symbol = '>', - } - } - end - nextToken() + nextSymbolOrError '>' return signs end @@ -376,7 +353,7 @@ local function parseClass(parent) end result.start = getStart() result.finish = getFinish() - result.signs = parseSigns(result, 'name') + result.signs = parseSigns(result) if not checkToken('symbol', ':', 1) then return result end @@ -421,6 +398,42 @@ local function parseTypeUnitArray(parent, node) return result end +local function parseTypeUnitSign(parent, node) + if not checkToken('symbol', '<', 1) then + return nil + end + nextToken() + local result = { + type = 'doc.type.sign', + start = node.start, + finish = getFinish(), + node = node, + parent = parent, + signs = {}, + } + node.parent = result + while true do + local sign = parseType(result) + if not sign then + pushWarning { + type = 'LUA_DOC_MISS_SIGN', + start = getFinish(), + finish = getFinish(), + } + break + end + result.signs[#result.signs+1] = sign + if checkToken('symbol', ',', 1) then + nextToken() + else + break + end + end + nextSymbolOrError '>' + result.finish = getFinish() + return result +end + local function parseDots(tp, parent) if not checkToken('symbol', '...', 1) then return @@ -629,7 +642,13 @@ function parseTypeUnit(parent) result.literal = true nextSymbolOrError '`' end - result.signs = parseSigns(result, 'type') + end + while true do + local newResult = parseTypeUnitSign(parent, result) + if not newResult then + break + end + result = newResult end while true do local newResult = parseTypeUnitArray(parent, result) @@ -777,7 +796,7 @@ local function parseAlias() return nil end result.start = getStart() - result.signs = parseSigns(result, 'name') + result.signs = parseSigns(result) result.extends = parseType(result) if not result.extends then pushWarning { -- cgit v1.2.3