diff options
author | 最萌小汐 <sumneko@hotmail.com> | 2022-07-06 19:02:23 +0800 |
---|---|---|
committer | 最萌小汐 <sumneko@hotmail.com> | 2022-07-06 19:02:23 +0800 |
commit | 26e0310a410820650832f8576154c9b7ee183324 (patch) | |
tree | 3979fdaa48bdc223c2af9dd17b3f7a5f4764b8f6 /script/parser | |
parent | 91ab8e7b4c3c17da0a1bcdfb02a38c23cc786910 (diff) | |
download | lua-language-server-26e0310a410820650832f8576154c9b7ee183324.zip |
support unary operator
Diffstat (limited to 'script/parser')
-rw-r--r-- | script/parser/guide.lua | 27 | ||||
-rw-r--r-- | script/parser/luadoc.lua | 18 |
2 files changed, 14 insertions, 31 deletions
diff --git a/script/parser/guide.lua b/script/parser/guide.lua index f782c43a..0768cbb4 100644 --- a/script/parser/guide.lua +++ b/script/parser/guide.lua @@ -158,6 +158,7 @@ local childMap = { ['doc.as'] = {'as'}, ['doc.cast'] = {'loc', '#casts'}, ['doc.cast.block'] = {'extends'}, + ['doc.operator'] = {'op', 'exp', 'extends'} } ---@type table<string, fun(obj: parser.object, list: parser.object[])> @@ -250,32 +251,6 @@ m.actionMap = { ['funcargs'] = {'#'}, } -local inf = 1 / 0 -local nan = 0 / 0 - -local function isInteger(n) - if math.type then - return math.type(n) == 'integer' - else - return type(n) == 'number' and n % 1 == 0 - end -end - -local function formatNumber(n) - if n == inf - or n == -inf - or n == nan - or n ~= n then -- IEEE 标准中,NAN 不等于自己。但是某些实现中没有遵守这个规则 - return ('%q'):format(n) - end - if isInteger(n) then - return tostring(n) - end - local str = ('%.10f'):format(n) - str = str:gsub('%.?0*$', '') - return str -end - --- 是否是字面量 ---@param obj table ---@return boolean diff --git a/script/parser/luadoc.lua b/script/parser/luadoc.lua index a94f89cd..2237b232 100644 --- a/script/parser/luadoc.lua +++ b/script/parser/luadoc.lua @@ -819,8 +819,9 @@ local docSwitch = util.switch() : case 'class' : call(function () local result = { - type = 'doc.class', - fields = {}, + type = 'doc.class', + fields = {}, + operators = {}, } result.class = parseName('doc.class.name', result) if not result.class then @@ -1386,8 +1387,8 @@ local docSwitch = util.switch() local ret = parseType(result) if ret then - result.ret = ret - result.finish = ret.finish + result.extends = ret + result.finish = ret.finish end return result @@ -1497,8 +1498,10 @@ local function isContinuedDoc(lastDoc, nextDoc) return false end if lastDoc.type == 'doc.class' - or lastDoc.type == 'doc.field' then + or lastDoc.type == 'doc.field' + or lastDoc.type == 'doc.operator' then if nextDoc.type ~= 'doc.field' + and nextDoc.type ~= 'doc.operator' and nextDoc.type ~= 'doc.comment' and nextDoc.type ~= 'doc.overload' then return false @@ -1650,6 +1653,11 @@ local function bindClassAndFields(binded) class.fields[#class.fields+1] = doc doc.class = class end + elseif doc.type == 'doc.operator' then + if class then + class.operators[#class.operators+1] = doc + doc.class = class + end end end end |