- Added: pretty printing of asm code blocks
This commit is contained in:
parent
790f4465ff
commit
21a95c7986
58
pret-pas.lua
58
pret-pas.lua
|
@ -68,17 +68,37 @@ local states = {
|
||||||
local reserved_style = "\{\\bf "
|
local reserved_style = "\{\\bf "
|
||||||
local comment_style = "\{\\sl "
|
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
|
if word then
|
||||||
local id = known_words[string.lower(word)]
|
local lword = string.lower(word)
|
||||||
|
local id = known_words[lword]
|
||||||
if id then
|
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.sprint(tex.ctxcatcodes, reserved_style)
|
||||||
tex.write(word)
|
tex.write(word)
|
||||||
tex.sprint(tex.ctxcatcodes, "\}")
|
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
|
else
|
||||||
tex.write(word)
|
tex.write(word)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return state
|
||||||
end
|
end
|
||||||
|
|
||||||
local function flush_whatever(str)
|
local function flush_whatever(str)
|
||||||
|
@ -98,8 +118,6 @@ local function flush_whatever(str)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
|
|
||||||
|
|
||||||
function visualizer.reset()
|
function visualizer.reset()
|
||||||
inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
|
inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
|
||||||
end
|
end
|
||||||
|
@ -167,6 +185,8 @@ function visualizer.flush_line(str, nested)
|
||||||
state = buffers.changestate(3, state)
|
state = buffers.changestate(3, state)
|
||||||
end
|
end
|
||||||
tex.sprint(tex.ctxcatcodes, comment_style)
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
||||||
|
elseif inasm then
|
||||||
|
state = buffers.changestate(2, state)
|
||||||
end
|
end
|
||||||
|
|
||||||
local c, word = nil, nil
|
local c, word = nil, nil
|
||||||
|
@ -188,7 +208,12 @@ function visualizer.flush_line(str, nested)
|
||||||
-- long comment/(alternative)/compiler directive ends
|
-- long comment/(alternative)/compiler directive ends
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
tex.sprint(tex.ctxcatcodes, "\}")
|
tex.sprint(tex.ctxcatcodes, "\}")
|
||||||
|
if inasm then
|
||||||
|
-- resume to asm mode
|
||||||
|
state = buffers.changestate(2, state)
|
||||||
|
else
|
||||||
state = buffers.finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
|
end
|
||||||
incompdirec = false
|
incompdirec = false
|
||||||
inlongcomment = false
|
inlongcomment = false
|
||||||
inlongcomment_alt = 0
|
inlongcomment_alt = 0
|
||||||
|
@ -213,14 +238,18 @@ function visualizer.flush_line(str, nested)
|
||||||
-- number, that belongs to identifier
|
-- number, that belongs to identifier
|
||||||
word = word .. c
|
word = word .. c
|
||||||
else
|
else
|
||||||
|
if not inasm then
|
||||||
-- number
|
-- number
|
||||||
state = buffers.changestate(3, state)
|
state = buffers.changestate(3, state)
|
||||||
|
end
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
|
if not inasm then
|
||||||
state = buffers.finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
|
end
|
||||||
-- identifier complete, check if it's a reserved word and flush
|
-- identifier complete, check if it's a reserved word and flush
|
||||||
flush_pas_word(word)
|
state = flush_pas_word(word, state)
|
||||||
word = nil
|
word = nil
|
||||||
if c == " " then
|
if c == " " then
|
||||||
tex.sprint(tex.ctxcatcodes, "\\obs")
|
tex.sprint(tex.ctxcatcodes, "\\obs")
|
||||||
|
@ -230,12 +259,14 @@ function visualizer.flush_line(str, nested)
|
||||||
tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength))
|
tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength))
|
||||||
end
|
end
|
||||||
elseif c == "'" then
|
elseif c == "'" then
|
||||||
-- string starts
|
if not inasm then
|
||||||
|
-- string begins
|
||||||
instring = true
|
instring = true
|
||||||
state = buffers.changestate(3, state)
|
state = buffers.changestate(3, state)
|
||||||
|
end
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
elseif (c == "/") and (nextc == "/") then
|
elseif (c == "/") and (nextc == "/") then
|
||||||
-- one-line comment starts
|
-- one-line comment begins
|
||||||
incomment = true
|
incomment = true
|
||||||
state = buffers.changestate(3, state)
|
state = buffers.changestate(3, state)
|
||||||
tex.sprint(tex.ctxcatcodes, comment_style)
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
||||||
|
@ -243,38 +274,39 @@ function visualizer.flush_line(str, nested)
|
||||||
elseif c == "{" then
|
elseif c == "{" then
|
||||||
incomment = true
|
incomment = true
|
||||||
if nextc == "$" then
|
if nextc == "$" then
|
||||||
-- compiler directive starts
|
-- compiler directive begins
|
||||||
incompdirec = true
|
incompdirec = true
|
||||||
state = buffers.changestate(1, state)
|
state = buffers.changestate(1, state)
|
||||||
else
|
else
|
||||||
-- long comment starts
|
-- long comment begins
|
||||||
inlongcomment = true
|
inlongcomment = true
|
||||||
state = buffers.changestate(3, state)
|
state = buffers.changestate(3, state)
|
||||||
end
|
end
|
||||||
tex.sprint(tex.ctxcatcodes, comment_style)
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
elseif (c == "(") and (nextc == "*") then
|
elseif (c == "(") and (nextc == "*") then
|
||||||
-- long comment (alternative) starts
|
-- long comment (alternative) begins
|
||||||
incomment = true
|
incomment = true
|
||||||
inlongcomment_alt = 2
|
inlongcomment_alt = 2
|
||||||
state = buffers.changestate(3, state)
|
state = buffers.changestate(3, state)
|
||||||
tex.sprint(tex.ctxcatcodes, comment_style)
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
-- TODO: asm
|
|
||||||
else
|
else
|
||||||
|
if not inasm then
|
||||||
-- symbol
|
-- symbol
|
||||||
state = buffers.changestate(1, state)
|
state = buffers.changestate(1, state)
|
||||||
|
end
|
||||||
tex.write(c)
|
tex.write(c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
c = nextc
|
c = nextc
|
||||||
end
|
end
|
||||||
if not incomment then
|
if not incomment and not inasm then
|
||||||
state = buffers.finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
end
|
end
|
||||||
-- maybe something left, check if it's a reserved word and flush
|
-- 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
|
if incomment then
|
||||||
-- end the comment-line
|
-- end the comment-line
|
||||||
tex.sprint(tex.ctxcatcodes, "\}")
|
tex.sprint(tex.ctxcatcodes, "\}")
|
||||||
|
|
Loading…
Reference in New Issue