diff options
author | Marius <mariausol@gmail.com> | 2012-12-24 21:40:31 +0200 |
---|---|---|
committer | Marius <mariausol@gmail.com> | 2012-12-24 21:40:31 +0200 |
commit | 31c8bf0930a6d3e353a552d6bab71f62bc25f34e (patch) | |
tree | f9fd41e91d4751cdddd2bdfc15ae69f78b61f73f /tex/context/base/cldf-prs.lua | |
parent | 1c36d2cc9c25d74a806ee74c0ee28da32d5e84ba (diff) | |
download | context-31c8bf0930a6d3e353a552d6bab71f62bc25f34e.tar.gz |
beta 2012.12.24 20:08
Diffstat (limited to 'tex/context/base/cldf-prs.lua')
-rw-r--r-- | tex/context/base/cldf-prs.lua | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tex/context/base/cldf-prs.lua b/tex/context/base/cldf-prs.lua new file mode 100644 index 000000000..42757be19 --- /dev/null +++ b/tex/context/base/cldf-prs.lua @@ -0,0 +1,52 @@ +if not modules then modules = { } end modules ['cldf-bas'] = { + version = 1.001, + comment = "companion to cldf-ini.mkiv", + author = "Hans Hagen, PRAGMA-ADE, Hasselt NL", + copyright = "PRAGMA ADE / ConTeXt Development Team", + license = "see context related readme files" +} + +local lpegmatch, patterns = lpeg.match, lpeg.patterns +local P, R, V, Cc, Cs = lpeg.P, lpeg.R, lpeg.V, lpeg.Cc, lpeg.Cs +local format = string.format + +local cpatterns = patterns.context or { } +patterns.context = cpatterns + +local backslash = P("\\") +local csname = backslash * P(1) * (1-backslash)^0 +local sign = P("+") / "\\textplus " + + P("-") / "\\textminus " +local leftbrace = P("{") +local rightbrace = P("}") +local nested = P { leftbrace * (V(1) + (1-rightbrace))^0 * rightbrace } +local subscript = P("_") +local superscript = P("^") +local utf8char = patterns.utf8char +local cardinal = patterns.cardinal + +-- local content = Cs(csname + nested + sign^-1 * (csname + cardinal + utf8char)) +-- local lowfirst = subscript * ( Cc("\\lohi{%s}{%s}") * content * superscript + Cc("\\low{%s}" ) ) * content / format +-- local highfirst = superscript * ( Cc("\\hilo{%s}{%s}") * content * subscript + Cc("\\high{%s}") ) * content / format +-- local scripts = Cs(lowfirst + highfirst) + +local scripts = P { "start", + start = V("csname") + V("lowfirst") + V("highfirst"), + csname = csname, + content = Cs(V("csname") + nested + sign^-1 * (cardinal + utf8char)), + lowfirst = subscript * ( Cc("\\lohi{%s}{%s}") * V("content") * superscript + Cc("\\low{%s}" ) ) * V("content") / format, + highfirst = superscript * ( Cc("\\hilo{%s}{%s}") * V("content") * subscript + Cc("\\high{%s}") ) * V("content") / format, + } + +local scripted = Cs((csname + scripts + utf8char)^0) + +cpatterns.scripts = scripts +cpatterns.csname = csname +cpatterns.scripted = scripted +cpatterns.nested = nested + +-- inspect(scripted) + +-- print(lpegmatch(scripted,"10^-3")) +-- print(lpegmatch(scripted,"10^-a")) + |