1if not modules then modules = { } end modules ['chem-ini'] = {
2 version = 1.001,
3 comment = "companion to chem-ini.mkiv",
4 author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
5 copyright = "PRAGMA ADE / ConTeXt Development Team",
6 license = "see context related readme files"
7}
8
9local format = string.format
10local lpegmatch, patterns = lpeg.match, lpeg.patterns
11
12local trace_molecules = false trackers.register("chemistry.molecules", function(v) trace_molecules = v end)
13
14local report_chemistry = logs.reporter("chemistry")
15
16local context = context
17local cpatterns = patterns.context
18
19chemistry = chemistry or { }
20local chemistry = chemistry
21
22
23
24
25
26local moleculeparser = cpatterns.scripted
27chemistry.moleculeparser = moleculeparser
28
29function chemistry.molecule(str)
30 return lpegmatch(moleculeparser,str)
31end
32
33interfaces.implement {
34 name = "molecule",
35 arguments = "string",
36 actions = function(str)
37 if trace_molecules then
38 local rep = lpegmatch(moleculeparser,str)
39 report_chemistry("molecule %a becomes %a",str,rep)
40 context(rep)
41 else
42 context(lpegmatch(moleculeparser,str))
43 end
44 end,
45}
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 |