summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/luatex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2012-07-29 17:06:24 +0000
committerKarl Berry <karl@freefriends.org>2012-07-29 17:06:24 +0000
commit1fb658cc9435346a6f399e846f07f05c08260fc7 (patch)
tree21c1bed0af6d3a90b6ad164f7d8075057d8967dc /Master/texmf-dist/tex/luatex
parent13f625a8c0179b6984b24ed7e1fb6d25b23e2c7c (diff)
interpreter (10jun12)
git-svn-id: svn://tug.org/texlive/trunk@27232 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/luatex')
-rw-r--r--Master/texmf-dist/tex/luatex/interpreter/interpreter.lua165
-rw-r--r--Master/texmf-dist/tex/luatex/interpreter/interpreter.sty4
-rw-r--r--Master/texmf-dist/tex/luatex/interpreter/interpreter.tex2
3 files changed, 110 insertions, 61 deletions
diff --git a/Master/texmf-dist/tex/luatex/interpreter/interpreter.lua b/Master/texmf-dist/tex/luatex/interpreter/interpreter.lua
index 2a87d979195..05de6eb791f 100644
--- a/Master/texmf-dist/tex/luatex/interpreter/interpreter.lua
+++ b/Master/texmf-dist/tex/luatex/interpreter/interpreter.lua
@@ -1,6 +1,6 @@
-- This is the main Lua file for the Interpreter package.
-- Further information in interpreter-doc.pdf or interpreter-doc.txt.
--- Paul Isambert - zappathustra AT free DOT fr - December 2011
+-- Paul Isambert - zappathustra AT free DOT fr - June 2012
--
-- Beware, this is written with Gates. Please read the Gates doc if
-- you want to understand something.
@@ -8,7 +8,12 @@
local find, gsub, match, sub = string.find, string.gsub, string.match, string.sub
local insert, sort, remove = table.insert, table.sort, table.remove
local io_open = io.open
+local ipairs, pairs, type = ipairs, pairs, type
require("gates.lua")
+if not gates.iterator then
+ tex.error("Interpreter error: Your version of Gates should be at least v.0.2. I quit. Expect chaos")
+ return
+end
interpreter = gates.new("interpreter")
@@ -251,7 +256,8 @@ interpreter.direct = "%%%%I%s+"
-- At last, the function to be registered in open_read_file, defining the
-- function that reads a file.
-
+interpreter.core.reader.current_line = 0
+interpreter.core.reader.current_line = 0
interpreter.core.reader.list{"read_file",
{"make_paragraph", conditional = function () return #interpreter.core.lines == 0 end,
@@ -274,71 +280,114 @@ interpreter.core.reader.list{"read_file",
insert(interpreter.core.lines, line)
end}},
{"apply_classes", conditional = function () return #interpreter.core.lines > 0 and interpreter.active end,
- {"initialize",
- function ()
- return 1, 1, 1, 1
- end},
- {"pass_class", loop = function (c) return type(interpreter.core.reader.protected) ~= "boolean"
- and c <= #interpreter.core.classes end,
- {"pass_pattern", loop = function (c, p) return type(interpreter.core.reader.protected) ~= "boolean"
- and p <= #interpreter.core.classes[c] end,
- {"pass_line", loop = function (c, p, l) return type(interpreter.core.reader.protected) ~= "boolean"
- and l <= #interpreter.core.lines end,
- {"check_index", loop = function (c, p, l, i)
- return (type(interpreter.core.lines[l]) == "string" and type(interpreter.core.reader.protected) ~= "boolean")
- and interpreter.core.tools.get_index(interpreter.core.lines[l], interpreter.core.classes[c][p].pattern, i)
- end,
- {"call", conditional = function (c, p) return interpreter.core.classes[c][p].call end,
- function(c, p, l, i)
- local line, pattern = interpreter.core.lines[l], interpreter.core.classes[c][p]
- local index = interpreter.core.tools.get_index(line, pattern.pattern, i)
- local L, O = pattern.call(interpreter.core.lines, l, index, pattern)
- if O then
- l, i = L, O
- elseif L then
- i = L
+ {"pass_class", iterator = function ()
+ local done_zero
+ local function f (t, i)
+ if type(interpreter.core.reader.protected) ~= "boolean" then
+ if not done_zero then
+ i = i+1
+ local v = t[i]
+ if v then
+ return i, v
+ else
+ done_zero = true
+ return 0, t[0]
+ end
+ end
+ end
+ end
+ return f, interpreter.core.classes, 0
+ end,
+ {"pass_pattern", iterator = function (_, class)
+ local function f (t, i)
+ if type(interpreter.core.reader.protected) ~= "boolean" then
+ i = i+1
+ local v = t[i]
+ if v then
+ return i, v
+ end
+ end
+ end
+ return f, class, 0
+ end,
+ {"process_lines", iterator = function (_, pattern)
+ interpreter.core.reader.current_line = 0
+ interpreter.core.reader.current_index = 0
+ return function ()
+ if type(interpreter.core.reader.protected) ~= "boolean" then
+ local l = interpreter.core.reader.current_line
+ local i = interpreter.core.reader.current_index
+ if i == 0 then
+ l, i = l + 1, 1
+ end
+ line = interpreter.core.lines[l]
+ -- When protected, a line is a table.
+ while type(line) == "table" do
+ l, i = l+1, 1
+ line = interpreter.core.lines[l]
+ end
+ if line then
+ interpreter.core.reader.current_line = l
+ interpreter.core.reader.current_index = i
+ return l, pattern, i
+ end
+ end
+ end
+ end,
+ {"switch", autoreturn = true,
+ function (_, pattern)
+ if pattern.call then
+ interpreter.core.reader.ajar("call", "process_lines")
+ elseif pattern.replace then
+ interpreter.core.reader.ajar("replace", "process_lines")
end
- return c, p, l, i
- end},
- {"replace", conditional = function (c, p) return not interpreter.core.classes[c][p].call
- and interpreter.core.classes[c][p].replace end,
- function(c, p, l, i)
- local line, pattern = interpreter.core.lines[l], interpreter.core.classes[c][p]
- local index = interpreter.core.tools.get_index(line, pattern.pattern, i)
- interpreter.core.lines[l] = interpreter.core.tools.xsub(line, index, pattern.pattern, pattern.replace)
- i = index + (pattern.offset or 0)
- return c, p, l, i
end},
- {"protect", conditional = function () return type(interpreter.core.reader.protected) == "table" end,
- autoreturn = true,
- function ()
- for n, _ in pairs(interpreter.core.reader.protected) do
- if type(interpreter.core.lines[n]) == "string" then
- interpreter.core.lines[n] = {interpreter.core.lines[n]}
+ {"call", status = "close",
+ function(i, pattern, ind)
+ local line = interpreter.core.lines[i]
+ local index = interpreter.core.tools.get_index(line, pattern.pattern, ind)
+ if index then
+ local L, O = pattern.call(interpreter.core.lines, i, index, pattern)
+ if O then
+ interpreter.core.reader.current_line = L
+ interpreter.core.reader.current_index = O
+ elseif L then
+ interpreter.core.reader.current_index = L
end
+ else
+ interpreter.core.reader.current_index = 0
end
- end}},
- {"increment_line", function (c, p, l, i) return c, p, l+1, 1 end}},
- {"increment_pattern", function (c, p, l) return c, p+1, 1, 1 end}},
- {"increment_class", function (c) return c+1, 1, 1, 1 end}},
- {"apply_class0", conditional = function () return type(interpreter.core.reader.protected) ~= "boolean" end,
- {"initialize0",
- function ()
- return 0, 1, 1, 1
- end},
- {"pass_pattern", loop = function (c, p) return type(interpreter.core.reader.protected) ~= "boolean"
- and p <= #interpreter.core.classes[c] end}},
+ end},
+ {"replace", status = "close",
+ function(i, pattern, ind)
+ local line = interpreter.core.lines[i]
+ local index = interpreter.core.tools.get_index(line, pattern.pattern, ind)
+ if index then
+ interpreter.core.lines[i] = interpreter.core.tools.xsub(line, index, pattern.pattern, pattern.replace)
+ interpreter.core.reader.current_index = index + (pattern.offset or 0)
+ else
+ interpreter.core.reader.current_index = 0
+ end
+ end},
+ {"protect", iterator = function ()
+ if type(interpreter.core.reader.protected) == "table" then
+ return pairs(interpreter.core.reader.protected)
+ end
+ end,
+ function (n)
+ if type(interpreter.core.lines[n]) == "string" then
+ interpreter.core.lines[n] = {interpreter.core.lines[n]}
+ end
+ end}}}},
{"unprotect",
{"undo_protected",
function ()
interpreter.core.reader.protected = nil
end},
- {"unprotect_lines",
- function ()
- for n, l in ipairs(interpreter.core.lines) do
- if type(l) == "table" then
- interpreter.core.lines[n] = l[1]
- end
+ {"unprotect_lines", iterator = function () return ipairs(interpreter.core.lines) end,
+ function (i, l)
+ if type(l) == "table" then
+ interpreter.core.lines[i] = l[1]
end
end}},
{"remove_escape", conditional = function () return interpreter.escape end,
diff --git a/Master/texmf-dist/tex/luatex/interpreter/interpreter.sty b/Master/texmf-dist/tex/luatex/interpreter/interpreter.sty
index 94f94443ad9..ba16a86256f 100644
--- a/Master/texmf-dist/tex/luatex/interpreter/interpreter.sty
+++ b/Master/texmf-dist/tex/luatex/interpreter/interpreter.sty
@@ -5,10 +5,10 @@
% Author: Paul Isambert.
% E-mail: zappathustra AT free DOT fr
% Comments and suggestions are welcome.
-% Date: December 2011.
+% Date: June 2012.
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{interpreter}[2011/12/03 v.1.1 Preprocessing input files on the fly.]
+\ProvidesPackage{interpreter}[2012/06/10 v.1.2 Preprocessing input files on the fly.]
% Needed to prevent LaTeX check input, which would call open_read_file and
% thus remove Interpreter's main function (which is removed as soon as it is
% used).
diff --git a/Master/texmf-dist/tex/luatex/interpreter/interpreter.tex b/Master/texmf-dist/tex/luatex/interpreter/interpreter.tex
index 3f58083dd72..3568fc90e9d 100644
--- a/Master/texmf-dist/tex/luatex/interpreter/interpreter.tex
+++ b/Master/texmf-dist/tex/luatex/interpreter/interpreter.tex
@@ -1,7 +1,7 @@
% This is the main TeX file for the Interpreter package.
% Further information in interpreter-doc.pdf or interpreter-doc.txt.
%
-% Paul Isambert - zappathustra AT free DOT fr - December 2011
+% Paul Isambert - zappathustra AT free DOT fr - June 2012
%
\csname Oh no, Interpreter won't be loaded twice!\endcsname
\expandafter\let\csname Oh no, Interpreter won't be loaded twice!\endcsname\endinput