From 84f4da78a9b07823f6d78409fea8d373b6fbc3b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Thu, 26 Nov 2020 12:04:14 +0800 Subject: luadoc support tailcomment --- script/parser/guide.lua | 24 ++++++++++++------------ script/parser/luadoc.lua | 20 +++++++++++--------- 2 files changed, 23 insertions(+), 21 deletions(-) (limited to 'script/parser') diff --git a/script/parser/guide.lua b/script/parser/guide.lua index 7ca3ddd0..bc82ec57 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -84,18 +84,18 @@ m.childMap = { ['unary'] = {1}, ['doc'] = {'#'}, - ['doc.class'] = {'class', 'extends'}, - ['doc.type'] = {'#types', '#enums', 'name'}, - ['doc.alias'] = {'alias', 'extends'}, - ['doc.param'] = {'param', 'extends'}, - ['doc.return'] = {'#returns'}, - ['doc.field'] = {'field', 'extends'}, - ['doc.generic'] = {'#generics'}, - ['doc.generic.object'] = {'generic', 'extends'}, - ['doc.vararg'] = {'vararg'}, - ['doc.type.table'] = {'key', 'value'}, - ['doc.type.function'] = {'#args', '#returns'}, - ['doc.overload'] = {'overload'}, + ['doc.class'] = {'class', 'extends', 'comment'}, + ['doc.type'] = {'#types', '#enums', 'name', 'comment'}, + ['doc.alias'] = {'alias', 'extends', 'comment'}, + ['doc.param'] = {'param', 'extends', 'comment'}, + ['doc.return'] = {'#returns', 'comment'}, + ['doc.field'] = {'field', 'extends', 'comment'}, + ['doc.generic'] = {'#generics', 'comment'}, + ['doc.generic.object'] = {'generic', 'extends', 'comment'}, + ['doc.vararg'] = {'vararg', 'comment'}, + ['doc.type.table'] = {'key', 'value', 'comment'}, + ['doc.type.function'] = {'#args', '#returns', 'comment'}, + ['doc.overload'] = {'overload', 'comment'}, } m.actionMap = { diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 2b2396ec..53f0097d 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -856,19 +856,21 @@ local function buildLuaDoc(comment) comment = comment, } end - local finishPos = text:find('@', startPos + 1) - local doc, lastComment - if finishPos then - doc = text:sub(startPos + 1, finishPos - 1) - lastComment = text:sub(finishPos) - else - doc = text:sub(startPos + 1) - end + + local doc = text:sub(startPos + 1) parseTokens(doc, comment.start + startPos - 1) local result = convertTokens() if result then - result.comment = lastComment + local cstart = text:find('%S', result.finish - comment.start + 2) + if cstart and cstart < comment.finish then + result.comment = { + type = 'doc.tailcomment', + start = cstart + comment.start - 1, + finish = comment.finish, + text = text:sub(cstart), + } + end end return result -- cgit v1.2.3