summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/context/base/mult-chk.lua
blob: 2a2dfcd4bd91095fec00bcb16991afc70cfb1499 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
if not modules then modules = { } end modules ['mult-chk'] = {
    version   = 1.001,
    comment   = "companion to mult-chk.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 = lpeg.match
local type = type

local make_settings_to_hash_pattern = utilities.parsers.make_settings_to_hash_pattern
local settings_to_set               = utilities.parsers.settings_to_set
local allocate                      = utilities.storage.allocate

local report_interface = logs.reporter("interface","checking")

interfaces = interfaces or { }

interfaces.syntax = allocate {
    test = { keys = table.tohash { "a","b","c","d","e","f","g" } }
}

function interfaces.invalidkey(category,key)
    report_interface("invalid key %a for %a in line %a",key,category,tex.inputlineno)
end

function interfaces.setvalidkeys(category,list)
    local s = interfaces.syntax[category]
    if not s then
        interfaces.syntax[category] = {
            keys = settings_to_set(list)
        }
    else
        s.keys = settings_to_set(list)
    end
end

function interfaces.addvalidkeys(category,list)
    local s = interfaces.syntax[category]
    if not s then
        interfaces.syntax[category] = {
            keys = settings_to_set(list)
        }
    else
        settings_to_set(list,s.keys)
    end
end

-- weird code, looks incomplete ... probably an experiment

local prefix, category, keys

local setsomevalue = context.setsomevalue
local invalidkey   = interfaces.invalidkey

local function set(key,value)
    if keys and not keys[key] then
        invalidkey(category,key)
    else
        setsomevalue(prefix,key,value)
    end
end

local pattern = make_settings_to_hash_pattern(set,"tolerant")

function interfaces.getcheckedparameters(k,p,s)
    if s and s ~= "" then
        prefix, category = p, k
        keys = k and k ~= "" and interfaces.syntax[k].keys
        lpegmatch(pattern,s)
    end
end

-- _igcp_ = interfaces.getcheckedparameters