- Updated: recognition of identifiers (checked for being reserved words)
- Added: numbers not belonging to identifiers typeset blue - Added: symbols typeset red
This commit is contained in:
parent
470053a135
commit
19107ca30a
71
pret-pas.lua
71
pret-pas.lua
|
@ -45,9 +45,9 @@ for k,v in next, visualizer.reservedwords do
|
|||
end
|
||||
|
||||
local colors = {
|
||||
"prettyone", -- red
|
||||
"prettytwo", -- green
|
||||
"prettythree", -- blue
|
||||
"prettyone", -- red: compiler directive, symbol
|
||||
"prettytwo", -- green: assembler (dark green)
|
||||
"prettythree", -- blue: comment, number (dark blue)
|
||||
"prettyfour", -- yellow
|
||||
}
|
||||
|
||||
|
@ -99,29 +99,51 @@ function visualizer.flush_line(str, nested)
|
|||
local state, instr, inesc, word = 0, false, false, nil
|
||||
buffers.currentcolors = colors
|
||||
|
||||
--[[
|
||||
local identifier = nil
|
||||
for c in string.string.utfcharacters(str) do
|
||||
if string.string.string.find(c, "^[%a%_]$") then
|
||||
if identifier then
|
||||
identifier = identifier .. c
|
||||
--state = buffers.changestate(1, state)
|
||||
for c in string.utfcharacters(str) do
|
||||
if string.find(c, "^[%a%_]$") then
|
||||
-- char belongs to identifier
|
||||
if word then
|
||||
word = word .. c
|
||||
else
|
||||
identifier = c
|
||||
word = c
|
||||
end
|
||||
elseif string.string.string.find(c, "^[%d]$")
|
||||
if identifier and #identifier > 1 then
|
||||
identifier = identifier .. c
|
||||
--state = buffers.changestate(2, state)
|
||||
elseif string.find(c, "^[%d]$") then
|
||||
if word and (#word > 1) then
|
||||
-- number, that belongs to identifier
|
||||
word = word .. c
|
||||
else
|
||||
-- number
|
||||
state = buffers.changestate(3, state)
|
||||
tex.write(c)
|
||||
end
|
||||
elseif
|
||||
--flush_pas_word(identifier)
|
||||
identifier = nil
|
||||
--state = buffers.changestate(3, state)
|
||||
else
|
||||
flush_pas_word(word)
|
||||
word = nil
|
||||
if c == " " then
|
||||
state = buffers.finishstate(state)
|
||||
tex.sprint(tex.ctxcatcodes,"\\obs")
|
||||
elseif c == "\t" then
|
||||
state = buffers.finishstate(state)
|
||||
tex.sprint(tex.ctxcatcodes,"\\obs")
|
||||
if buffers.visualizers.enabletab then
|
||||
tex.sprint(tex.ctxcatcodes,rep("\\obs ",buffers.visualizers.tablength))
|
||||
end
|
||||
tex.write("p")
|
||||
else
|
||||
-- symbol
|
||||
state = buffers.changestate(1, state)
|
||||
tex.write(c)
|
||||
end
|
||||
--flush_pas_word(identifier)
|
||||
identifier = nil
|
||||
]]
|
||||
end
|
||||
--tex.write(c)
|
||||
state = buffers.finishstate(state)
|
||||
end
|
||||
flush_pas_word(word)
|
||||
word = nil
|
||||
|
||||
--[[
|
||||
local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$")
|
||||
if comment then
|
||||
-- process the code and then flush the comment
|
||||
|
@ -133,7 +155,7 @@ function visualizer.flush_line(str, nested)
|
|||
if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
|
||||
end
|
||||
state = buffers.changestate(states['--'], state)
|
||||
tex.write("]]")
|
||||
tex.write("KKK")
|
||||
state = buffers.finishstate(state)
|
||||
incomment = false
|
||||
else
|
||||
|
@ -184,7 +206,7 @@ function visualizer.flush_line(str, nested)
|
|||
end
|
||||
if p == "[" then
|
||||
inlongstring = true
|
||||
state = buffers.changestate(states["[["],state)
|
||||
state = buffers.changestate(states["NRA"],state)
|
||||
tex.write(p,c)
|
||||
state = buffers.finishstate(state)
|
||||
p = nil
|
||||
|
@ -201,7 +223,7 @@ function visualizer.flush_line(str, nested)
|
|||
end
|
||||
if p == "]" then
|
||||
inlongstring = false
|
||||
state = buffers.changestate(states["]]"],state)
|
||||
state = buffers.changestate(states["KKK"],state)
|
||||
tex.write(p,c)
|
||||
state = buffers.finishstate(state)
|
||||
p = nil
|
||||
|
@ -268,12 +290,13 @@ function visualizer.flush_line(str, nested)
|
|||
if comment then
|
||||
incomment = true
|
||||
state = buffers.changestate(states['--'], state)
|
||||
tex.write("[[")
|
||||
tex.write("NRA")
|
||||
state = buffers.finishstate(state)
|
||||
-- tex.write(comment) -- maybe also split and
|
||||
for c in string.utfcharacters(comment) do
|
||||
state, i = written(state,c,i)
|
||||
end
|
||||
end
|
||||
]]
|
||||
state = buffers.finishstate(state)
|
||||
end
|
Loading…
Reference in New Issue