add multiline comments
This commit is contained in:
parent
97f5792a75
commit
6b64e61537
@ -294,7 +294,7 @@ local function prefixCode(code, fn) -- fix strings, add line numbers
|
|||||||
local function out(c) assert(type(c)=="string"); table.insert(outt, c); end
|
local function out(c) assert(type(c)=="string"); table.insert(outt, c); end
|
||||||
local function outn(n) out("$"..string.format("%02X", n)) out("\\") end
|
local function outn(n) out("$"..string.format("%02X", n)) out("\\") end
|
||||||
local function outnext(c) assert(type(c)=="string"); table.insert(outnextnl, c); end
|
local function outnext(c) assert(type(c)=="string"); table.insert(outnextnl, c); end
|
||||||
local state = "code" -- code, comment, string, stringesc
|
local state = "code" -- code, comment, string, stringesc, commentml
|
||||||
|
|
||||||
local lastbracelabel = 0
|
local lastbracelabel = 0
|
||||||
local function bracelabel() lastbracelabel = lastbracelabel+1; return "_BRACE_"..lastbracelabel.."_"; end
|
local function bracelabel() lastbracelabel = lastbracelabel+1; return "_BRACE_"..lastbracelabel.."_"; end
|
||||||
@ -306,10 +306,11 @@ local function prefixCode(code, fn) -- fix strings, add line numbers
|
|||||||
for i = 1, #code do
|
for i = 1, #code do
|
||||||
local c = code:sub(i, i)
|
local c = code:sub(i, i)
|
||||||
local cn = code:sub(i+1, i+1)
|
local cn = code:sub(i+1, i+1)
|
||||||
|
local cp = code:sub(i-1, i-1)
|
||||||
|
|
||||||
if state=="code" then
|
if state=="code" then
|
||||||
if c=="\r" then
|
if c=="\r" then
|
||||||
elseif c=="\n" or (c=="/" and cn~="/") then
|
elseif c=="\n" or (c=="/" and cn~="/" and cn~="*") then
|
||||||
linenum = linenum+1
|
linenum = linenum+1
|
||||||
if not skipnl then out("\n") out(".ln "..linenum); out("\n"); end
|
if not skipnl then out("\n") out(".ln "..linenum); out("\n"); end
|
||||||
lastnl = true
|
lastnl = true
|
||||||
@ -319,6 +320,7 @@ local function prefixCode(code, fn) -- fix strings, add line numbers
|
|||||||
end; outnextnl = {};
|
end; outnextnl = {};
|
||||||
skipnl = false
|
skipnl = false
|
||||||
elseif c=="#" or c==";" or (c=="/" and cn=="/") then state = "comment"
|
elseif c=="#" or c==";" or (c=="/" and cn=="/") then state = "comment"
|
||||||
|
elseif c=="/" and cn=="*" then state = "commentml"
|
||||||
elseif c=="\t" or c==" " then if (not lastnl) then out(" ") end
|
elseif c=="\t" or c==" " then if (not lastnl) then out(" ") end
|
||||||
elseif c=="\"" then state = "string" lastnl = false
|
elseif c=="\"" then state = "string" lastnl = false
|
||||||
elseif c=="\\" then skipnl = true; out("\\");
|
elseif c=="\\" then skipnl = true; out("\\");
|
||||||
@ -341,6 +343,9 @@ local function prefixCode(code, fn) -- fix strings, add line numbers
|
|||||||
else error("invalid char "..c) end
|
else error("invalid char "..c) end
|
||||||
elseif state=="comment" then
|
elseif state=="comment" then
|
||||||
if c=="\n" then state = "code" out("\n") lastnl = true end
|
if c=="\n" then state = "code" out("\n") lastnl = true end
|
||||||
|
elseif state=="commentml" then
|
||||||
|
print(c)
|
||||||
|
if c=="/" and cp=="*" then state = "code" end
|
||||||
elseif state=="string" then
|
elseif state=="string" then
|
||||||
if c=="\\" then state = "stringesc"
|
if c=="\\" then state = "stringesc"
|
||||||
elseif c=="\"" then state = "code"
|
elseif c=="\"" then state = "code"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user