- 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
} }
@ -79,7 +79,7 @@ function visualizer.reset()
incompdirec, inasm = false, false incompdirec, inasm = false, false
end end
local function written(state,c,i) local function written(state, c, i)
if c == " " then if c == " " then
state = buffers.finishstate(state) state = buffers.finishstate(state)
tex.sprint(tex.ctxcatcodes,"\\obs") tex.sprint(tex.ctxcatcodes,"\\obs")
@ -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
--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
else
-- symbol
state = buffers.changestate(1, state)
tex.write(c)
end end
elseif
--flush_pas_word(identifier)
identifier = nil
end end
tex.write("p") --tex.write(c)
state = buffers.finishstate(state)
end end
--flush_pas_word(identifier) flush_pas_word(word)
identifier = nil 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