From 8123dd362c1991ac87a26822729f24a53ef6b35e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=80=E8=90=8C=E5=B0=8F=E6=B1=90?= Date: Fri, 7 May 2021 17:48:31 +0800 Subject: resolve #455 tail comments support lua string --- script/parser/luadoc.lua | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) (limited to 'script') diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index 74e53718..3ab9f6a1 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -2,6 +2,7 @@ local m = require 'lpeglabel' local re = require 'parser.relabel' local lines = require 'parser.lines' local guide = require 'core.guide' +local grammar = require 'parser.grammar' local TokenTypes, TokenStarts, TokenFinishs, TokenContents local Ci, Offset, pushError, Ct, NextComment, Lines @@ -999,16 +1000,23 @@ local function convertTokens() end local function trimTailComment(text) + local comment = text if text:sub(1, 1) == '@' then - return text:sub(2) + comment = text:sub(2) end if text:sub(1, 1) == '#' then - return text:sub(2) + comment = text:sub(2) end if text:sub(1, 2) == '--' then - return text:sub(3) + comment = text:sub(3) end - return text + if comment:find '^%s*[\'"[]' then + local result = grammar(nil, comment:gsub('^%s+', ''), 'string') + if result then + comment = result[1][1] + end + end + return comment end local function buildLuaDoc(comment) @@ -1185,7 +1193,7 @@ local function bindDoc(sources, lns, binded) end bindGeneric(binded) local row = guide.positionOf(lns, lastDoc.finish) - local cstart, cfinish = guide.lineRange(lns, row) + local cstart, cfinish = guide.lineRange(lns, row) local nstart, nfinish = guide.lineRange(lns, row + 1) bindDocsBetween(sources, binded, bindSources, cstart, cfinish) if #bindSources == 0 then -- cgit v1.2.3