diff --git a/ldoc.lua b/ldoc.lua index ef9652d..9c58974 100644 --- a/ldoc.lua +++ b/ldoc.lua @@ -7,7 +7,7 @@ -- -- C/C++ support for Lua extensions is provided. -- --- Available from LuaRocks as 'ldoc' and as a [Zip file](http://stevedonovan.github.com/files/ldoc-1.3.9.zip) +-- Available from LuaRocks as 'ldoc' and as a [Zip file](http://stevedonovan.github.com/files/ldoc-1.4.0.zip) -- -- [Github Page](https://github.com/stevedonovan/ldoc) -- @@ -475,7 +475,8 @@ if type(ldoc.examples) == 'table' then }) -- wrap prettify for this example so it knows which file to blame -- if there's a problem - item.postprocess = function(code) return prettify.lua(f,code,0,true) end + local ext = path.extension(f):sub(2) + item.postprocess = function(code) return prettify.lua(ext,f,code,0,true) end end) end diff --git a/ldoc/prettify.lua b/ldoc/prettify.lua index d33f34a..8013dc5 100644 --- a/ldoc/prettify.lua +++ b/ldoc/prettify.lua @@ -4,9 +4,7 @@ -- A module reference to an example `test-fun.lua` would look like -- `@{example:test-fun}`. local List = require 'pl.List' -local lexer = require 'ldoc.lexer' local globals = require 'ldoc.builtin.globals' -local tnext = lexer.skipws local prettify = {} local escaped_chars = { @@ -26,14 +24,23 @@ end local spans = {keyword=true,number=true,string=true,comment=true,global=true,backtick=true} -function prettify.lua (fname, code, initial_lineno, pre) - local res = List() +local cpp_lang = {c = true, cpp = true, cxx = true, h = true} + +function prettify.lua (lang, fname, code, initial_lineno, pre) + local res, lexer, tokenizer = List(), require 'ldoc.lexer' + local tnext = lexer.skipws + if not cpp_lang[lang] then + tokenizer = lexer.lua + else + tokenizer = lexer.cpp + end + if pre then res:append '
\n' end initial_lineno = initial_lineno or 0 - local tok = lexer.lua(code,{},{}) + local tok = tokenizer(code,{},{}) local error_reporter = { warning = function (self,msg) io.stderr:write(fname..':'..tok:lineno()+initial_lineno..': '..msg,'\n') @@ -72,7 +79,7 @@ local lxsh_highlighers = {bib=true,c=true,lua=true,sh=true} function prettify.code (lang,fname,code,initial_lineno,pre) if not lxsh then - return prettify.lua (fname, code, initial_lineno, pre) + return prettify.lua (lang,fname, code, initial_lineno, pre) else if not lxsh_highlighers[lang] then lang = 'lua'