moon: distinguish static/class members
This commit is contained in:
parent
3df442d66a
commit
68a21f5ce7
11
ldoc/doc.lua
11
ldoc/doc.lua
|
@ -27,7 +27,8 @@ local known_tags = {
|
||||||
class = 'id', name = 'id', pragma = 'id', alias = 'id',
|
class = 'id', name = 'id', pragma = 'id', alias = 'id',
|
||||||
copyright = 'S', summary = 'S', description = 'S', release = 'S', license = 'S',
|
copyright = 'S', summary = 'S', description = 'S', release = 'S', license = 'S',
|
||||||
fixme = 'S', todo = 'S', warning = 'S', raise = 'S', charset = 'S', within = 'S',
|
fixme = 'S', todo = 'S', warning = 'S', raise = 'S', charset = 'S', within = 'S',
|
||||||
['local'] = 'N', export = 'N', private = 'N', constructor = 'N', static = 'N',include = 'S',
|
['local'] = 'N', export = 'N', private = 'N', constructor = 'N', static = 'N', classmethod = 'N',
|
||||||
|
include = 'S',
|
||||||
-- project-level
|
-- project-level
|
||||||
module = 'T', script = 'T', example = 'T', topic = 'T', submodule='T', classmod='T', file='T',
|
module = 'T', script = 'T', example = 'T', topic = 'T', submodule='T', classmod='T', file='T',
|
||||||
-- module-level
|
-- module-level
|
||||||
|
@ -344,6 +345,7 @@ function File:finish()
|
||||||
-- a class is either a @type section or a @classmod module. Is this a _method_?
|
-- a class is either a @type section or a @classmod module. Is this a _method_?
|
||||||
local class = classmod and this_mod.name or this_section.name
|
local class = classmod and this_mod.name or this_section.name
|
||||||
local static = item.tags.constructor or item.tags.static or item.type ~= 'function'
|
local static = item.tags.constructor or item.tags.static or item.type ~= 'function'
|
||||||
|
local classmethod = item.tags.classmethod
|
||||||
-- methods and metamethods go into their own special sections...
|
-- methods and metamethods go into their own special sections...
|
||||||
if classmod and item.type == 'function' then
|
if classmod and item.type == 'function' then
|
||||||
local inferred_section
|
local inferred_section
|
||||||
|
@ -357,7 +359,8 @@ function File:finish()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- Whether to use '.' or the language's version of ':' (e.g. \ for Moonscript)
|
-- Whether to use '.' or the language's version of ':' (e.g. \ for Moonscript)
|
||||||
item.name = class..(not static and this_mod.file.lang.method_call or '.')..item.name
|
class_name = classmethod and class or class:lower()
|
||||||
|
item.name = class_name..(not static and this_mod.file.lang.method_call or '.')..item.name
|
||||||
end
|
end
|
||||||
if stype == 'factory' then
|
if stype == 'factory' then
|
||||||
if item.tags.private then to_be_removed = true
|
if item.tags.private then to_be_removed = true
|
||||||
|
@ -407,7 +410,7 @@ function File:finish()
|
||||||
-- luacheck: pop
|
-- luacheck: pop
|
||||||
item.names_hierarchy = require('pl.utils').split(
|
item.names_hierarchy = require('pl.utils').split(
|
||||||
item.name,
|
item.name,
|
||||||
'[.:]'
|
'[.:\\]'
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1184,7 +1187,7 @@ function Module:get_fun_ref(s)
|
||||||
local fun_ref = self.items.by_name[s]
|
local fun_ref = self.items.by_name[s]
|
||||||
-- did not get an exact match, so try to match by the unqualified fun name
|
-- did not get an exact match, so try to match by the unqualified fun name
|
||||||
if not fun_ref then
|
if not fun_ref then
|
||||||
local patt = '[.:]'..s..'$'
|
local patt = '[.:\\]'..s..'$'
|
||||||
for qname,ref in pairs(self.items.by_name) do
|
for qname,ref in pairs(self.items.by_name) do
|
||||||
if qname:match(patt) then
|
if qname:match(patt) then
|
||||||
fun_ref = ref
|
fun_ref = ref
|
||||||
|
|
|
@ -301,7 +301,6 @@ function CC:item_follows (t,v,tok)
|
||||||
name = v
|
name = v
|
||||||
t,v = tnext(tok)
|
t,v = tnext(tok)
|
||||||
end
|
end
|
||||||
--print ('got',name,t,v,return_type)
|
|
||||||
return function(tags,tok)
|
return function(tags,tok)
|
||||||
if not tags.name then
|
if not tags.name then
|
||||||
tags:add('name',name)
|
tags:add('name',name)
|
||||||
|
@ -339,9 +338,14 @@ function Moon:extract_arg (tl,idx)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Moon:item_follows (t,v,tok)
|
function Moon:item_follows (t,v,tok)
|
||||||
|
local classmethod = false
|
||||||
if t == '.' then -- enclosed in with statement
|
if t == '.' then -- enclosed in with statement
|
||||||
t,v = tnext(tok)
|
t,v = tnext(tok)
|
||||||
end
|
end
|
||||||
|
if t == '@' then -- static member declaration
|
||||||
|
classmethod = true
|
||||||
|
t,v = tnext(tok)
|
||||||
|
end
|
||||||
if t == 'iden' then
|
if t == 'iden' then
|
||||||
local name,t,v = tools.get_fun_name(tok,v,'')
|
local name,t,v = tools.get_fun_name(tok,v,'')
|
||||||
if name == 'class' then
|
if name == 'class' then
|
||||||
|
@ -353,8 +357,7 @@ function Moon:item_follows (t,v,tok)
|
||||||
tags:add('name',name)
|
tags:add('name',name)
|
||||||
end
|
end
|
||||||
elseif t == '=' or t == ':' then -- function/method
|
elseif t == '=' or t == ':' then -- function/method
|
||||||
local _
|
t,v = tnext(tok)
|
||||||
t,_ = tnext(tok)
|
|
||||||
return function(tags,tok)
|
return function(tags,tok)
|
||||||
if not tags.name then
|
if not tags.name then
|
||||||
tags:add('name',name)
|
tags:add('name',name)
|
||||||
|
@ -364,10 +367,16 @@ function Moon:item_follows (t,v,tok)
|
||||||
else
|
else
|
||||||
tags.formal_args = List()
|
tags.formal_args = List()
|
||||||
end
|
end
|
||||||
t,_ = tnext(tok)
|
if t == '-' then
|
||||||
|
tags:add('static')
|
||||||
|
end
|
||||||
|
if classmethod then
|
||||||
|
tags:add('classmethod')
|
||||||
|
end
|
||||||
|
t,v = tnext(tok)
|
||||||
tags:add('class','function')
|
tags:add('class','function')
|
||||||
if t ~= '>' then
|
if t ~= '>' then
|
||||||
tags.static = true
|
tags:add('static')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
|
|
@ -152,7 +152,7 @@ end
|
||||||
-- e.g 'pl.utils.split' becomes 'pl.utils' and 'split'. Also
|
-- e.g 'pl.utils.split' becomes 'pl.utils' and 'split'. Also
|
||||||
-- must understand colon notation!
|
-- must understand colon notation!
|
||||||
function M.split_dotted_name (s)
|
function M.split_dotted_name (s)
|
||||||
local s1,s2 = s:match '^(.+)[%.:](.+)$'
|
local s1,s2 = s:match '^(.+)[%.:\\](.+)$'
|
||||||
if s1 then -- we can split
|
if s1 then -- we can split
|
||||||
return s1,s2
|
return s1,s2
|
||||||
else
|
else
|
||||||
|
|
Loading…
Reference in New Issue