- Added: pretty printing of asm code blocks

This commit is contained in:
Stefan Müller 2010-10-02 15:23:10 +02:00
parent 790f4465ff
commit 21a95c7986
1 changed files with 56 additions and 24 deletions

View File

@ -68,17 +68,37 @@ local states = {
local reserved_style = "\{\\bf "
local comment_style = "\{\\sl "
local function flush_pas_word(word)
local inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
local function flush_pas_word(word, state)
if word then
local id = known_words[string.lower(word)]
local lword = string.lower(word)
local id = known_words[lword]
if id then
if inasm and (lword == "end") then
-- asm mode ends
state = buffers.finishstate(state)
inasm = false
print("leave asm")
end
if not inasm then
tex.sprint(tex.ctxcatcodes, reserved_style)
tex.write(word)
tex.sprint(tex.ctxcatcodes, "\}")
if lword == "asm" then
-- asm mode begins
print("enter asm")
inasm = true
state = buffers.changestate(2, state)
end
else
tex.write(word)
end
else
tex.write(word)
end
end
return state
end
local function flush_whatever(str)
@ -98,8 +118,6 @@ local function flush_whatever(str)
end
end
local inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
function visualizer.reset()
inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
end
@ -167,6 +185,8 @@ function visualizer.flush_line(str, nested)
state = buffers.changestate(3, state)
end
tex.sprint(tex.ctxcatcodes, comment_style)
elseif inasm then
state = buffers.changestate(2, state)
end
local c, word = nil, nil
@ -188,7 +208,12 @@ function visualizer.flush_line(str, nested)
-- long comment/(alternative)/compiler directive ends
tex.write(c)
tex.sprint(tex.ctxcatcodes, "\}")
if inasm then
-- resume to asm mode
state = buffers.changestate(2, state)
else
state = buffers.finishstate(state)
end
incompdirec = false
inlongcomment = false
inlongcomment_alt = 0
@ -213,14 +238,18 @@ function visualizer.flush_line(str, nested)
-- number, that belongs to identifier
word = word .. c
else
if not inasm then
-- number
state = buffers.changestate(3, state)
end
tex.write(c)
end
else
if not inasm then
state = buffers.finishstate(state)
end
-- identifier complete, check if it's a reserved word and flush
flush_pas_word(word)
state = flush_pas_word(word, state)
word = nil
if c == " " then
tex.sprint(tex.ctxcatcodes, "\\obs")
@ -230,12 +259,14 @@ function visualizer.flush_line(str, nested)
tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength))
end
elseif c == "'" then
-- string starts
if not inasm then
-- string begins
instring = true
state = buffers.changestate(3, state)
end
tex.write(c)
elseif (c == "/") and (nextc == "/") then
-- one-line comment starts
-- one-line comment begins
incomment = true
state = buffers.changestate(3, state)
tex.sprint(tex.ctxcatcodes, comment_style)
@ -243,38 +274,39 @@ function visualizer.flush_line(str, nested)
elseif c == "{" then
incomment = true
if nextc == "$" then
-- compiler directive starts
-- compiler directive begins
incompdirec = true
state = buffers.changestate(1, state)
else
-- long comment starts
-- long comment begins
inlongcomment = true
state = buffers.changestate(3, state)
end
tex.sprint(tex.ctxcatcodes, comment_style)
tex.write(c)
elseif (c == "(") and (nextc == "*") then
-- long comment (alternative) starts
-- long comment (alternative) begins
incomment = true
inlongcomment_alt = 2
state = buffers.changestate(3, state)
tex.sprint(tex.ctxcatcodes, comment_style)
tex.write(c)
-- TODO: asm
else
if not inasm then
-- symbol
state = buffers.changestate(1, state)
end
tex.write(c)
end
end
end
c = nextc
end
if not incomment then
if not incomment and not inasm then
state = buffers.finishstate(state)
end
-- maybe something left, check if it's a reserved word and flush
flush_pas_word(word)
state = flush_pas_word(word, state)
if incomment then
-- end the comment-line
tex.sprint(tex.ctxcatcodes, "\}")