Issue #93: can define fields/properties of objects; the 'readonly' modifier is now special. See tests/styles/type.lua

This commit is contained in:
steve donovan 2013-11-16 19:21:50 +02:00
parent 7e2e6e975c
commit 955802e07b
4 changed files with 56 additions and 2 deletions

View File

@ -288,6 +288,9 @@ function File:finish()
-- add the item to the module's item list
if this_mod then
-- new-style modules will have qualified names like 'mod.foo'
if item.name == nil then
self:error("item's name is nil")
end
local mod,fname = split_dotted_name(item.name)
-- warning for inferred unqualified names in new style modules
-- (retired until we handle methods like Set:unset() properly)
@ -421,7 +424,7 @@ end
function Item:trailing_warning (kind,tag,rest)
if type(rest)=='string' and #rest > 0 then
Item.warning(self,kind.." tag: '"..tag..'" has trailing text; use not_luadoc=true if you want description to continue between tags\n'..rest)
Item.warning(self,kind.." tag: '"..tag..'" has trailing text ; use not_luadoc=true if you want description to continue between tags\n"'..rest..'"')
end
end
@ -825,6 +828,12 @@ function Item:default_of_param(p)
return opt
end
function Item:readonly(p)
local m = self:param_modifiers(p)
if not m then return nil end
return m.readonly
end
function Item:subparam(p)
local subp = rawget(self.subparams,p)
if subp then

View File

@ -155,7 +155,10 @@ return [==[
$(M(ldoc.descript(item),item))
# if show_parms and item.params and #item.params > 0 then
<h3>$(module.kinds:type_of(item).subnames):</h3>
# local subnames = module.kinds:type_of(item).subnames
# if subnames then
<h3>$(subnames):</h3>
# end
<ul>
# for parm in iter(item.params) do
# local param,sublist = item:subparam(parm)
@ -172,6 +175,9 @@ return [==[
$(M(item.params[p],item))
# if def then
(<em>default</em> $(def))
# end
# if item:readonly(p) then
<em>readonly</em>
# end
</li>
# end

View File

@ -364,6 +364,17 @@ local function parse_file(fname, lang, package, args)
if is_local or tags['local'] then
tags:add('local',true)
end
-- support for standalone fields/properties of classes/modules
if (tags.field or tags.param) and not tags.class then
-- the hack is to take a subfield and pull out its name,
-- (see Tag:add above) but let the subfield itself go through
-- with any modifiers.
local fp = tags.field or tags.param
if type(fp) == 'table' then fp = fp[1] end
fp = tools.extract_identifier(fp)
tags:add('name',fp)
tags:add('class','field')
end
if tags.name then
current_item = F:new_item(tags,line)
current_item.inferred = item_follows ~= nil

28
tests/styles/type.lua Normal file
View File

@ -0,0 +1,28 @@
-----
-- module containing a class
-- @module type
----
-- Our class.
-- @type Bonzo
----
-- make a new Bonzo
-- @string s name of Bonzo
function Bonzo.new(s)
end
-----
-- get a string representation.
function Bonzo.__tostring()
end
----
-- A subtable with fields.
-- @table Details
-- @string[readonly] name
-- @int[readonly] age
---
-- This is a simple field/property of the class.
-- @string[opt="Bilbo",readonly] frodo direct access to text