- 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:
Stefan Müller 2010-09-29 23:39:58 +02:00
parent 470053a135
commit 19107ca30a
1 changed files with 48 additions and 25 deletions

View File

@ -45,9 +45,9 @@ for k,v in next, visualizer.reservedwords do
end end
local colors = { local colors = {
"prettyone", -- red "prettyone", -- red: compiler directive, symbol
"prettytwo", -- green "prettytwo", -- green: assembler (dark green)
"prettythree", -- blue "prettythree", -- blue: comment, number (dark blue)
"prettyfour", -- yellow "prettyfour", -- yellow
} }
@ -99,29 +99,51 @@ function visualizer.flush_line(str, nested)
local state, instr, inesc, word = 0, false, false, nil local state, instr, inesc, word = 0, false, false, nil
buffers.currentcolors = colors buffers.currentcolors = colors
--[[ --state = buffers.changestate(1, state)
local identifier = nil for c in string.utfcharacters(str) do
for c in string.string.utfcharacters(str) do if string.find(c, "^[%a%_]$") then
if string.string.string.find(c, "^[%a%_]$") then -- char belongs to identifier
if identifier then if word then
identifier = identifier .. c word = word .. c
else else
identifier = c word = c
end end
elseif string.string.string.find(c, "^[%d]$") --state = buffers.changestate(2, state)
if identifier and #identifier > 1 then elseif string.find(c, "^[%d]$") then
identifier = identifier .. c 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 end
elseif --state = buffers.changestate(3, state)
--flush_pas_word(identifier) else
identifier = nil 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 end
tex.write("p") else
-- symbol
state = buffers.changestate(1, state)
tex.write(c)
end end
--flush_pas_word(identifier) end
identifier = nil --tex.write(c)
]] state = buffers.finishstate(state)
end
flush_pas_word(word)
word = nil
--[[
local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$") local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$")
if comment then if comment then
-- process the code and then flush the comment -- 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 if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
end end
state = buffers.changestate(states['--'], state) state = buffers.changestate(states['--'], state)
tex.write("]]") tex.write("KKK")
state = buffers.finishstate(state) state = buffers.finishstate(state)
incomment = false incomment = false
else else
@ -184,7 +206,7 @@ function visualizer.flush_line(str, nested)
end end
if p == "[" then if p == "[" then
inlongstring = true inlongstring = true
state = buffers.changestate(states["[["],state) state = buffers.changestate(states["NRA"],state)
tex.write(p,c) tex.write(p,c)
state = buffers.finishstate(state) state = buffers.finishstate(state)
p = nil p = nil
@ -201,7 +223,7 @@ function visualizer.flush_line(str, nested)
end end
if p == "]" then if p == "]" then
inlongstring = false inlongstring = false
state = buffers.changestate(states["]]"],state) state = buffers.changestate(states["KKK"],state)
tex.write(p,c) tex.write(p,c)
state = buffers.finishstate(state) state = buffers.finishstate(state)
p = nil p = nil
@ -268,12 +290,13 @@ function visualizer.flush_line(str, nested)
if comment then if comment then
incomment = true incomment = true
state = buffers.changestate(states['--'], state) state = buffers.changestate(states['--'], state)
tex.write("[[") tex.write("NRA")
state = buffers.finishstate(state) state = buffers.finishstate(state)
-- tex.write(comment) -- maybe also split and -- tex.write(comment) -- maybe also split and
for c in string.utfcharacters(comment) do for c in string.utfcharacters(comment) do
state, i = written(state,c,i) state, i = written(state,c,i)
end end
end end
]]
state = buffers.finishstate(state) state = buffers.finishstate(state)
end end