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
27
28local moleculeparser = cpatterns.scripted
29chemistry.moleculeparser = moleculeparser
30
31function chemistry.molecule(str)
32 return lpegmatch(moleculeparser,str)
33end
34
35interfaces.implement {
36 name = "molecule",
37 arguments = "string",
38 actions = function(str)
39 if trace_molecules then
40 local rep = lpegmatch(moleculeparser,str)
41 report_chemistry("molecule %a becomes %a",str,rep)
42 context(rep)
43 else
44 context(lpegmatch(moleculeparser,str))
45 end
46 end,
47}
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63 |