- Removed "short-cut" aliases
This commit is contained in:
parent
5d047d521f
commit
902cdaa74a
122
pret-pas.lua
122
pret-pas.lua
|
@ -6,22 +6,9 @@ if not modules then modules = { } end modules ['pret-pas'] = {
|
||||||
license = "see context related readme files"
|
license = "see context related readme files"
|
||||||
}
|
}
|
||||||
|
|
||||||
local utf = unicode.utf8
|
|
||||||
|
|
||||||
local utfcharacters, utfvalues = string.utfcharacters, string.utfvalues
|
|
||||||
local utfbyte, utffind = utf.byte, utf.find
|
|
||||||
local byte, sub, find, match = string.byte, string.sub, string.find, string.match
|
|
||||||
local texsprint, texwrite = tex.sprint, tex.write
|
|
||||||
local ctxcatcodes = tex.ctxcatcodes
|
|
||||||
|
|
||||||
local buffers = buffers
|
|
||||||
|
|
||||||
local changestate, finishstate = buffers.changestate, buffers.finishstate
|
|
||||||
|
|
||||||
local visualizer = buffers.newvisualizer("pas")
|
local visualizer = buffers.newvisualizer("pas")
|
||||||
|
|
||||||
-- reserved words taken from http://www.freepascal.org/docs-html/ref/refse3.html
|
-- reserved words taken from http://www.freepascal.org/docs-html/ref/refse3.html
|
||||||
|
|
||||||
visualizer.reservedwords = {
|
visualizer.reservedwords = {
|
||||||
-- Turbo Pascal
|
-- Turbo Pascal
|
||||||
"absolute", "and", "array", "asm", "begin", "case", "const", "constructor",
|
"absolute", "and", "array", "asm", "begin", "case", "const", "constructor",
|
||||||
|
@ -94,32 +81,31 @@ end
|
||||||
|
|
||||||
local function written(state,c,i)
|
local function written(state,c,i)
|
||||||
if c == " " then
|
if c == " " then
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
texsprint(ctxcatcodes,"\\obs")
|
tex.sprint(tex.ctxcatcodes,"\\obs")
|
||||||
elseif c == "\t" then
|
elseif c == "\t" then
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
texsprint(ctxcatcodes,"\\obs")
|
tex.sprint(tex.ctxcatcodes,"\\obs")
|
||||||
if buffers.visualizers.enabletab then
|
if buffers.visualizers.enabletab then
|
||||||
texsprint(ctxcatcodes,rep("\\obs ",i%buffers.visualizers.tablength))
|
tex.sprint(tex.ctxcatcodes,rep("\\obs ",i%buffers.visualizers.tablength))
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
texwrite(c)
|
tex.write(c)
|
||||||
end
|
end
|
||||||
return state, 0
|
return state, 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function visualizer.flush_line(str, nested)
|
function visualizer.flush_line(str, nested)
|
||||||
--[[
|
--[[
|
||||||
buffers.currentcolors = colors
|
|
||||||
local identifier = nil
|
local identifier = nil
|
||||||
for c in string.utfcharacters(str) do
|
for c in string.string.utfcharacters(str) do
|
||||||
if string.string.find(c, "^[%a%_]$") then
|
if string.string.string.find(c, "^[%a%_]$") then
|
||||||
if identifier then
|
if identifier then
|
||||||
identifier = identifier .. c
|
identifier = identifier .. c
|
||||||
else
|
else
|
||||||
identifier = c
|
identifier = c
|
||||||
end
|
end
|
||||||
elseif string.string.find(c, "^[%d]$")
|
elseif string.string.string.find(c, "^[%d]$")
|
||||||
if identifier and #identifier > 1 then
|
if identifier and #identifier > 1 then
|
||||||
identifier = identifier .. c
|
identifier = identifier .. c
|
||||||
end
|
end
|
||||||
|
@ -134,23 +120,23 @@ 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
|
||||||
local code, comment = 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
|
||||||
elseif incomment then
|
elseif incomment then
|
||||||
comment, code = match(str,"^(.-)%]%](.*)$")
|
comment, code = string.match(str,"^(.-)%]%](.*)$")
|
||||||
if comment then
|
if comment then
|
||||||
-- flush the comment and then process the code
|
-- flush the comment and then process the code
|
||||||
for c in utfcharacters(comment) do
|
for c in string.utfcharacters(comment) do
|
||||||
if c == " " then texsprint(ctxcatcodes,"\\obs") else texwrite(c) end
|
if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
|
||||||
end
|
end
|
||||||
state = changestate(states['--'], state)
|
state = buffers.changestate(states['--'], state)
|
||||||
texwrite("]]")
|
tex.write("]]")
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
incomment = false
|
incomment = false
|
||||||
else
|
else
|
||||||
for c in utfcharacters(str) do
|
for c in string.utfcharacters(str) do
|
||||||
if c == " " then texsprint(ctxcatcodes,"\\obs") else texwrite(c) end
|
if c == " " then tex.sprint(tex.ctxcatcodes,"\\obs") else tex.write(c) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
comment = nil
|
comment = nil
|
||||||
|
@ -158,27 +144,27 @@ function visualizer.flush_line(str, nested)
|
||||||
code = str
|
code = str
|
||||||
end
|
end
|
||||||
if code and code ~= "" then
|
if code and code ~= "" then
|
||||||
local pre, post = match(code,"^(.-)%-%-(.*)$")
|
local pre, post = string.match(code,"^(.-)%-%-(.*)$")
|
||||||
if pre then
|
if pre then
|
||||||
code = pre
|
code = pre
|
||||||
end
|
end
|
||||||
local p, s, i = nil, nil, 0
|
local p, s, i = nil, nil, 0
|
||||||
for c in utfcharacters(code) do
|
for c in string.utfcharacters(code) do
|
||||||
i = i + 1
|
i = i + 1
|
||||||
if instr then
|
if instr then
|
||||||
if p then
|
if p then
|
||||||
texwrite(p)
|
tex.write(p)
|
||||||
p = nil
|
p = nil
|
||||||
end
|
end
|
||||||
if c == s then
|
if c == s then
|
||||||
if inesc then
|
if inesc then
|
||||||
texwrite(c)
|
tex.write(c)
|
||||||
inesc = false
|
inesc = false
|
||||||
else
|
else
|
||||||
state = changestate(states[c],state)
|
state = buffers.changestate(states[c],state)
|
||||||
instr = false
|
instr = false
|
||||||
texwrite(c)
|
tex.write(c)
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
end
|
end
|
||||||
s = nil
|
s = nil
|
||||||
else
|
else
|
||||||
|
@ -191,14 +177,14 @@ function visualizer.flush_line(str, nested)
|
||||||
end
|
end
|
||||||
elseif c == "[" then
|
elseif c == "[" then
|
||||||
if word then
|
if word then
|
||||||
texwrite(word)
|
tex.write(word)
|
||||||
word = nil
|
word = nil
|
||||||
end
|
end
|
||||||
if p == "[" then
|
if p == "[" then
|
||||||
inlongstring = true
|
inlongstring = true
|
||||||
state = changestate(states["[["],state)
|
state = buffers.changestate(states["[["],state)
|
||||||
texwrite(p,c)
|
tex.write(p,c)
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
p = nil
|
p = nil
|
||||||
else
|
else
|
||||||
if p then
|
if p then
|
||||||
|
@ -208,14 +194,14 @@ function visualizer.flush_line(str, nested)
|
||||||
end
|
end
|
||||||
elseif c == "]" then
|
elseif c == "]" then
|
||||||
if word then
|
if word then
|
||||||
texwrite(word)
|
tex.write(word)
|
||||||
word = nil
|
word = nil
|
||||||
end
|
end
|
||||||
if p == "]" then
|
if p == "]" then
|
||||||
inlongstring = false
|
inlongstring = false
|
||||||
state = changestate(states["]]"],state)
|
state = buffers.changestate(states["]]"],state)
|
||||||
texwrite(p,c)
|
tex.write(p,c)
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
p = nil
|
p = nil
|
||||||
else
|
else
|
||||||
if p then
|
if p then
|
||||||
|
@ -225,9 +211,9 @@ function visualizer.flush_line(str, nested)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
if p then
|
if p then
|
||||||
state = changestate(states[p],state)
|
state = buffers.changestate(states[p],state)
|
||||||
texwrite(p)
|
tex.write(p)
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
p = nil
|
p = nil
|
||||||
end
|
end
|
||||||
if c == " " or c == "\t" then
|
if c == " " or c == "\t" then
|
||||||
|
@ -244,48 +230,48 @@ function visualizer.flush_line(str, nested)
|
||||||
word = nil
|
word = nil
|
||||||
end
|
end
|
||||||
instr = true
|
instr = true
|
||||||
state = changestate(states[c],state)
|
state = buffers.changestate(states[c],state)
|
||||||
state, i = written(state,c,i)
|
state, i = written(state,c,i)
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
s = c
|
s = c
|
||||||
elseif find(c,"^[%a]$") then
|
elseif string.find(c,"^[%a]$") then
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
if word then word = word .. c else word = c end
|
if word then word = word .. c else word = c end
|
||||||
elseif word and (#word > 1) and find(c,"^[%d%.%_]$") then
|
elseif word and (#word > 1) and string.find(c,"^[%d%.%_]$") then
|
||||||
if word then word = word .. c else word = c end
|
if word then word = word .. c else word = c end
|
||||||
else
|
else
|
||||||
flush_pas_word(word)
|
flush_pas_word(word)
|
||||||
word = nil
|
word = nil
|
||||||
state = changestate(states[c],state)
|
state = buffers.changestate(states[c],state)
|
||||||
texwrite(c)
|
tex.write(c)
|
||||||
instr = (c == '"')
|
instr = (c == '"')
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if p then
|
if p then
|
||||||
texwrite(p)
|
tex.write(p)
|
||||||
-- state, i = written(state,p,i)
|
-- state, i = written(state,p,i)
|
||||||
p = nil
|
p = nil
|
||||||
end
|
end
|
||||||
flush_pas_word(word)
|
flush_pas_word(word)
|
||||||
if post then
|
if post then
|
||||||
state = changestate(states['--'], state)
|
state = buffers.changestate(states['--'], state)
|
||||||
texwrite("--")
|
tex.write("--")
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
for c in utfcharacters(post) do
|
for c in string.utfcharacters(post) do
|
||||||
state, i = written(state,c,i)
|
state, i = written(state,c,i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if comment then
|
if comment then
|
||||||
incomment = true
|
incomment = true
|
||||||
state = changestate(states['--'], state)
|
state = buffers.changestate(states['--'], state)
|
||||||
texwrite("[[")
|
tex.write("[[")
|
||||||
state = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
-- texwrite(comment) -- maybe also split and
|
-- tex.write(comment) -- maybe also split and
|
||||||
for c in 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 = finishstate(state)
|
state = buffers.finishstate(state)
|
||||||
end
|
end
|
Loading…
Reference in New Issue