version bump; underscore escaping fix for backticks; horrible workaround for deficiencies of C lexer
steve donovan
9 years ago
258 | 258 | local err |
259 | 259 | f,err = utils.readfile(f) |
260 | 260 | if not f then quit(err) end |
261 | return lexer.cpp(f,{}) | |
261 | return lexer.cpp(f,{},nil,true) | |
262 | 262 | end |
263 | 263 | |
264 | 264 | function CC:grab_block_comment(v,tok) |
43 | 43 | local STRING3 = "^((['\"])%2)" -- empty string |
44 | 44 | local PREPRO = '^#.-[^\\]\n' |
45 | 45 | |
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 | |
47 | 47 | |
48 | 48 | local function tdump(tok) |
49 | 49 | return tok,tok |
323 | 323 | -- @param filter a table of token types to exclude, by default {space=true,comments=true} |
324 | 324 | -- @param options a table of options; by default, {number=true,string=true}, |
325 | 325 | -- which means convert numbers and strip string quotes. |
326 | function lexer.cpp(s,filter,options) | |
326 | function lexer.cpp(s,filter,options,no_string) | |
327 | 327 | filter = filter or {comments=true} |
328 | 328 | if not cpp_keyword then |
329 | 329 | cpp_keyword = { |
349 | 349 | {IDEN,cpp_vdump}, |
350 | 350 | {NUMBER4,ndump}, |
351 | 351 | {NUMBER5,ndump}, |
352 | -- {STRING3,sdump}, | |
353 | -- {STRING1,chdump}, | |
354 | -- {STRING2,sdump}, | |
352 | {STRING3,sdump}, | |
353 | {STRING1,chdump}, | |
354 | {STRING2,sdump}, | |
355 | 355 | {'^//.-\n',cdump}, |
356 | 356 | {'^/%*.-%*/',cdump}, |
357 | 357 | {'^==',tdump}, |
374 | 374 | {'^.',tdump} |
375 | 375 | } |
376 | 376 | 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) | |
378 | 410 | end |
379 | 411 | |
380 | 412 | --- get a list of parameters separated by a delimiter from a stream. |
53 | 53 | if backtick_references then |
54 | 54 | res = res:gsub('`([^`]+)`',function(name) |
55 | 55 | local ref,err = markup.process_reference(name) |
56 | local label = name | |
57 | if name and do_escape then | |
58 | label = name:gsub('_', '\\_') | |
59 | end | |
56 | 60 | 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) | |
61 | 62 | else |
62 | return '<code>'..name..'</code>' | |
63 | return '<code>'..label..'</code>' | |
63 | 64 | end |
64 | 65 | end) |
65 | 66 | end |
116 | 117 | -- - prettify any code blocks |
117 | 118 | |
118 | 119 | 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 | |
120 | 121 | local err_item = { |
121 | 122 | warning = function (self,msg) |
122 | 123 | io.stderr:write(filename..':'..L..': '..msg,'\n') |
132 | 133 | if code ~= '' then |
133 | 134 | local err |
134 | 135 | -- 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. | |
136 | 137 | code, err = prettify.code(lang,filename,code..'\n',L,false) |
137 | 138 | code = resolve_inline_references(ldoc, code, err_item,true) |
138 | 139 | append(res,'<pre>') |
307 | 308 | -- AFAIK only markdown.lua has underscore-in-identifier problem... |
308 | 309 | if ldoc.dont_escape_underscore ~= nil then |
309 | 310 | ldoc.dont_escape_underscore = actual_format ~= 'markdown' |
310 | end | |
311 | end | |
311 | 312 | return markdown_processor(ldoc, formatter) |
312 | 313 | end |
313 | 314 |