summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-12-29 00:00:16 +0100
committerPhilipp Gesang <pgesang@ix.urz.uni-heidelberg.de>2010-12-29 00:00:16 +0100
commitc648ccf7728650440b6d7046211128a58ddbbc5f (patch)
treeb33495bf6a00ff11ed1ff0a2371395d0147f41db
parent891e6c10ebffe2cb1e9a6a6d9987a6583b37369e (diff)
downloadtransliterator-c648ccf7728650440b6d7046211128a58ddbbc5f.tar.gz
restructured main transliteration procedure to not redundantly reload tables
-rw-r--r--tex/context/third/transliterator/trans_tables_gr.lua4
-rw-r--r--tex/context/third/transliterator/trans_tables_iso9.lua7
-rw-r--r--tex/context/third/transliterator/trans_tables_scntfc.lua7
-rw-r--r--tex/context/third/transliterator/trans_tables_trsc.lua8
-rw-r--r--tex/context/third/transliterator/transliterator.lua56
5 files changed, 48 insertions, 34 deletions
diff --git a/tex/context/third/transliterator/trans_tables_gr.lua b/tex/context/third/transliterator/trans_tables_gr.lua
index 0e04f60..31637b8 100644
--- a/tex/context/third/transliterator/trans_tables_gr.lua
+++ b/tex/context/third/transliterator/trans_tables_gr.lua
@@ -645,7 +645,7 @@ end
-- End Of Tables --
--===========================================================================--
-function translit.dogreek (mode, text)
+local function greek (mode, text)
local P, V, Cs = lpeg.P, lpeg.V, lpeg.Cs
local addrules = translit.addrules
local utfchar = translit.utfchar
@@ -687,3 +687,5 @@ function translit.dogreek (mode, text)
end
end
+translit.methods ["gr"] = function (text) return greek("gr" , text) end
+translit.methods ["gr_n"] = function (text) return greek("gr_n", text) end
diff --git a/tex/context/third/transliterator/trans_tables_iso9.lua b/tex/context/third/transliterator/trans_tables_iso9.lua
index b0eb2a0..9007b20 100644
--- a/tex/context/third/transliterator/trans_tables_iso9.lua
+++ b/tex/context/third/transliterator/trans_tables_iso9.lua
@@ -251,7 +251,7 @@ end
--===========================================================================--
-function translit.iso9 (mode, text)
+local function iso9 (mode, text)
local P, R, S, V, Cs = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.Cs
local addrules = translit.addrules
local utfchar = translit.utfchar
@@ -280,3 +280,8 @@ function translit.iso9 (mode, text)
return iso9_parser:match(text)
end
+
+translit.methods ["ru"] = function (text) return iso9 ("all" , text) end
+translit.methods ["all"] = function (text) return iso9 ("all" , text) end
+translit.methods ["ru_old"] = function (text) return iso9 ("ru_old" , text) end
+translit.methods ["ru_old_jer_hack"] = function (text) return iso9 ("ru_old_jer_hack", text) end
diff --git a/tex/context/third/transliterator/trans_tables_scntfc.lua b/tex/context/third/transliterator/trans_tables_scntfc.lua
index 0a24130..9de4b96 100644
--- a/tex/context/third/transliterator/trans_tables_scntfc.lua
+++ b/tex/context/third/transliterator/trans_tables_scntfc.lua
@@ -200,7 +200,7 @@ end
-- End Of Tables --
--===========================================================================--
-function translit.scientific (mode, text)
+local function scientific (mode, text)
local P, Cs = lpeg.P, lpeg.Cs
local utfchar = translit.utfchar
local addrules = translit.addrules
@@ -250,3 +250,8 @@ function translit.scientific (mode, text)
return scientific_parser:match(text)
end
+
+translit.methods ["iso9_ocs"] = function (text) return scientific( "iso9_ocs" , text ) end
+translit.methods ["iso9_ocs_hack"] = function (text) return scientific( "iso9_ocs_hack", text ) end
+translit.methods ["ocs"] = function (text) return scientific( "ocs" , text ) end
+translit.methods ["ocs_gla"] = function (text) return scientific( "ocs_gla" , text ) end
diff --git a/tex/context/third/transliterator/trans_tables_trsc.lua b/tex/context/third/transliterator/trans_tables_trsc.lua
index f5de9bb..6ba07a2 100644
--- a/tex/context/third/transliterator/trans_tables_trsc.lua
+++ b/tex/context/third/transliterator/trans_tables_trsc.lua
@@ -494,7 +494,7 @@ end
-- End Of Tables --
--===========================================================================--
-function translit.transcript (mode, text)
+local function transcript (mode, text)
local P, R, S, V, Cs = lpeg.P, lpeg.R, lpeg.S, lpeg.V, lpeg.Cs
local addrules = translit.addrules
local utfchar = translit.utfchar
@@ -679,3 +679,9 @@ function translit.transcript (mode, text)
end
+translit.methods ["ru_transcript_de"] = function (text) return transcript("ru_transcript_de" , text) end
+translit.methods ["ru_transcript_de_exp"] = function (text) return transcript("ru_transcript_de_exp", text) end
+translit.methods ["ru_transcript_en"] = function (text) return transcript("ru_transcript_en" , text) end
+translit.methods ["ru_transcript_en_exp"] = function (text) return transcript("ru_transcript_en_exp", text) end
+translit.methods ["ru_cz"] = function (text) return transcript("ru_cz" , text) end
+translit.methods ["ocs_cz"] = function (text) return transcript("ocs_cz" , text) end
diff --git a/tex/context/third/transliterator/transliterator.lua b/tex/context/third/transliterator/transliterator.lua
index 36eb804..ddda144 100644
--- a/tex/context/third/transliterator/transliterator.lua
+++ b/tex/context/third/transliterator/transliterator.lua
@@ -10,7 +10,8 @@
--
translit = translit or {}
-translit.tables = translit.tables or {}
+translit.tables = translit.tables or {}
+translit.methods = translit.methods or {}
--------------------------------------------------------------------------------
-- Predefining vowel lists
@@ -225,35 +226,30 @@ end
-- It loads the transliteration tables according to \type{method} and calls the
-- corresponding function.
+-- Those supposedly are the most frequently used so it won’t hurt to preload
+-- them.
+environment.loadluafile ("trans_tables_iso9")
+
function translit.transliterate (method, text)
- if method == "ru" or
- method == "ru_old" or
- method == "ru_old_jer_hack" or
- method == "all"
- then
- environment.loadluafile ("trans_tables_iso9")
- text = translit.iso9 (method, text)
- elseif method == "ru_transcript_de" or
- method == "ru_transcript_de_exp" or -- experimental lpeg
- method == "ru_transcript_en" or
- method == "ru_transcript_en_exp" or
- method == "ru_cz" or
- method == "ocs_cz"
- then
- environment.loadluafile ("trans_tables_trsc")
- text = translit.transcript (method, text)
- elseif method == "iso9_ocs" or
- method == "iso9_ocs_hack" or
- method == "ocs" or
- method == "ocs_gla"
- then
- environment.loadluafile ("trans_tables_scntfc")
- text = translit.scientific (method, text)
- elseif method == "gr" or
- method == "gr_n"
- then
- environment.loadluafile ("trans_tables_gr")
- text = translit.dogreek (method, text)
+ local methods = translit.methods
+ if not methods[method] then -- register tables and method
+ if method == "ru_transcript_de" or
+ method == "ru_transcript_de_exp" or -- experimental lpeg
+ method == "ru_transcript_en" or
+ method == "ru_transcript_en_exp" or
+ method == "ru_cz" or
+ method == "ocs_cz" then
+ environment.loadluafile ("trans_tables_trsc")
+ elseif method == "iso9_ocs" or
+ method == "iso9_ocs_hack" or
+ method == "ocs" or
+ method == "ocs_gla" then
+ environment.loadluafile ("trans_tables_scntfc")
+ elseif method == "gr" or
+ method == "gr_n" then
+ environment.loadluafile ("trans_tables_gr")
+ end
end
- context (text)
+
+ context ( methods[method](text) )
end