- comments within formal arguments: last comment may be outside the

closing parenthesis. If comments are of form TYPE:COMMENT then
equivalent to @tparam not @param. See tests/factory/mymod.lua
- @constructor tag attaches CLASS. as prefix to name
- No more implicit use of "require 'pl'".
This commit is contained in:
steve donovan 2012-10-28 19:51:00 +02:00
parent f474eccdf8
commit 05727ec0cf
9 changed files with 81 additions and 18 deletions

View File

@ -16,7 +16,14 @@
-- @license MIT/X11 -- @license MIT/X11
-- @script ldoc -- @script ldoc
require 'pl' local class = require 'pl.class'
local app = require 'pl.app'
local path = require 'pl.path'
local utils = require 'pl.utils'
local List = require 'pl.List'
local stringx = require 'pl.stringx'
local tablex = require 'pl.tablex'
local append = table.insert local append = table.insert

View File

@ -2,7 +2,9 @@
-- Defining the ldoc document model. -- Defining the ldoc document model.
require 'pl' local class = require 'pl.class'
local utils = require 'pl.utils'
local List = require 'pl.List'
local doc = {} local doc = {}
local global = require 'ldoc.builtin.globals' local global = require 'ldoc.builtin.globals'
@ -222,9 +224,8 @@ function File:finish()
-- if it was a class, then the name should be 'Class:foo' -- if it was a class, then the name should be 'Class:foo'
local stype = this_mod.section.type local stype = this_mod.section.type
if doc.class_tag(stype) then if doc.class_tag(stype) then
local prefix = this_mod.section.name .. ':' local prefix = this_mod.section.name .. (not item.tags.constructor and ':' or '.')
local i1,i2 = item.name:find(prefix) if not has_prefix(item.name,prefix) then
if not has_prefix(item.name,prefix) and not item.tags.constructor then
item.name = prefix .. item.name item.name = prefix .. item.name
end end
if stype == 'factory' then if stype == 'factory' then
@ -416,8 +417,9 @@ function Item:finish()
else else
self.parameter = 'field' self.parameter = 'field'
end end
local params = read_del(tags,self.parameter) local field = self.parameter
local names, comments, modifiers = List(), List(), List() local params = read_del(tags,field)
local names, comments = List(), List()
if params then if params then
for line in params:iter() do for line in params:iter() do
local name, comment = line :match('%s*([%w_%.:]+)(.*)') local name, comment = line :match('%s*([%w_%.:]+)(.*)')
@ -447,8 +449,23 @@ function Item:finish()
end end
end end
names:append(name) names:append(name)
-- ldoc allows comments in the formal arg list to be used local comment = pcomments[i]
comments:append (fargs.comments[name] or pcomments[i] or '') if not comment then
-- ldoc allows comments in the formal arg list to be used, if they aren't specified with @param
-- Further, these comments may start with a type followed by a colon, and are then equivalent
-- to a @tparam
comment = fargs.comments[name]
if comment then
comment = comment:gsub('^%-+%s*','')
local type,rest = comment:match '([^:]+):(.*)'
if type then
if not self.modifiers[field] then self.modifiers[field] = List() end
self.modifiers[field]:append {type = type}
comment = rest
end
end
end
comments:append (comment or '')
end end
-- A formal argument of ... may match any number of params, however. -- A formal argument of ... may match any number of params, however.
if #pnames > #fargs then if #pnames > #fargs then
@ -468,7 +485,7 @@ function Item:finish()
-- adding name-value pairs to the params list (this is -- adding name-value pairs to the params list (this is
-- also done for any associated modifiers) -- also done for any associated modifiers)
self.params = names self.params = names
local pmods = self.modifiers[self.parameter] local pmods = self.modifiers[field]
for i,name in ipairs(self.params) do for i,name in ipairs(self.params) do
self.params[name] = comments[i] self.params[name] = comments[i]
if pmods then if pmods then
@ -543,9 +560,7 @@ end
local err = io.stderr local err = io.stderr
local function custom_see_references (s) local function custom_see_references (s)
--err:write('next',next(see_reference_handlers),'\n')
for pat, action in pairs(see_reference_handlers) do for pat, action in pairs(see_reference_handlers) do
--err:write('pair ',pair,'\n')
if s:match(pat) then if s:match(pat) then
local label, href = action(s:match(pat)) local label, href = action(s:match(pat))
return {href = href, label = label} return {href = href, label = label}

View File

@ -13,6 +13,10 @@
-- generalizes the idea of these project-level categories and in fact custom categories -- generalizes the idea of these project-level categories and in fact custom categories
-- can be created (refered to as 'kinds' in the code) -- can be created (refered to as 'kinds' in the code)
local List = require 'pl.List'
local utils = require 'pl.utils'
local path = require 'pl.path'
local stringx = require 'pl.stringx'
local template = require 'pl.template' local template = require 'pl.template'
local tools = require 'ldoc.tools' local tools = require 'ldoc.tools'
local markup = require 'ldoc.markup' local markup = require 'ldoc.markup'

View File

@ -3,8 +3,8 @@
-- This encapsulates the different strategies needed for parsing C and Lua -- This encapsulates the different strategies needed for parsing C and Lua
-- source code. -- source code.
require 'pl' local class = require 'pl.class'
local utils = require 'pl.utils'
local tools = require 'ldoc.tools' local tools = require 'ldoc.tools'
local lexer = require 'ldoc.lexer' local lexer = require 'ldoc.lexer'

View File

@ -3,9 +3,9 @@
-- Currently just does Markdown, but this is intended to -- Currently just does Markdown, but this is intended to
-- be the general module for managing other formats as well. -- be the general module for managing other formats as well.
require 'pl'
local doc = require 'ldoc.doc' local doc = require 'ldoc.doc'
local utils = require 'pl.utils' local utils = require 'pl.utils'
local stringx = require 'pl.stringx'
local prettify = require 'ldoc.prettify' local prettify = require 'ldoc.prettify'
local quit, concat, lstrip = utils.quit, table.concat, stringx.lstrip local quit, concat, lstrip = utils.quit, table.concat, stringx.lstrip
local markup = {} local markup = {}

View File

@ -1,6 +1,8 @@
-- parsing code for doc comments -- parsing code for doc comments
require 'pl' local List = require 'pl.List'
local Map = require 'pl.Map'
local stringio = require 'pl.stringio'
local lexer = require 'ldoc.lexer' local lexer = require 'ldoc.lexer'
local tools = require 'ldoc.tools' local tools = require 'ldoc.tools'
local doc = require 'ldoc.doc' local doc = require 'ldoc.doc'

View File

@ -3,7 +3,7 @@
-- for known modules and functions. -- for known modules and functions.
-- A module reference to an example `test-fun.lua` would look like -- A module reference to an example `test-fun.lua` would look like
-- `@{example:test-fun}`. -- `@{example:test-fun}`.
require 'pl' local List = require 'pl.List'
local lexer = require 'ldoc.lexer' local lexer = require 'ldoc.lexer'
local globals = require 'ldoc.builtin.globals' local globals = require 'ldoc.builtin.globals'
local tnext = lexer.skipws local tnext = lexer.skipws

View File

@ -2,7 +2,10 @@
-- General utility functions for ldoc -- General utility functions for ldoc
-- @module tools -- @module tools
require 'pl' local class = require 'pl.class'
local List = require 'pl.List'
local path = require 'pl.path'
local utils = require 'pl.utils'
local tools = {} local tools = {}
local M = tools local M = tools
local append = table.insert local append = table.insert
@ -300,6 +303,17 @@ function M.get_parameters (tok,endtoken,delim)
end end
end end
if next(args.comments) then -- we had argument comments
-- but the last one may be outside the parens! (Geoff style)
local n = #args
if not args.comments[n] then
local t = {tok()}
if type_of(t) == 'comment' then
set_comment(n,t)
end
end
end
return args return args
end end

21
tests/factory/mymod.lua Normal file
View File

@ -0,0 +1,21 @@
--- mymod
local mymod = {}
--- everything!
function mymod.query (
a, --string: first arg
b, --int: second arg
c --table: arg
)
end
--- for everything.
function mymod.answer (
a, -- first arg
b, -- second arg
c) -- third arg
end
return mymod