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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
if not modules then modules = { } end modules ['toks-aux'] = {
version = 1.001,
author = "Hans Hagen, PRAGMA-ADE, Hasselt NL",
copyright = "PRAGMA ADE / ConTeXt Development Team",
license = "see context related readme files"
}
local type, tostring, next = type, tostring, next
local max = math.max
local formatters, gsub, char, gmatch = string.formatters, string.gsub, string.char, string.gmatch
local concat = table.concat
-- todo : locals from scanners
local function flags(t)
if type(t) == "string" then
t = token.create(t)
end
local r = { }
if t.frozen then r[#r+1] = "frozen" end
if t.permanent then r[#r+1] = "permanent" end
if t.immutable then r[#r+1] = "immutable" end
if t.primitive then r[#r+1] = "primitive" end
if t.mutable then r[#r+1] = "mutable" end
if t.noaligned then r[#r+1] = "noaligned" end
if t.instance then r[#r+1] = "instance" end
if t.tolerant then r[#r+1] = "tolerant" end
if t.protected then r[#r+1] = "protected" end
return r
end
tokens.flags= flags
interfaces.implement {
name = "showluatokens",
public = true,
protected = true,
actions = function()
local f0 = formatters["%s: %s"]
local nl = logs.newline
local wr = logs.writer
local t = token.peeknext() -- local t = token.scannext() token.putback(t)
local n = ""
local w = ""
local c = t.cmdname
if c == "left_brace" then
w = "given token list"
t = token.scantoks(false)
elseif c == "register_toks" then
token.scannext()
w = "token register"
n = t.csname or t.index
t = tex.gettoks(n,true)
elseif c == "internal_toks" then
token.scannext()
w = "internal token variable"
n = t.csname or t.index
t = tex.gettoks(n,true)
else
n = token.scancsname()
local r = flags(t)
local m = token.getmeaning(n,true)
r[#r+1] = "control sequence"
if type(m) == "table" then
t = m
else
t = { t }
end
w = concat(r, " ")
end
wr(f0(w,n))
nl()
if type(t) == "table" then
local w1 = 4
local w2 = 1
local w3 = 3
local w4 = 3
for i=1,#t do
local ti = t[i]
w1 = max(w1,#tostring(ti.id))
w2 = max(w2,#tostring(ti.command))
w3 = max(w3,#tostring(ti.index))
w4 = max(w4,#ti.cmdname)
end
local f1 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s %s"]
local f2 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s"]
local f3 = formatters["%" .. w1 .. "i %" .. w2 .. "i %" .. w3 .. "i %-" .. w4 .. "s %C"]
for i=1,#t do
local ti = t[i]
local cs = ti.csname
local id = ti.id
local ix = ti.index
local cd = ti.command
local cn = ti.cmdname
if cn == "prefix" and not cs then
cs = "always enforced"
end
cn = gsub(cn,"_"," ")
if cs then
wr(f1(id,cd,ix,cn,cs))
elseif cn == "letter" or cn == "other char" then
wr(f3(id,cd,ix,cn,ix))
elseif cn == "match" then
local s
if ix == 32 then s = "optional spacer" -- space
elseif ix == 42 then s = "skip spaces" -- *
elseif ix == 43 then s = "keep braces" -- +
elseif ix == 45 then s = "thrash" -- -
elseif ix == 47 then s = "prune" -- /
elseif ix == 58 then s = "continue" -- :
elseif ix == 59 then s = "quit" -- ;
elseif ix == 61 then s = "mandate braces" -- =
elseif ix == 94 then s = "keep spaces" -- ^
elseif ix == 95 then s = "keep mandate braces" -- _
else s = "argument " .. char(ix)
end
wr(f1(id,cd,ix,cn,s))
else
wr(f2(id,cd,ix,cn))
if cn == "end match" then
wr("--------------")
end
end
end
nl()
end
end
}
-- For the moment here, will move to initex only (also see node-ini.lua); we need
-- to actually store these.
local context = context
local function getthem(getter,post)
local codes = { }
if getter then
local texintegerdef = tex.integerdef
for k, v in next, getter() do
codes[k] = gsub(v,"[_ ]","")
end
if post ~= "" then
if environment.initex then
for k, v in next, codes do
texintegerdef(v .. post,k,"immutable")
end
end
interfaces.implement {
name = post .. "string",
public = true,
arguments = "integer",
actions = function(i)
context(codes[i] or "unknown")
end
}
end
end
return utilities.storage.allocate(table.swapped(codes,codes))
end
tex.discoptioncodes = getthem(tex.getdiscoptionvalues, "discoptioncode")
tex.flagcodes = getthem(tex.getflagvalues, "flagcode" )
tex.frozenparcodes = getthem(tex.getfrozenparvalues, "frozenparcode")
tex.glyphoptioncodes = getthem(tex.getglyphoptionvalues, "glyphoptioncode")
tex.groupcodes = getthem(tex.getgroupvalues, "groupcode")
tex.hyphenationcodes = getthem(tex.gethyphenationvalues, "hyphenationcode")
tex.mathcontrolcodes = getthem(tex.getmathcontrolvalues, "mathcontrolcode")
tex.mathflattencodes = getthem(tex.getmathflattenvalues, "mathflattencode")
tex.mathoptioncodes = getthem(tex.getmathoptionvalues, "") -- only at lua end
tex.normalizecodes = getthem(tex.getnormalizevalues, "normalizecode")
tex.automigrationcodes = getthem(tex.getautomigrationvalues, "automigrationcode") -- only at lua end
tex.parcontextcodes = getthem(tex.getparcontextvalues, "parcontextcode")
tex.textcontrolcodes = getthem(tex.gettextcontrolvalues, "") -- only at lua end
function tex.stringtocodesbitmap(str,codes)
local bitmap = 0
if codes then
if not str or str == "" then
-- zero
elseif str == "all" then
for k in next, codes do
if type(k) == "number" then
bitmap = bitmap | k
end
end
else
str = gsub(str,"[_ ]","")
for s in gmatch(str,"[^%,]+") do
local b = codes[s]
if b then
bitmap = bitmap | b
end
end
end
end
return bitmap
end
|