Codebase list lua-ldoc / c516eeb
version bump; underscore escaping fix for backticks; horrible workaround for deficiencies of C lexer steve donovan 9 years ago
4 changed file(s) with 49 addition(s) and 16 deletion(s). Raw diff Collapse all Expand all
258258 local err
259259 f,err = utils.readfile(f)
260260 if not f then quit(err) end
261 return lexer.cpp(f,{})
261 return lexer.cpp(f,{},nil,true)
262262 end
263263
264264 function CC:grab_block_comment(v,tok)
4343 local STRING3 = "^((['\"])%2)" -- empty string
4444 local PREPRO = '^#.-[^\\]\n'
4545
46 local plain_matches,lua_matches,cpp_matches,lua_keyword,cpp_keyword
46 local plain_matches,lua_matches,cpp_matches,cpp_matches_no_string,lua_keyword,cpp_keyword
4747
4848 local function tdump(tok)
4949 return tok,tok
323323 -- @param filter a table of token types to exclude, by default {space=true,comments=true}
324324 -- @param options a table of options; by default, {number=true,string=true},
325325 -- which means convert numbers and strip string quotes.
326 function lexer.cpp(s,filter,options)
326 function lexer.cpp(s,filter,options,no_string)
327327 filter = filter or {comments=true}
328328 if not cpp_keyword then
329329 cpp_keyword = {
349349 {IDEN,cpp_vdump},
350350 {NUMBER4,ndump},
351351 {NUMBER5,ndump},
352 -- {STRING3,sdump},
353 -- {STRING1,chdump},
354 -- {STRING2,sdump},
352 {STRING3,sdump},
353 {STRING1,chdump},
354 {STRING2,sdump},
355355 {'^//.-\n',cdump},
356356 {'^/%*.-%*/',cdump},
357357 {'^==',tdump},
374374 {'^.',tdump}
375375 }
376376 end
377 return lexer.scan(s,cpp_matches,filter,options)
377 if not cpp_matches_no_string then
378 cpp_matches_no_string = {
379 {WSPACE,wsdump},
380 {PREPRO,pdump},
381 {NUMBER3,ndump},
382 {IDEN,cpp_vdump},
383 {NUMBER4,ndump},
384 {NUMBER5,ndump},
385 {'^//.-\n',cdump},
386 {'^/%*.-%*/',cdump},
387 {'^==',tdump},
388 {'^!=',tdump},
389 {'^<=',tdump},
390 {'^>=',tdump},
391 {'^->',tdump},
392 {'^&&',tdump},
393 {'^||',tdump},
394 {'^%+%+',tdump},
395 {'^%-%-',tdump},
396 {'^%+=',tdump},
397 {'^%-=',tdump},
398 {'^%*=',tdump},
399 {'^/=',tdump},
400 {'^|=',tdump},
401 {'^%^=',tdump},
402 {'^::',tdump},
403 {'^%.%.%.',tdump},
404 {'^.',tdump}
405 }
406 end
407 return lexer.scan(s,
408 not no_string and cpp_matches or cpp_matches_no_string,
409 filter,options)
378410 end
379411
380412 --- get a list of parameters separated by a delimiter from a stream.
5353 if backtick_references then
5454 res = res:gsub('`([^`]+)`',function(name)
5555 local ref,err = markup.process_reference(name)
56 local label = name
57 if name and do_escape then
58 label = name:gsub('_', '\\_')
59 end
5660 if ref then
57 if name and do_escape then
58 name = name:gsub('_', '\\_')
59 end
60 return ('<a href="%s">%s</a>'):format(ldoc.href(ref),name)
61 return ('<a href="%s">%s</a>'):format(ldoc.href(ref),label)
6162 else
62 return '<code>'..name..'</code>'
63 return '<code>'..label..'</code>'
6364 end
6465 end)
6566 end
116117 -- - prettify any code blocks
117118
118119 local function process_multiline_markdown(ldoc, txt, F, filename, deflang)
119 local res, L, append = {}, 0, table.insert
120 local res, L, append = {}, 0, table.insert
120121 local err_item = {
121122 warning = function (self,msg)
122123 io.stderr:write(filename..':'..L..': '..msg,'\n')
132133 if code ~= '' then
133134 local err
134135 -- If we omit the following '\n', a '--' (or '//') comment on the
135 -- last line won't be recognized.
136 -- last line won't be recognized.
136137 code, err = prettify.code(lang,filename,code..'\n',L,false)
137138 code = resolve_inline_references(ldoc, code, err_item,true)
138139 append(res,'<pre>')
307308 -- AFAIK only markdown.lua has underscore-in-identifier problem...
308309 if ldoc.dont_escape_underscore ~= nil then
309310 ldoc.dont_escape_underscore = actual_format ~= 'markdown'
310 end
311 end
311312 return markdown_processor(ldoc, formatter)
312313 end
313314
3636
3737 --- @usage
3838 local usage = [[
39 ldoc, a documentation generator for Lua, vs 1.4.2
39 ldoc, a documentation generator for Lua, vs 1.4.3
4040 -d,--dir (default doc) output directory
4141 -o,--output (default 'index') output name
4242 -v,--verbose verbose