From db8facdb5f913a0bab786e7e22a658d9f538767d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20M=C3=BCller?= Date: Thu, 30 Sep 2010 23:33:06 +0200 Subject: [PATCH] - Added: handle start of one-line comments and long comments --- pret-pas.lua | 47 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/pret-pas.lua b/pret-pas.lua index 0288327..6e4145f 100644 --- a/pret-pas.lua +++ b/pret-pas.lua @@ -98,7 +98,8 @@ end end]] function visualizer.flush_line(str, nested) - local state, word = 0, nil + local state, word, lastc = 0, nil, nil + local incomment = false buffers.currentcolors = colors --[[ @@ -116,6 +117,7 @@ function visualizer.flush_line(str, nested) ]] --state = buffers.changestate(1, state) + --TODO: handle inlongcomment etc. for c in string.utfcharacters(str) do if string.find(c, "^[%a_]$") then -- char belongs to identifier @@ -130,31 +132,64 @@ function visualizer.flush_line(str, nested) word = word .. c else -- number - state = buffers.changestate(3, state) + if not incomment then + state = buffers.changestate(3, state) + end tex.write(c) end else + if not incomment then + state = buffers.finishstate(state) + end flush_pas_word(word) word = nil if c == " " then - state = buffers.finishstate(state) + --state = buffers.finishstate(state) tex.sprint(tex.ctxcatcodes, "\\obs") elseif c == "\t" then - state = buffers.finishstate(state) + --state = buffers.finishstate(state) tex.sprint(tex.ctxcatcodes, "\\obs") if buffers.visualizers.enabletab then tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength)) end + elseif c == "/" then + if lastc == "/" then + if not incomment then + -- one-line comment starts + incomment = true + state = buffers.changestate(3, state) + tex.sprint(tex.ctxcatcodes, "\{\\bf") + end + tex.write("//") + end + elseif c == "{" then + if not incomment then + -- long comment starts + incomment = true + inlongcomment = true + state = buffers.changestate(3, state) + tex.sprint(tex.ctxcatcodes, "\{\\bf") + end + tex.write(c) + -- TODO: (*, asm, {$, ' else -- symbol - state = buffers.changestate(1, state) + if not incomment then + state = buffers.changestate(1, state) + end tex.write(c) end end + lastc = c + end + if not incomment then state = buffers.finishstate(state) end flush_pas_word(word) - word = nil + if incomment then + tex.sprint(tex.ctxcatcodes, "\}") + end + --word = nil --[[ local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$")