- Added: handle start of one-line comments and long comments
This commit is contained in:
parent
7f7c0f07d7
commit
db8facdb5f
43
pret-pas.lua
43
pret-pas.lua
|
@ -98,7 +98,8 @@ end
|
||||||
end]]
|
end]]
|
||||||
|
|
||||||
function visualizer.flush_line(str, nested)
|
function visualizer.flush_line(str, nested)
|
||||||
local state, word = 0, nil
|
local state, word, lastc = 0, nil, nil
|
||||||
|
local incomment = false
|
||||||
buffers.currentcolors = colors
|
buffers.currentcolors = colors
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
|
@ -116,6 +117,7 @@ function visualizer.flush_line(str, nested)
|
||||||
]]
|
]]
|
||||||
|
|
||||||
--state = buffers.changestate(1, state)
|
--state = buffers.changestate(1, state)
|
||||||
|
--TODO: handle inlongcomment etc.
|
||||||
for c in string.utfcharacters(str) do
|
for c in string.utfcharacters(str) do
|
||||||
if string.find(c, "^[%a_]$") then
|
if string.find(c, "^[%a_]$") then
|
||||||
-- char belongs to identifier
|
-- char belongs to identifier
|
||||||
|
@ -130,31 +132,64 @@ function visualizer.flush_line(str, nested)
|
||||||
word = word .. c
|
word = word .. c
|
||||||
else
|
else
|
||||||
-- number
|
-- number
|
||||||
|
if not incomment then
|
||||||
state = buffers.changestate(3, state)
|
state = buffers.changestate(3, state)
|
||||||
|
end
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
if not incomment then
|
||||||
|
state = buffers.finishstate(state)
|
||||||
|
end
|
||||||
flush_pas_word(word)
|
flush_pas_word(word)
|
||||||
word = nil
|
word = nil
|
||||||
if c == " " then
|
if c == " " then
|
||||||
state = buffers.finishstate(state)
|
--state = buffers.finishstate(state)
|
||||||
tex.sprint(tex.ctxcatcodes, "\\obs")
|
tex.sprint(tex.ctxcatcodes, "\\obs")
|
||||||
elseif c == "\t" then
|
elseif c == "\t" then
|
||||||
state = buffers.finishstate(state)
|
--state = buffers.finishstate(state)
|
||||||
tex.sprint(tex.ctxcatcodes, "\\obs")
|
tex.sprint(tex.ctxcatcodes, "\\obs")
|
||||||
if buffers.visualizers.enabletab then
|
if buffers.visualizers.enabletab then
|
||||||
tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength))
|
tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength))
|
||||||
end
|
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
|
else
|
||||||
-- symbol
|
-- symbol
|
||||||
|
if not incomment then
|
||||||
state = buffers.changestate(1, state)
|
state = buffers.changestate(1, state)
|
||||||
|
end
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
lastc = c
|
||||||
|
end
|
||||||
|
if not incomment then
|
||||||
state = buffers.finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
end
|
end
|
||||||
flush_pas_word(word)
|
flush_pas_word(word)
|
||||||
word = nil
|
if incomment then
|
||||||
|
tex.sprint(tex.ctxcatcodes, "\}")
|
||||||
|
end
|
||||||
|
--word = nil
|
||||||
|
|
||||||
--[[
|
--[[
|
||||||
local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$")
|
local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$")
|
||||||
|
|
Loading…
Reference in New Issue