2010-09-29 19:08:31 +02:00
|
|
|
if not modules then modules = { } end modules ['pret-pas'] = {
|
|
|
|
version = 1.0,
|
|
|
|
comment = "custom pretty printer for Pascal code",
|
|
|
|
author = "Stefan Müller, Chemnitz DE",
|
|
|
|
copyright = "Stefan Müller",
|
|
|
|
license = "see context related readme files"
|
|
|
|
}
|
|
|
|
|
2010-10-02 11:53:54 +02:00
|
|
|
-- The code formatting is adapted from Lazarus, a Free Pascal RAD IDE, which
|
|
|
|
-- should be quite similar to the Delphi style. Please note that comments are
|
|
|
|
-- not typeset with bold fontface but slanted, which improves output when not
|
|
|
|
-- using colors.
|
2010-09-30 14:56:18 +02:00
|
|
|
-- http://lazarus.freepascal.org/
|
|
|
|
|
2010-09-29 19:08:31 +02:00
|
|
|
local visualizer = buffers.newvisualizer("pas")
|
|
|
|
|
2010-09-30 14:56:18 +02:00
|
|
|
-- The list of reserved words is taken from
|
|
|
|
-- http://www.freepascal.org/docs-html/ref/refse3.html
|
2010-09-29 19:08:31 +02:00
|
|
|
visualizer.reservedwords = {
|
|
|
|
-- Turbo Pascal
|
|
|
|
"absolute", "and", "array", "asm", "begin", "case", "const", "constructor",
|
|
|
|
"destructor", "div", "do", "downto", "else", "end", "file", "for",
|
|
|
|
"function", "goto", "if", "implementation", "in", "inherited", "inline",
|
|
|
|
"interface", "label", "mod", "nil", "not", "object", "of", "on", "operator",
|
|
|
|
"or", "packed", "procedure", "program", "record", "reintroduce", "repeat",
|
|
|
|
"self", "set", "shl", "shr", "string", "then", "to", "type", "unit",
|
|
|
|
"until", "uses", "var", "while", "with", "xor",
|
|
|
|
|
|
|
|
-- Free Pascal
|
|
|
|
-- these are not bold type (keeping them, just in case)
|
|
|
|
-- "dispose", "exit", "false", "new", "true",
|
|
|
|
|
|
|
|
-- Object Pascal
|
|
|
|
"as", "class", "dispinterface", "except", "exports", "finalization",
|
|
|
|
"finally", "initialization", "inline", "is", "library", "on", "out",
|
|
|
|
"packed", "property", "raise", "resourcestring", "threadvar", "try",
|
|
|
|
|
|
|
|
-- Modifiers
|
2010-09-30 14:56:18 +02:00
|
|
|
-- some of these are only bold in specific places (in the following, this is
|
|
|
|
-- deliberately ignored)
|
2010-09-29 19:08:31 +02:00
|
|
|
"absolute", "abstract", "alias", "assembler", "cdecl", "cppdecl", "default",
|
|
|
|
"export", "external", "far", "far16", "forward", "index", "local", "name",
|
|
|
|
"near", "nostackframe", "oldfpccall", "override", "pascal", "private",
|
|
|
|
"protected", "public", "published", "read", "register", "reintroduce",
|
|
|
|
"safecall", "softfloat", "stdcall", "virtual", "write"
|
|
|
|
}
|
|
|
|
|
|
|
|
local known_words = { }
|
|
|
|
|
|
|
|
for k,v in next, visualizer.reservedwords do
|
|
|
|
known_words[v] = k
|
|
|
|
end
|
|
|
|
|
|
|
|
local colors = {
|
2010-09-29 23:39:58 +02:00
|
|
|
"prettyone", -- red: compiler directive, symbol
|
|
|
|
"prettytwo", -- green: assembler (dark green)
|
|
|
|
"prettythree", -- blue: comment, number (dark blue)
|
2010-09-29 19:08:31 +02:00
|
|
|
"prettyfour", -- yellow
|
|
|
|
}
|
|
|
|
|
|
|
|
local states = {
|
|
|
|
['"']=1, ["'"]=1, ["[["] = 1, ["]]"] = 1,
|
|
|
|
['+']=1, ['-']=1, ['*']=1, ['/']=1, ['%']=1, ['^']=1,
|
|
|
|
["("] = 3, [")"] = 3, ["["] = 3, ["]"] = 3,
|
|
|
|
['--']=4,
|
|
|
|
}
|
|
|
|
|
2010-10-02 11:53:45 +02:00
|
|
|
local reserved_style = "\{\\bf "
|
|
|
|
local comment_style = "\{\\sl "
|
|
|
|
|
2010-10-02 15:23:10 +02:00
|
|
|
local inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
|
|
|
|
|
|
|
|
local function flush_pas_word(word, state)
|
2010-09-29 19:08:31 +02:00
|
|
|
if word then
|
2010-10-02 15:23:10 +02:00
|
|
|
local lword = string.lower(word)
|
|
|
|
local id = known_words[lword]
|
2010-09-29 19:08:31 +02:00
|
|
|
if id then
|
2010-10-02 15:23:10 +02:00
|
|
|
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
|
2010-09-29 19:08:31 +02:00
|
|
|
else
|
|
|
|
tex.write(word)
|
|
|
|
end
|
|
|
|
end
|
2010-10-02 15:23:10 +02:00
|
|
|
return state
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
|
|
|
|
2010-10-01 20:47:24 +02:00
|
|
|
local function flush_whatever(str)
|
|
|
|
if str then
|
|
|
|
for c in string.utfcharacters(str) do
|
|
|
|
if c == " " then
|
|
|
|
tex.sprint(tex.ctxcatcodes, "\\obs")
|
|
|
|
elseif c == "\t" then
|
|
|
|
tex.sprint(tex.ctxcatcodes, "\\obs")
|
|
|
|
if buffers.visualizers.enabletab then
|
|
|
|
tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength))
|
|
|
|
end
|
|
|
|
else
|
|
|
|
tex.write(c);
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-09-29 19:08:31 +02:00
|
|
|
function visualizer.reset()
|
2010-10-01 22:52:01 +02:00
|
|
|
inlongcomment, inlongcomment_alt, incompdirec, inasm = false, 0, false, false
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
|
|
|
|
2010-09-29 23:46:45 +02:00
|
|
|
--[[local function written(state, c, i)
|
2010-09-29 19:08:31 +02:00
|
|
|
if c == " " then
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.finishstate(state)
|
|
|
|
tex.sprint(tex.ctxcatcodes,"\\obs")
|
2010-09-29 19:08:31 +02:00
|
|
|
elseif c == "\t" then
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.finishstate(state)
|
|
|
|
tex.sprint(tex.ctxcatcodes,"\\obs")
|
2010-09-29 19:08:31 +02:00
|
|
|
if buffers.visualizers.enabletab then
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.sprint(tex.ctxcatcodes,rep("\\obs ",i%buffers.visualizers.tablength))
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
|
|
|
else
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(c)
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
|
|
|
return state, 0
|
2010-09-29 23:46:45 +02:00
|
|
|
end]]
|
2010-09-29 19:08:31 +02:00
|
|
|
|
|
|
|
function visualizer.flush_line(str, nested)
|
2010-10-01 22:52:01 +02:00
|
|
|
local state = 0
|
2010-10-01 20:47:24 +02:00
|
|
|
local incomment, instring = false, false
|
2010-10-01 22:52:01 +02:00
|
|
|
--local code, comment = nil, nil
|
2010-09-29 19:43:27 +02:00
|
|
|
buffers.currentcolors = colors
|
|
|
|
|
2010-09-30 14:06:14 +02:00
|
|
|
--[[
|
|
|
|
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
|
|
|
|
]]
|
2010-09-30 23:33:06 +02:00
|
|
|
--TODO: handle inlongcomment etc.
|
2010-10-01 22:52:01 +02:00
|
|
|
--[[
|
2010-10-01 20:47:24 +02:00
|
|
|
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
|
2010-10-01 22:52:01 +02:00
|
|
|
]]
|
|
|
|
if inlongcomment or (inlongcomment_alt == 2) or incompdirec then
|
|
|
|
incomment = true
|
|
|
|
if incompdirec then
|
|
|
|
state = buffers.changestate(1, state)
|
2010-10-01 20:47:24 +02:00
|
|
|
else
|
2010-10-01 22:52:01 +02:00
|
|
|
state = buffers.changestate(3, state)
|
2010-10-01 20:47:24 +02:00
|
|
|
end
|
2010-10-02 11:53:45 +02:00
|
|
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
2010-10-02 15:23:10 +02:00
|
|
|
elseif inasm then
|
|
|
|
state = buffers.changestate(2, state)
|
2010-10-01 20:47:24 +02:00
|
|
|
end
|
2010-10-01 22:52:01 +02:00
|
|
|
|
|
|
|
local c, word = nil, nil
|
|
|
|
for nextc in string.utfcharacters(str .. " ") do
|
2010-10-01 20:47:24 +02:00
|
|
|
if c then
|
|
|
|
if instring then
|
|
|
|
if c == "'" then
|
|
|
|
-- string ends
|
|
|
|
tex.write(c)
|
|
|
|
state = buffers.finishstate(state)
|
|
|
|
instring = false
|
|
|
|
else
|
|
|
|
-- inside the string
|
|
|
|
flush_whatever(c)
|
|
|
|
end
|
|
|
|
elseif incomment then
|
2010-10-01 22:52:01 +02:00
|
|
|
if ((inlongcomment or incompdirec) and (c == "}"))
|
|
|
|
or (inlongcomment_alt == 1) then
|
|
|
|
-- long comment/(alternative)/compiler directive ends
|
2010-10-01 20:47:24 +02:00
|
|
|
tex.write(c)
|
|
|
|
tex.sprint(tex.ctxcatcodes, "\}")
|
2010-10-02 15:23:10 +02:00
|
|
|
if inasm then
|
|
|
|
-- resume to asm mode
|
|
|
|
state = buffers.changestate(2, state)
|
|
|
|
else
|
|
|
|
state = buffers.finishstate(state)
|
|
|
|
end
|
2010-10-01 22:52:01 +02:00
|
|
|
incompdirec = false
|
2010-10-01 20:47:24 +02:00
|
|
|
inlongcomment = false
|
2010-10-01 22:52:01 +02:00
|
|
|
inlongcomment_alt = 0
|
2010-10-01 20:47:24 +02:00
|
|
|
incomment = false
|
2010-10-01 22:52:01 +02:00
|
|
|
elseif (inlongcomment_alt == 2) and (c == "*") and (nextc == ")") then
|
|
|
|
-- long comment (alternative) ends after nextc
|
|
|
|
tex.write(c)
|
|
|
|
inlongcomment_alt = 1
|
2010-10-01 20:47:24 +02:00
|
|
|
else
|
|
|
|
-- inside the comment
|
|
|
|
flush_whatever(c)
|
|
|
|
end
|
|
|
|
elseif string.find(c, "^[%a_]$") then
|
|
|
|
-- char belongs to identifier
|
|
|
|
if word then
|
|
|
|
word = word .. c
|
|
|
|
else
|
|
|
|
word = c
|
|
|
|
end
|
|
|
|
elseif string.find(c, "^[%d]$") then
|
|
|
|
if word and (#word > 1) then
|
|
|
|
-- number, that belongs to identifier
|
|
|
|
word = word .. c
|
|
|
|
else
|
2010-10-02 15:23:10 +02:00
|
|
|
if not inasm then
|
|
|
|
-- number
|
|
|
|
state = buffers.changestate(3, state)
|
|
|
|
end
|
2010-10-01 20:47:24 +02:00
|
|
|
tex.write(c)
|
|
|
|
end
|
2010-09-29 19:08:31 +02:00
|
|
|
else
|
2010-10-02 15:23:10 +02:00
|
|
|
if not inasm then
|
|
|
|
state = buffers.finishstate(state)
|
|
|
|
end
|
2010-10-01 20:47:24 +02:00
|
|
|
-- identifier complete, check if it's a reserved word and flush
|
2010-10-02 15:23:10 +02:00
|
|
|
state = flush_pas_word(word, state)
|
2010-10-01 20:47:24 +02:00
|
|
|
word = nil
|
|
|
|
if c == " " then
|
|
|
|
tex.sprint(tex.ctxcatcodes, "\\obs")
|
|
|
|
elseif c == "\t" then
|
|
|
|
tex.sprint(tex.ctxcatcodes, "\\obs")
|
|
|
|
if buffers.visualizers.enabletab then
|
|
|
|
tex.sprint(tex.ctxcatcodes,rep("\\obs ", buffers.visualizers.tablength))
|
|
|
|
end
|
|
|
|
elseif c == "'" then
|
2010-10-02 15:23:10 +02:00
|
|
|
if not inasm then
|
|
|
|
-- string begins
|
|
|
|
instring = true
|
|
|
|
state = buffers.changestate(3, state)
|
|
|
|
end
|
2010-10-01 20:47:24 +02:00
|
|
|
tex.write(c)
|
|
|
|
elseif (c == "/") and (nextc == "/") then
|
2010-10-02 15:23:10 +02:00
|
|
|
-- one-line comment begins
|
2010-10-01 22:52:01 +02:00
|
|
|
incomment = true
|
|
|
|
state = buffers.changestate(3, state)
|
2010-10-02 11:53:45 +02:00
|
|
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
2010-10-01 20:47:24 +02:00
|
|
|
tex.write(c)
|
|
|
|
elseif c == "{" then
|
2010-10-01 22:52:01 +02:00
|
|
|
incomment = true
|
|
|
|
if nextc == "$" then
|
2010-10-02 15:23:10 +02:00
|
|
|
-- compiler directive begins
|
2010-10-01 22:52:01 +02:00
|
|
|
incompdirec = true
|
|
|
|
state = buffers.changestate(1, state)
|
|
|
|
else
|
2010-10-02 15:23:10 +02:00
|
|
|
-- long comment begins
|
2010-10-01 20:47:24 +02:00
|
|
|
inlongcomment = true
|
|
|
|
state = buffers.changestate(3, state)
|
|
|
|
end
|
2010-10-02 11:53:45 +02:00
|
|
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
2010-10-01 22:52:01 +02:00
|
|
|
tex.write(c)
|
|
|
|
elseif (c == "(") and (nextc == "*") then
|
2010-10-02 15:23:10 +02:00
|
|
|
-- long comment (alternative) begins
|
2010-10-01 22:52:01 +02:00
|
|
|
incomment = true
|
|
|
|
inlongcomment_alt = 2
|
|
|
|
state = buffers.changestate(3, state)
|
2010-10-02 11:53:45 +02:00
|
|
|
tex.sprint(tex.ctxcatcodes, comment_style)
|
2010-10-01 20:47:24 +02:00
|
|
|
tex.write(c)
|
|
|
|
else
|
2010-10-02 15:23:10 +02:00
|
|
|
if not inasm then
|
|
|
|
-- symbol
|
|
|
|
state = buffers.changestate(1, state)
|
|
|
|
end
|
2010-10-01 20:47:24 +02:00
|
|
|
tex.write(c)
|
2010-09-30 23:33:06 +02:00
|
|
|
end
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
|
|
|
end
|
2010-10-01 20:47:24 +02:00
|
|
|
c = nextc
|
2010-09-30 23:33:06 +02:00
|
|
|
end
|
2010-10-02 15:23:10 +02:00
|
|
|
if not incomment and not inasm then
|
2010-09-29 23:39:58 +02:00
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
2010-10-01 20:47:24 +02:00
|
|
|
-- maybe something left, check if it's a reserved word and flush
|
2010-10-02 15:23:10 +02:00
|
|
|
state = flush_pas_word(word, state)
|
2010-09-30 23:33:06 +02:00
|
|
|
if incomment then
|
2010-10-01 20:47:24 +02:00
|
|
|
-- end the comment-line
|
2010-09-30 23:33:06 +02:00
|
|
|
tex.sprint(tex.ctxcatcodes, "\}")
|
|
|
|
end
|
2010-10-01 22:52:01 +02:00
|
|
|
state = buffers.finishstate(state)
|
2010-09-30 12:02:22 +02:00
|
|
|
|
2010-09-29 23:39:58 +02:00
|
|
|
--[[
|
2010-09-29 19:30:20 +02:00
|
|
|
local code, comment = string.match(str,"^(.-)%-%-%[%[(.*)$")
|
2010-09-29 19:08:31 +02:00
|
|
|
if comment then
|
|
|
|
-- process the code and then flush the comment
|
|
|
|
elseif incomment then
|
2010-09-29 19:30:20 +02:00
|
|
|
comment, code = string.match(str,"^(.-)%]%](.*)$")
|
2010-09-29 19:08:31 +02:00
|
|
|
if comment then
|
|
|
|
-- flush the comment and then process the code
|
2010-09-29 19:30:20 +02:00
|
|
|
for c in string.utfcharacters(comment) do
|
|
|
|
if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.changestate(states['--'], state)
|
2010-09-29 23:39:58 +02:00
|
|
|
tex.write("KKK")
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
incomment = false
|
|
|
|
else
|
2010-09-29 19:30:20 +02:00
|
|
|
for c in string.utfcharacters(str) do
|
|
|
|
if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
comment = nil
|
|
|
|
else
|
|
|
|
code = str
|
|
|
|
end
|
|
|
|
if code and code ~= "" then
|
2010-09-29 19:30:20 +02:00
|
|
|
local pre, post = string.match(code,"^(.-)%-%-(.*)$")
|
2010-09-29 19:08:31 +02:00
|
|
|
if pre then
|
|
|
|
code = pre
|
|
|
|
end
|
|
|
|
local p, s, i = nil, nil, 0
|
2010-09-29 19:30:20 +02:00
|
|
|
for c in string.utfcharacters(code) do
|
2010-09-29 19:08:31 +02:00
|
|
|
i = i + 1
|
|
|
|
if instr then
|
|
|
|
if p then
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(p)
|
2010-09-29 19:08:31 +02:00
|
|
|
p = nil
|
|
|
|
end
|
|
|
|
if c == s then
|
|
|
|
if inesc then
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(c)
|
2010-09-29 19:08:31 +02:00
|
|
|
inesc = false
|
|
|
|
else
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.changestate(states[c],state)
|
2010-09-29 19:08:31 +02:00
|
|
|
instr = false
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(c)
|
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
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
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(word)
|
2010-09-29 19:08:31 +02:00
|
|
|
word = nil
|
|
|
|
end
|
|
|
|
if p == "[" then
|
|
|
|
inlongstring = true
|
2010-09-29 23:39:58 +02:00
|
|
|
state = buffers.changestate(states["NRA"],state)
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(p,c)
|
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
p = nil
|
|
|
|
else
|
|
|
|
if p then
|
|
|
|
state, i = written(state,p,i)
|
|
|
|
end
|
|
|
|
p = c
|
|
|
|
end
|
|
|
|
elseif c == "]" then
|
|
|
|
if word then
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(word)
|
2010-09-29 19:08:31 +02:00
|
|
|
word = nil
|
|
|
|
end
|
|
|
|
if p == "]" then
|
|
|
|
inlongstring = false
|
2010-09-29 23:39:58 +02:00
|
|
|
state = buffers.changestate(states["KKK"],state)
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(p,c)
|
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
p = nil
|
|
|
|
else
|
|
|
|
if p then
|
|
|
|
state, i = written(state,p,i)
|
|
|
|
end
|
|
|
|
p = c
|
|
|
|
end
|
|
|
|
else
|
|
|
|
if p then
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.changestate(states[p],state)
|
|
|
|
tex.write(p)
|
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
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
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.changestate(states[c],state)
|
2010-09-29 19:08:31 +02:00
|
|
|
state, i = written(state,c,i)
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
s = c
|
2010-09-29 19:30:20 +02:00
|
|
|
elseif string.find(c,"^[%a]$") then
|
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
if word then word = word .. c else word = c end
|
2010-09-29 19:30:20 +02:00
|
|
|
elseif word and (#word > 1) and string.find(c,"^[%d%.%_]$") then
|
2010-09-29 19:08:31 +02:00
|
|
|
if word then word = word .. c else word = c end
|
|
|
|
else
|
|
|
|
flush_pas_word(word)
|
|
|
|
word = nil
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.changestate(states[c],state)
|
|
|
|
tex.write(c)
|
2010-09-29 19:08:31 +02:00
|
|
|
instr = (c == '"')
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if p then
|
2010-09-29 19:30:20 +02:00
|
|
|
tex.write(p)
|
2010-09-29 19:08:31 +02:00
|
|
|
-- state, i = written(state,p,i)
|
|
|
|
p = nil
|
|
|
|
end
|
|
|
|
flush_pas_word(word)
|
|
|
|
if post then
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.changestate(states['--'], state)
|
|
|
|
tex.write("--")
|
|
|
|
state = buffers.finishstate(state)
|
|
|
|
for c in string.utfcharacters(post) do
|
2010-09-29 19:08:31 +02:00
|
|
|
state, i = written(state,c,i)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if comment then
|
|
|
|
incomment = true
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.changestate(states['--'], state)
|
2010-09-29 23:39:58 +02:00
|
|
|
tex.write("NRA")
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.finishstate(state)
|
|
|
|
-- tex.write(comment) -- maybe also split and
|
|
|
|
for c in string.utfcharacters(comment) do
|
2010-09-29 19:08:31 +02:00
|
|
|
state, i = written(state,c,i)
|
|
|
|
end
|
|
|
|
end
|
2010-09-29 23:39:58 +02:00
|
|
|
]]
|
2010-09-29 19:30:20 +02:00
|
|
|
state = buffers.finishstate(state)
|
2010-09-29 19:08:31 +02:00
|
|
|
end
|