_properly_ handle arb Lua block comments; now passes the embedded block comment test
steve donovan
12 years ago
28 | 28 |
|
29 | 29 |
function Lang:grab_block_comment(v,tok)
|
30 | 30 |
v = v:gsub(self.block_comment,'')
|
31 | |
return tools.grab_block_comment(v,tok,self.end_block1,self.end_block2)
|
|
31 |
return tools.grab_block_comment(v,tok,self.end_comment)
|
32 | 32 |
end
|
33 | 33 |
|
34 | 34 |
function Lang:find_module(tok,t,v)
|
|
61 | 61 |
self.line_comment = '^%-%-+' -- used for stripping
|
62 | 62 |
self.start_comment_ = '^%-%-%-+' -- used for doc comment line start
|
63 | 63 |
self.block_comment = '^%-%-%[=*%[%-+' -- used for block doc comments
|
64 | |
self.end_block1 = ']'
|
65 | |
self.end_block2 = ']'
|
66 | 64 |
self:finalize()
|
67 | 65 |
end
|
68 | 66 |
|
|
71 | 69 |
if not f then quit(e) end
|
72 | 70 |
return lexer.lua(f,{}),f
|
73 | 71 |
end
|
|
72 |
|
|
73 |
function Lua:grab_block_comment(v,tok)
|
|
74 |
local equals = v:match('^%-%-%[(=*)%[')
|
|
75 |
v = v:gsub(self.block_comment,'')
|
|
76 |
return tools.grab_block_comment(v,tok,'%]'..equals..'%]')
|
|
77 |
end
|
|
78 |
|
74 | 79 |
|
75 | 80 |
function Lua:parse_module_call(tok,t,v)
|
76 | 81 |
t,v = tnext(tok)
|
|
166 | 171 |
end
|
167 | 172 |
end
|
168 | 173 |
|
|
174 |
-- note a difference here: we scan C/C++ code in full-text mode, not line by line.
|
|
175 |
-- This is because we can't detect multiline comments in line mode
|
169 | 176 |
|
170 | 177 |
class.CC(Lang)
|
171 | 178 |
|
326 | 326 |
-- The PL Lua lexer does not do block comments
|
327 | 327 |
-- when used in line-grabbing mode, so this function grabs each line
|
328 | 328 |
-- until we meet the end of the comment
|
329 | |
function M.grab_block_comment (v,tok,end1,end2)
|
|
329 |
function M.grab_block_comment (v,tok,patt)
|
330 | 330 |
local res = {v}
|
331 | 331 |
repeat
|
332 | 332 |
v = lexer.getline(tok)
|
333 | |
if v:match '%]=*%]' then break end
|
|
333 |
if v:match (patt) then break end
|
334 | 334 |
append(res,v)
|
335 | 335 |
append(res,'\n')
|
336 | 336 |
until false
|