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
|
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 = type, tostring
local max = math.max
local formatters, gsub, char = string.formatters, string.gsub, string.char
local concat = table.concat
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.peek_next() -- local t = token.scan_next() token.put_back(t)
local n = ""
local w = ""
local c = t.cmdname
if c == "left_brace" then
w = "given token list"
t = token.scan_toks(false)
elseif c == "register_toks" then
token.scan_next()
w = "token register"
n = t.csname or t.index
t = tex.gettoks(n,true)
elseif c == "internal_toks" then
token.scan_next()
w = "internal token variable"
n = t.csname or t.index
t = tex.gettoks(n,true)
else
n = token.scan_csname()
local r = flags(t)
local m = token.get_meaning(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 groupcodes = { }
local glyphoptioncodes = { }
local hyphenationcodes = { }
local frozenparcodes = { }
local flagcodes = { }
local normalizecodes = { }
for k, v in next, tex.getgroupvalues() do
groupcodes[k] = gsub(v,"[_ ]","")
end
for k, v in next, tex.gethyphenationvalues() do
hyphenationcodes[k] = gsub(v,"[_ ]","")
end
for k, v in next, tex.getglyphoptionvalues() do
glyphoptioncodes[k] = gsub(v,"[_ ]","")
end
for k, v in next, tex.getfrozenparvalues() do
frozenparcodes[k] = gsub(v,"[_ ]","")
end
for k, v in next, tex.getflagvalues() do
flagcodes[k] = gsub(v,"[_ ]","")
end
for k, v in next, tex.getnormalizevalues() do
normalizecodes[k] = gsub(v,"[_ ]","")
end
if environment.initex then
local texintegerdef = tex.integerdef
for k, v in next, groupcodes do texintegerdef(v .. "groupcode", k,"immutable") end
for k, v in next, glyphoptioncodes do texintegerdef(v .. "code", k,"immutable") end
for k, v in next, hyphenationcodes do texintegerdef(v .. "hyphenationmodecode",k,"immutable") end
for k, v in next, frozenparcodes do texintegerdef("frozen" .. v .. "code", k,"immutable") end
for k, v in next, flagcodes do texintegerdef(v .. "flagcode", k,"immutable") end
for k, v in next, normalizecodes do texintegerdef(v .. "code", k,"immutable") end
end
groupcodes = utilities.storage.allocate(table.swapped(groupcodes, groupcodes))
glyphoptioncodes = utilities.storage.allocate(table.swapped(glyphoptioncodes,glyphoptioncodes))
hyphenationcodes = utilities.storage.allocate(table.swapped(hyphenationcodes,hyphenationcodes))
frozenparcodes = utilities.storage.allocate(table.swapped(frozenparcodes, frozenparcodes))
flagcodes = utilities.storage.allocate(table.swapped(flagcodes, flagcodes))
normalizecodes = utilities.storage.allocate(table.swapped(normalizecodes, normalizecodes))
tex.groupcodes = groupcodes
tex.glyphoptioncodes = glyphoptioncodes
tex.hyphenationcodes = hyphenationcodes
tex.frozenparcodes = frozenparcodes
tex.flagcodes = flagcodes
tex.normalizecodes = normalizecodes
|