From 6b64e6153721d1970d1ba5d977fb9f040d65aad7 Mon Sep 17 00:00:00 2001 From: Redo Date: Wed, 2 Nov 2022 11:42:01 -0600 Subject: [PATCH] add multiline comments --- assembler-8608.lua | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/assembler-8608.lua b/assembler-8608.lua index f8294c3..7b7e216 100644 --- a/assembler-8608.lua +++ b/assembler-8608.lua @@ -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 outn(n) out("$"..string.format("%02X", n)) out("\\") 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 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 local c = code:sub(i, i) local cn = code:sub(i+1, i+1) + local cp = code:sub(i-1, i-1) if state=="code" then - if c=="\r" then - elseif c=="\n" or (c=="/" and cn~="/") then + if c=="\r" then + elseif c=="\n" or (c=="/" and cn~="/" and cn~="*") then linenum = linenum+1 if not skipnl then out("\n") out(".ln "..linenum); out("\n"); end lastnl = true @@ -319,6 +320,7 @@ local function prefixCode(code, fn) -- fix strings, add line numbers end; outnextnl = {}; skipnl = false 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=="\"" then state = "string" lastnl = false 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 elseif state=="comment" then 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 if c=="\\" then state = "stringesc" elseif c=="\"" then state = "code"