summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/chem-ini.lua
diff options
context:
space:
mode:
authorContext Git Mirror Bot <phg42.2a@gmail.com>2016-01-12 17:15:07 +0100
committerContext Git Mirror Bot <phg42.2a@gmail.com>2016-01-12 17:15:07 +0100
commit8d8d528d2ad52599f11250cfc567fea4f37f2a8b (patch)
tree94286bc131ef7d994f9432febaf03fe23d10eef8 /tex/context/base/mkiv/chem-ini.lua
parentf5aed2e51223c36c84c5f25a6cad238b2af59087 (diff)
downloadcontext-8d8d528d2ad52599f11250cfc567fea4f37f2a8b.tar.gz
2016-01-12 16:26:00
Diffstat (limited to 'tex/context/base/mkiv/chem-ini.lua')
-rw-r--r--tex/context/base/mkiv/chem-ini.lua62
1 files changed, 62 insertions, 0 deletions
diff --git a/tex/context/base/mkiv/chem-ini.lua b/tex/context/base/mkiv/chem-ini.lua
new file mode 100644
index 000000000..f7d10ffa2
--- /dev/null
+++ b/tex/context/base/mkiv/chem-ini.lua
@@ -0,0 +1,62 @@
+if not modules then modules = { } end modules ['chem-ini'] = {
+ version = 1.001,
+ comment = "companion to chem-ini.mkiv",
+ author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
+ copyright = "PRAGMA ADE / ConTeXt Development Team",
+ license = "see context related readme files"
+}
+
+local format = string.format
+local lpegmatch, patterns = lpeg.match, lpeg.patterns
+
+local trace_molecules = false trackers.register("chemistry.molecules", function(v) trace_molecules = v end)
+
+local report_chemistry = logs.reporter("chemistry")
+
+local context = context
+local cpatterns = patterns.context
+
+chemistry = chemistry or { }
+local chemistry = chemistry
+
+--[[
+<p>The next code started out as adaptation of code from Wolfgang Schuster as
+posted on the mailing list. The current version supports nested braces and
+unbraced integers as scripts.</p>
+]]--
+
+local moleculeparser = cpatterns.scripted
+chemistry.moleculeparser = moleculeparser
+
+function chemistry.molecule(str)
+ return lpegmatch(moleculeparser,str)
+end
+
+interfaces.implement {
+ name = "molecule",
+ arguments = "string",
+ actions = function(str)
+ if trace_molecules then
+ local rep = lpegmatch(moleculeparser,str)
+ report_chemistry("molecule %a becomes %a",str,rep)
+ context(rep)
+ else
+ context(lpegmatch(moleculeparser,str))
+ end
+ end,
+}
+
+-- interfaces.implement {
+-- name = "molecule",
+-- scope = "private",
+-- action = function()
+-- local str = scanstring()
+-- if trace_molecules then
+-- local rep = lpegmatch(moleculeparser,str)
+-- report_chemistry("molecule %a becomes %a",str,rep)
+-- context(rep)
+-- else
+-- context(lpegmatch(moleculeparser,str))
+-- end
+-- end,
+-- }