-
Notifications
You must be signed in to change notification settings - Fork 2
/
nodetree.lua
2754 lines (2534 loc) · 77.2 KB
/
nodetree.lua
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
--- This file (`nodetree.lua`) is part of the LuaTeX package
--- 'nodetree'.
---
---`nodetree` uses the annotation system of the
---[lua-language-server](https://github.com/LuaLS/lua-language-server/wiki/Annotations).
---Install the [type definitions for LuaTeX](https://github.com/Josef-Friedrich/LuaTeX_Lua-API)
---or the [Visual Studio Code Extension](https://marketplace.visualstudio.com/items?itemName=JosefFriedrich.luatex).
---
---The LDoc support is deprecated.
---
---Nodes in LuaTeX are connected. The nodetree view distinguishes
---between *list* and *field* connections.
---
---* list: Nodes that are doubly connected by `next` and `previous`
--- fields.
---* field: Connections to nodes by other fields than `next` and
--- `previous` fields, e.g., `head`, `pre`.
---@module nodetree
---luacheck: globals node lang tex luatexbase lfs
---luacheck: globals callback os unicode status modules
---
---@alias ColorName 'black'|'red' |'green'|'yellow'|'blue'|'magenta'|'cyan'|'white'|'reset'
---@alias ColorMode 'bright'|'dim'|''
---
---@alias ConnectionType 'list'|'field' # A string literal,
--- which can be either 'list' or 'field'.
---@alias ConnectionState 'stop'|'continue' # A literal, which can
--- be either `continue` or `stop`.
if not modules then modules = {} end modules ['nodetree'] = {
version = '2.4.0',
comment = 'nodetree',
author = 'Josef Friedrich',
copyright = 'Josef Friedrich',
license = 'The LaTeX Project Public License Version 1.3c 2008-05-04'
}
local direct = node.direct
local todirect = direct.todirect
local getchar = direct.getchar
---Lua 5.1 does not have the utf8 library (Lua 5.1 is the default
---version in LuajitTeX). LuaJitTeX does include the slnunicode library.
local utf8 = utf8 or unicode.utf8
local utfchar = utf8.char
local properties = direct.get_properties_table()
---A counter for the compiled TeX examples. Some TeX code snippets
---a written into files, wrapped with some TeX boilerplate code.
---These written files are compiled later on.
local example_counter = 0
---A flag to indicate that something has been emitted by nodetree.
local have_output = false
--- The default options.
local default_options = {
callback = 'post_linebreak_filter',
channel = 'term',
color = 'colored',
decimalplaces = 2,
unit = 'pt',
verbosity = 0,
firstline = 1,
lastline = -1,
}
--- The current options.
local options = {}
for key, value in pairs(default_options) do
options[key] = value
end
--- The previous options.
---We need this for functions `push_options` and `pop_options` so that
---the effects of the `\setkeys` commands in `nodetree-embed.sty`
---(which directly manipulates the `options` table) stay local.
local prev_options = {}
local option_level = 0
---File descriptor.
local output_file
--- The state values of the current tree item.
---
---`tree_state`:
---
---* `1` (level):
--- * `list`: `continue`
--- * `field`: `stop`
---* `2`:
--- * `list`: `continue`
--- * `field`: `stop`
---
---...
local tree_state = {}
--- Format functions.
---
---Low-level template functions.
---
---@section format
local format = {
---@function format.underscore
---
---@param input string
---
---@return string
underscore = function(input)
if options.channel == 'tex' then
local result = input.gsub(input, '_', '\\_')
return result
else
return input
end
end,
---@function format.escape
---
---@param input string
---
---@return string
escape = function(input)
if options.channel == 'tex' then
local result = input.gsub(input, [[\]], [[\string\]])
return result
else
return input
end
end,
---@function format.function
---
---@param input number
---
---@return number
number = function(input)
local mult = 10^(options.decimalplaces or 0)
return math.floor(input * mult + 0.5) / mult
end,
---@function format.whitespace
---
---@param count? number # How many spaces should be output.
---
---@return string
whitespace = function(count)
local whitespace
local output = ''
if options.channel == 'tex' then
whitespace = '\\hspace{0.5em}'
else
whitespace = ' '
end
if not count then
count = 1
end
for _ = 1, count do
output = output .. whitespace
end
return output
end,
---@function format.color_code
---
---@param code number
---
---@return string
color_code = function(code)
return string.char(27) .. '[' .. tostring(code) .. 'm'
end,
---@function format.color_tex
---
---@param color string
---@param mode? string
---
---@return string
color_tex = function(color, mode)
if not mode then mode = '' end
return 'NTE' .. color .. mode
end,
---@function format.node_begin
---
---@return string
node_begin = function()
if options.channel == 'tex' then
return '\\mbox{'
else
return ''
end
end,
---@function format.node_end
---
---@return string
node_end = function()
if options.channel == 'tex' then
return '}'
else
return ''
end
end,
---@function format.new_line
---
---@param count? number # How many new lines should be output.
---
---@return string
new_line = function(count)
local output = ''
if not count then
count = 1
end
local new_line
if options.channel == 'tex' then
new_line = '\\par\n'
else
new_line = '\n'
end
for _ = 1, count do
output = output .. new_line
end
return output
end,
---@function format.type_id
---
---@param id number
---
---@return string
type_id = function(id)
return '[' .. tostring(id) .. ']'
end
}
--- Print the output to stdout or write it into a file (`output_file`).
---New text is appended.
---
---@param text string # A text string.
local function nodetree_print(text)
if options.channel == 'log' or options.channel == 'tex' then
output_file:write(text)
else
io.write(text)
end
end
--- Template functions.
---
---@section template
local template = {
node_colors = {
hlist = {'red', 'bright'},
vlist = {'green', 'bright'},
rule = {'blue', 'bright'},
ins = {'blue'},
mark = {'magenta'},
adjust = {'cyan'},
boundary = {'red', 'bright'},
disc = {'green', 'bright'},
whatsit = {'yellow', 'bright'},
local_par = {'blue', 'bright'},
dir = {'magenta', 'bright'},
math = {'cyan', 'bright'},
glue = {'magenta', 'bright'},
kern = {'green', 'bright'},
penalty = {'yellow', 'bright'},
unset = {'blue'},
style = {'magenta'},
choice = {'cyan'},
noad = {'red'},
radical = {'green'},
fraction = {'yellow'},
accent = {'blue'},
fence = {'magenta'},
math_char = {'cyan'},
sub_box = {'red', 'bright'},
sub_mlist = {'green', 'bright'},
math_text_char = {'yellow', 'bright'},
delim = {'blue', 'bright'},
margin_kern = {'magenta', 'bright'},
glyph = {'cyan', 'bright'},
align_record = {'red'},
pseudo_file = {'green'},
pseudo_line = {'yellow'},
page_insert = {'blue'},
split_insert = {'magenta'},
expr_stack = {'cyan'},
nested_list = {'red'},
span = {'green'},
attribute = {'yellow'},
glue_spec = {'magenta'},
attribute_list = {'cyan'},
temp = {'magenta'},
align_stack = {'red', 'bright'},
movement_stack = {'green', 'bright'},
if_stack = {'yellow', 'bright'},
unhyphenated = {'magenta', 'bright'},
hyphenated = {'cyan', 'bright'},
delta = {'red'},
passive = {'green'},
shape = {'yellow'},
},
-- Field name abbreviations for verbosity level 0. A second field
-- limits the abbreviation to this node type.
--
-- Entry '' means to omit the key, printing only the value. Entry
-- '()' means the same, but the value gets printed in parentheses.
field_abbrevs = {
char = {''},
depth = {'dp'},
dir = {'()', 'dir'},
height = {'ht'},
kern = {''},
mark = {''},
penalty = {'', 'penalty'},
shrink = {'minus'},
stretch = {'plus'},
style = {''},
subtype = {'()'},
width = {'wd'},
},
--- [SGR (Select Graphic Rendition)
-- parameters](https://en.wikipedia.org/wiki/ANSI_escape_code#SGR_parameters).
--
-- __attributes__
--
-- | color |code|
-- |------------|----|
-- | reset | 0 |
-- | clear | 0 |
-- | bright | 1 |
-- | dim | 2 |
-- | underscore | 4 |
-- | blink | 5 |
-- | reverse | 7 |
-- | hidden | 8 |
--
-- __foreground__
--
-- | color |code|
-- |------------|----|
-- | black | 30 |
-- | red | 31 |
-- | green | 32 |
-- | yellow | 33 |
-- | blue | 34 |
-- | magenta | 35 |
-- | cyan | 36 |
-- | white | 37 |
--
-- __background__
--
-- | color |code|
-- |------------|----|
-- | onblack | 40 |
-- | onred | 41 |
-- | ongreen | 42 |
-- | onyellow | 43 |
-- | onblue | 44 |
-- | onmagenta | 45 |
-- | oncyan | 46 |
-- | onwhite | 47 |
--
---@function template.color
---
---@param color ColorName # A color name.
---@param mode? ColorMode
---@param background? boolean # If set, colorize the background instead of the text.
---
---@return string
color = function(color, mode, background)
if options.color ~= 'colored' then
return ''
end
local output = ''
local code
if mode == 'bright' then
output = format.color_code(1)
elseif mode == 'dim' then
output = format.color_code(2)
end
if not background then
if color == 'reset' then code = 0
elseif color == 'red' then code = 31
elseif color == 'green' then code = 32
elseif color == 'yellow' then code = 33
elseif color == 'blue' then code = 34
elseif color == 'magenta' then code = 35
elseif color == 'cyan' then code = 36
else code = 37 end
else
if color == 'black' then code = 40
elseif color == 'red' then code = 41
elseif color == 'green' then code = 42
elseif color == 'yellow' then code = 43
elseif color == 'blue' then code = 44
elseif color == 'magenta' then code = 45
elseif color == 'cyan' then code = 46
elseif color == 'white' then code = 47
else code = 40 end
end
return output .. format.color_code(code)
end,
--- Format the char field of a node. Try to find a textual representation that
-- corresponds with the number stored in the `char` field.
--
-- LuaTeX’s `node.char` values are not really characters; they are font glyph indices
-- which sometimes happen to match valid Unicode characters. HarfBuzz shapers
-- differentiate between glyph IDs and characters by adding to 0x120000 to
-- glyph IDs.
--
-- The code of this function is borrowed from the [function
-- `get_glyph_info(n)`](https://github.com/latex3/luaotfload/blob/4c09fe264c1644792d95182280be259449e7da02/src/luaotfload-harf-plug.lua#L1018-L1031)
-- of the luaotfload package. The harfbuzz mode in luaotfload uses this
-- function to embed text in a PDF file and for messages that show textual
-- representation of the nodes like over/underfull messages. It will not
-- result in an error in other modes, but it might not give proper text
-- representation, but that is a limitation of these modes.
--
-- It should be understood what the glyph nodes represent. Before
-- processing by luaotfload they represent one-to-one mapping of the
-- input characters. After processing, they represent font glyphs with
-- potentially complicated relationship with input characters.
--
-- Relation between input characters and output glyphs are many-to-many.
-- An input character may be represented by one or more glyphs, and
-- output glyph might represent one or more input characters, and in
-- some cases (e.g. when there is reordering) a group of input
-- characters are represented by a group of output glyphs. In the 2nd
-- and 3rd cases, the first glyph node will have a `glyph_info` property
-- with all the characters of the group, and subsequent glyph nodes in
-- the group will have empty `glyph_info` properties.
--
-- It should also noted that this mapping is not unique, the same glyph
-- can represent different characters in different context.
--
---@function template.char
--
---@param head Node # The head node of a node list.
---
---@return string # A textual representation of the `char` number.
char = function(head)
local node_id = todirect(head) -- Convert to node id.
local props = properties[node_id]
local info = props and props.glyph_info
local textual
local character_index = getchar(node_id)
if info then
textual = info
elseif character_index == 0 then
textual = '^^@'
elseif character_index <= 31 or (character_index >= 127 and character_index <= 159) then
-- The C0 range [c-zero] contains characters from U+0000 to U+001F
-- (decimal 0-31) and U+007F (decimal 127), the C1 range covers
-- characters from U+0080 to U+009F (decimal 128-159).
textual = '???'
elseif character_index ~= nil and character_index < 0x110000 then
textual = utfchar(character_index)
else
textual = string.format('^^^^^^%06X', character_index)
end
if options.verbosity == 0 then
if textual == '???' then
return character_index
else
return "'" .. textual .. "'"
end
elseif options.verbosity <= 2 then
return character_index .. " ('" .. textual .. "')"
else
return character_index
.. ' ('
.. string.format('0x%x', character_index)
.. ", '"
.. textual
.. "')"
end
end,
---@function template.line
---
---@param length string # If `long`, emit a longer line.
---
---@return string
line = function(length)
local output
if length == 'long' then
output = '------------------------------------------'
else
output = '-----------------------'
end
return output .. format.new_line()
end,
---@function template.branch
---
---@param connection_type ConnectionType
---@param connection_state ConnectionState
---@param last boolean
---
---@return string
branch = function(connection_type, connection_state, last)
local c = connection_type
local s = connection_state
local l = last
if c == 'list' and s == 'stop' and l == false then
return format.whitespace(2)
elseif c == 'field' and s == 'stop' and l == false then
return format.whitespace(2)
elseif c == 'list' and s == 'continue' and l == false then
return '│' .. format.whitespace()
elseif c == 'field' and s == 'continue' and l == false then
return '║' .. format.whitespace()
elseif c == 'list' and s == 'continue' and l == true then
return '├─'
elseif c == 'field' and s == 'continue' and l == true then
return '╠═'
elseif c == 'list' and s == 'stop' and l == true then
return '└─'
elseif c == 'field' and s == 'stop' and l == true then
return '╚═'
end
return ''
end,
}
---@param number number
---@param order number
---@param field string
---
---@return string
function template.fill(number, order, field)
local output
if order ~= nil and order ~= 0 then
if field == 'stretch' then
output = '+'
else
output = '-'
end
return output .. string.format(
'%g%s', number / 2^16,
template.colored_string(
'fi' .. string.rep('l', order - 1),
'white',
'dim'
)
)
else
return template.length(number)
end
end
--- Colorize a text string.
---
---@param text string # A text string.
---@param color ColorName # A color name.
---@param mode? ColorMode
---@param background? boolean # If set, colorize the background instead of the text.
---
---@return string
function template.colored_string(text, color, mode, background)
if options.channel == 'tex' then
if mode == 'dim' then
mode = ''
end
return '\\textcolor{' ..
format.color_tex(color, mode) ..
'}{' ..
text ..
'}'
else
return template.color(color, mode, background) .. text .. template.color('reset')
end
end
--- Format a scaled point input value into dimension string (`12pt`,
--- `1cm`)
---
---@param input number
---
---@return string
function template.length(input)
local i = tonumber(input)
if i ~= nil then
input = i / tex.sp('1' .. options.unit)
end
return string.format(
'%g%s',
format.number(input),
template.colored_string(options.unit, 'white', 'dim')
)
end
--- Get all data from a table including metatables.
---
---Properties will reside in a metatable if nodes were copied using an
---operation like box copy: (\copy). The LuaTeX manual states this: “If
---the second argument of `set_properties_mode` is true, then a
---metatable approach is chosen: the copy gets its own table with the
---original table as metatable.”
---
---Source: [StackOverflow](https://stackoverflow.com/a/5639667) – this
---works if `__index` returns a table, which it should as per LuaTeX
---manual.
---
---@param data table # A Lua table.
---@param previous_data? table # The data of a Lua table of a previous recursive call.
---
---@return table # A merged table.
local function get_all_table_data(data, previous_data)
-- If previous_data is nil, start empty, otherwise start with previous_data.
local output = previous_data or {}
-- Copy all the attributes from the table.
for key, value in pairs(data) do
output[key] = output[key] or value
end
-- Get table’s metatable, or exit if not existing.
local metatable = getmetatable(data)
if type(metatable) ~= 'table' then
return output
end
-- Get the `__index` from metatable, or exit if not table.
local index = metatable.__index
if type(index) ~= 'table' then
return output
end
-- Include the data from index into data recursively and return.
return get_all_table_data(index, output)
end
--- Convert a Lua table into a format string.
---
---@param tbl table # A table to generate an inline view of.
---
---@return string
function template.table_inline(tbl)
local tex_escape = ''
if options.channel == 'tex' then
tex_escape = '\\'
end
if type(tbl) == 'table' then
tbl = get_all_table_data(tbl)
local output = tex_escape .. '{'
local kv_list = ''
local keys = {}
for key in pairs(tbl) do
keys[#keys + 1] = key
end
table.sort(keys)
for i = 1, #keys do
local key = keys[i]
local value = tbl[key]
if type(key) ~= 'numbers' then
key = '\'' ..
template.colored_string(key, 'cyan', 'dim') .. '\''
end
kv_list = kv_list .. '[' .. key .. '] = ' ..
template.table_inline(value) .. ', '
end
output = output .. kv_list:gsub(', $', '')
return output .. tex_escape .. '}'
else
return tostring(tbl)
end
end
--- Format a key-value pair (`key: value, `).
---
---@param key string # A key.
---@param value string|number # A value.
---@param typ? string # A node type. Had to be named typ to avoid conflict with the type() function.
---@param color? ColorName # A color name.
---
---@return string
function template.key_value(key, value, typ, color)
if type(color) ~= 'string' then
color = 'yellow'
end
key = format.underscore(key)
local output = ''
local abbrev = nil
local separator = ':'
if options.verbosity == 0 then
if template.field_abbrevs[key] then
local only_this_type = template.field_abbrevs[key][2]
if not only_this_type or not typ or only_this_type == typ then
abbrev = template.field_abbrevs[key][1]
end
end
separator = ''
end
if abbrev == nil then
output = template.colored_string(key .. separator, color)
elseif abbrev ~= '' and abbrev ~= '()' then
output = template.colored_string(abbrev, color)
end
if value then
if abbrev == '()' then
-- Printing '(unused)' is confusing.
if value ~= 'unused' then
output = output .. '(' .. value .. ') '
end
elseif abbrev == '' then
output = output .. value .. ', '
else
output = output .. ' ' .. value .. ', '
end
end
return output
end
---@param type string
---@param id number
---
---@return string
function template.type(type, id)
local output
output = format.underscore(type)
output = string.upper(output)
if options.verbosity > 1 then
output = output .. format.type_id(id)
end
return template.colored_string(
output,
template.node_colors[type][1],
template.node_colors[type][2]
)
end
---@param callback_name string
---@param variables table|nil
---@param where 'before'|'after' # `'before'` or `'after'`
function template.callback(callback_name, variables, where)
if options.channel == 'term' or have_output == true then
nodetree_print(format.new_line(2))
end
have_output = true
nodetree_print(
where .. ' callback ' ..
template.colored_string(format.underscore(callback_name), 'red', '', true) ..
format.new_line()
)
if variables then
for name, value in pairs(variables) do
if value ~= nil and value ~= '' then
nodetree_print(
'- ' ..
format.underscore(name) ..
': ' ..
format.underscore(tostring(value)) ..
format.new_line()
)
end
end
end
nodetree_print(template.line('long'))
end
--- Format the branching tree for one output line.
---
---@param level number
---@param connection_type ConnectionType
---
---@return string
function template.branches(level, connection_type)
local output = ''
for i = 1, level - 1 do
output = output .. template.branch('list', tree_state[i]['list'], false)
output = output .. template.branch('field', tree_state[i]['field'], false)
end
---Format the last branches
if connection_type == 'list' then
output = output .. template.branch('list', tree_state[level]['list'], true)
else
output = output .. template.branch('list', tree_state[level]['list'], false)
output = output .. template.branch('field', tree_state[level]['field'], true)
end
return output
end
--- Node library extensions.
---
---@section node_extended
local node_extended = {}
--- Get the ID of a node.
---
---We have to convert the node into a string and then to extract
---the ID from this string using a regular expression. If you convert a
---node into a string it looks like: `<node nil < 172 > nil :
---hlist 2>`.
---
---@param n Node # A node.
---
---@return string
function node_extended.node_id(n)
local result = string.gsub(tostring(n), '^<node%s+%S+%s+<%s+(%d+).*', '%1')
return result
end
--- A table of all node subtype names.
---
---__Nodes without subtypes:__
---
---* `ins` (3)
---* `local_par` (9)
---* `penalty` (14)
---* `unset` (15)
---* `style` (16)
---* `choice` (17)
---* `fraction` (20)
---* `math_char` (23)
---* `sub_box` (24)
---* `sub_mlist` (25)
---* `math_text_char` (26)
---* `delim` (27)
---* `margin_kern` (28)
---* `align_record` (30)
---* `pseudo_file` (31)
---* `pseudo_line` (32)
---* `page_insert` (33)
---* `split_insert` (34)
---* `expr_stack` (35)
---* `nested_list` (36)
---* `span` (37)
---* `attribute` (38)
---* `glue_spec` (39)
---* `attribute_list` (40)
---* `temp` (41)
---* `align_stack` (42)
---* `movement_stack` (43)
---* `if_stack` (44)
---* `unhyphenated` (45)
---* `hyphenated` (46)
---* `delta` (47)
---* `passive` (48)
---* `shape` (49)
---
---@return table
local function get_node_subtypes()
local subtypes = {
-- hlist (0)
hlist = {
[0] = 'unknown',
[1] = 'line',
[2] = 'box',
[3] = 'indent',
[4] = 'alignment',
[5] = 'cell',
[6] = 'equation',
[7] = 'equationnumber',
[8] = 'math',
[9] = 'mathchar',
[10] = 'hextensible',
[11] = 'vextensible',
[12] = 'hdelimiter',
[13] = 'vdelimiter',
[14] = 'overdelimiter',
[15] = 'underdelimiter',
[16] = 'numerator',
[17] = 'denominator',
[18] = 'limits',
[19] = 'fraction',
[20] = 'nucleus',
[21] = 'sup',
[22] = 'sub',
[23] = 'degree',
[24] = 'scripts',
[25] = 'over',
[26] = 'under',
[27] = 'accent',
[28] = 'radical',
},
-- vlist (1)
vlist = {
[0] = 'unknown',
[4] = 'alignment',
[5] = 'cell',
},
-- rule (2)
rule = {
[0] = 'normal',
[1] = 'box',
[2] = 'image',
[3] = 'empty',
[4] = 'user',
[5] = 'over',
[6] = 'under',
[7] = 'fraction',
[8] = 'radical',
[9] = 'outline',
},
-- mark (4)
-- The subtype is not used.
mark = {
[0] = 'unused',
},
-- adjust (5)
adjust = {
[0] = 'normal',
[1] = 'pre',
},
-- boundary (6)
boundary = {
[0] = 'cancel',
[1] = 'user',
[2] = 'protrusion',
[3] = 'word',
},
-- disc (7)
disc = {
[0] = 'discretionary',
[1] = 'explicit',
[2] = 'automatic',
[3] = 'regular',
[4] = 'first',
[5] = 'second',
},
-- dir (10)
-- This is an internal detail, see luatex source code file
-- `texnodes.h`.
-- dir = {
-- [0] = 'normal_dir',
-- [1] = 'cancel_dir',
-- },
-- math (11)
math = {
[0] = 'beginmath',
[1] = 'endmath',
},
-- glue (12)
glue = {
[0] = 'userskip',
[1] = 'lineskip',
[2] = 'baselineskip',
[3] = 'parskip',
[4] = 'abovedisplayskip',
[5] = 'belowdisplayskip',
[6] = 'abovedisplayshortskip',
[7] = 'belowdisplayshortskip',
[8] = 'leftskip',
[9] = 'rightskip',
[10] = 'topskip',
[11] = 'splittopskip',
[12] = 'tabskip',
[13] = 'spaceskip',
[14] = 'xspaceskip',
[15] = 'parfillskip',
[16] = 'mathskip',
[17] = 'thinmuskip',
[18] = 'medmuskip',
[19] = 'thickmuskip',
[98] = 'conditionalmathskip',
[99] = 'muglue',
[100] = 'leaders',
[101] = 'cleaders',
[102] = 'xleaders',
[103] = 'gleaders',
},
-- kern (13)
kern = {
[0] = 'fontkern',
[1] = 'userkern',
[2] = 'accentkern',
[3] = 'italiccorrection',
},
-- penalty (14)
penalty = {
[0] = 'userpenalty',
[1] = 'linebreakpenalty',
[2] = 'linepenalty',
[3] = 'wordpenalty',
[4] = 'finalpenalty',
[5] = 'noadpenalty',