- Added: handle start of one-line comments and long comments
This commit is contained in:
parent
7f7c0f07d7
commit
db8facdb5f
47
pret-pas.lua
47
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,"^(.-)%-%-%[%[(.*)$")
|
||||
|
|
Loading…
Reference in New Issue