- Code clean-up

This commit is contained in:
Stefan Müller 2010-10-02 15:24:29 +02:00
parent 21a95c7986
commit e8dccbf5d8
1 changed files with 0 additions and 213 deletions

View File

@ -58,13 +58,6 @@ local colors = {
"prettyfour", -- yellow
}
local states = {
['"']=1, ["'"]=1, ["[["] = 1, ["]]"] = 1,
['+']=1, ['-']=1, ['*']=1, ['/']=1, ['%']=1, ['^']=1,
["("] = 3, [")"] = 3, ["["] = 3, ["]"] = 3,
['--']=4,
}
local reserved_style = "\{\\bf "
local comment_style = "\{\\sl "
@ -122,61 +115,12 @@ function visualizer.reset()
inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
end
--[[local function written(state, c, i)
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 ",i%buffers.visualizers.tablength))
end
else
tex.write(c)
end
return state, 0
end]]
function visualizer.flush_line(str, nested)
local state = 0
local incomment, instring = false, false
--local code, comment = nil, nil
buffers.currentcolors = colors
--[[
print("SEARCHING FOR IDENTIFIERS IN: " .. str)
local remain = str
local identifier
repeat
identifier = nil
identifier, remain = string.match(remain, "^[^%a_]*([%a_]+[%a%d_]*)(.*)$")
if identifier then
print("IDENTIFIER: " .. identifier)
--print("REMAIN: " .. remain)
end
until not identifier
]]
--TODO: handle inlongcomment etc.
--[[
if inlongcomment then
comment, code = string.match(str,"^(.-})(.*)$")
if not comment then
comment = str
end
state = buffers.changestate(3, state)
tex.sprint(tex.ctxcatcodes, "\{\\bf")
flush_whatever(comment)
tex.sprint(tex.ctxcatcodes, "\}")
if code then
inlongcomment = false
else
code = ""
end
else
code = str
end
]]
if inlongcomment or (inlongcomment_alt == 2) or incompdirec then
incomment = true
if incompdirec then
@ -312,161 +256,4 @@ function visualizer.flush_line(str, nested)
tex.sprint(tex.ctxcatcodes, "\}")
end
state = buffers.finishstate(state)
--[[
local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$")
if comment then
-- process the code and then flush the comment
elseif incomment then
comment, code = string.match(str,"^(.-)%]%](.*)$")
if comment then
-- flush the comment and then process the code
for c in string.utfcharacters(comment) do
if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
end
state = buffers.changestate(states['--'], state)
tex.write("KKK")
state = buffers.finishstate(state)
incomment = false
else
for c in string.utfcharacters(str) do
if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
end
end
comment = nil
else
code = str
end
if code and code ~= "" then
local pre, post = string.match(code,"^(.-)%-%-(.*)$")
if pre then
code = pre
end
local p, s, i = nil, nil, 0
for c in string.utfcharacters(code) do
i = i + 1
if instr then
if p then
tex.write(p)
p = nil
end
if c == s then
if inesc then
tex.write(c)
inesc = false
else
state = buffers.changestate(states[c],state)
instr = false
tex.write(c)
state = buffers.finishstate(state)
end
s = nil
else
if c == "\\" then
inesc = not inesc
else
inesc = false
end
state, i = written(state,c,i)
end
elseif c == "[" then
if word then
tex.write(word)
word = nil
end
if p == "[" then
inlongstring = true
state = buffers.changestate(states["NRA"],state)
tex.write(p,c)
state = buffers.finishstate(state)
p = nil
else
if p then
state, i = written(state,p,i)
end
p = c
end
elseif c == "]" then
if word then
tex.write(word)
word = nil
end
if p == "]" then
inlongstring = false
state = buffers.changestate(states["KKK"],state)
tex.write(p,c)
state = buffers.finishstate(state)
p = nil
else
if p then
state, i = written(state,p,i)
end
p = c
end
else
if p then
state = buffers.changestate(states[p],state)
tex.write(p)
state = buffers.finishstate(state)
p = nil
end
if c == " " or c == "\t" then
if word then
flush_pas_word(word)
word = nil
end
state, i = written(state,c,i)
elseif inlongstring then
state, i = written(state,c,i)
elseif c == '"' or c == "'" then
if word then
flush_pas_word(word)
word = nil
end
instr = true
state = buffers.changestate(states[c],state)
state, i = written(state,c,i)
state = buffers.finishstate(state)
s = c
elseif string.find(c,"^[%a]$") then
state = buffers.finishstate(state)
if word then word = word .. c else word = c end
elseif word and (#word > 1) and string.find(c,"^[%d%.%_]$") then
if word then word = word .. c else word = c end
else
flush_pas_word(word)
word = nil
state = buffers.changestate(states[c],state)
tex.write(c)
instr = (c == '"')
end
end
end
if p then
tex.write(p)
-- state, i = written(state,p,i)
p = nil
end
flush_pas_word(word)
if post then
state = buffers.changestate(states['--'], state)
tex.write("--")
state = buffers.finishstate(state)
for c in string.utfcharacters(post) do
state, i = written(state,c,i)
end
end
end
if comment then
incomment = true
state = buffers.changestate(states['--'], state)
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