node-tsk.lmt /size: 24 Kb    last modification: 2025-02-21 11:03
1if not modules then modules = { } end modules ['node-tsk'] = {
2    version   = 1.001,
3    comment   = "companion to node-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
9-- This might move to task-* and become less code as in sequencers
10-- we already have dirty flags as well. On the other hand, nodes are
11-- rather specialized and here we focus on node related tasks.
12
13local format = string.format
14
15local trace_tasks = false  trackers.register("tasks.creation", function(v) trace_tasks = v end)
16
17local report_tasks  = logs.reporter("tasks")
18
19local allocate      = utilities.storage.allocate
20
21local context       = context
22local nodes         = nodes
23
24local tasks         = nodes.tasks or { }
25nodes.tasks         = tasks
26
27local tasksdata     = { } -- no longer public
28
29local sequencers    = utilities.sequencers
30local compile       = sequencers.compile
31local nodeprocessor = sequencers.nodeprocessor
32
33local newsequencer  = sequencers.new
34
35local appendgroup   = sequencers.appendgroup
36----- prependgroup  = sequencers.prependgroup
37----- replacegroup  = sequencers.replacegroup
38local enablegroup   = sequencers.enablegroup
39local disablegroup  = sequencers.disablegroup
40
41local appendaction  = sequencers.appendaction
42local prependaction = sequencers.prependaction
43local replaceaction = sequencers.replaceaction
44local enableaction  = sequencers.enableaction
45local disableaction = sequencers.disableaction
46
47local frozengroups  = "no"
48
49function tasks.freeze(kind)
50    frozengroups = kind or "tolerant" -- todo: hook into jobname
51end
52
53function tasks.new(specification) -- was: name,arguments,list
54    local name      = specification.name
55    local sequence  = specification.sequence
56    if name and sequence then
57        local tasklist = newsequencer {
58            name = name
59            -- we can move more to the sequencer now .. todo
60        }
61        tasksdata[name] = {
62            name      = name,
63            list      = tasklist,
64            runner    = false,
65            frozen    = { },
66            processor = specification.processor or nodeprocessor,
67            -- could be metatable but best freeze it
68            arguments = specification.arguments or 0,
69            templates = specification.templates,
70        }
71        for l=1,#sequence do
72            appendgroup(tasklist,sequence[l])
73        end
74    end
75end
76
77local function valid(name)
78    local data = tasksdata[name]
79    if not data then
80        report_tasks("unknown task %a",name)
81    else
82        return data
83    end
84end
85
86local function validgroup(name,group,what)
87    local data = tasksdata[name]
88    if not data then
89        report_tasks("unknown task %a",name)
90    else
91        local frozen = data.frozen[group]
92        if frozen then
93            if frozengroup == "no" then
94                -- default
95            elseif frozengroup == "strict" then
96                report_tasks("warning: group %a of task %a is frozen, %a applied but not supported",group,name,what)
97                return
98            else -- if frozengroup == "tolerant" then
99                report_tasks("warning: group %a of task %a is frozen, %a ignored",group,name,what)
100            end
101        end
102        return data
103    end
104end
105
106function tasks.freezegroup(name,group)
107    local data = valid(name)
108    if data then
109        data.frozen[group] = true
110    end
111end
112
113function tasks.restart(name)
114    local data = valid(name)
115    if data then
116        data.runner = false
117    end
118end
119
120function tasks.enableaction(name,action)
121    local data = valid(name)
122    if data then
123        enableaction(data.list,action)
124        data.runner = false
125    end
126end
127
128function tasks.disableaction(name,action)
129    local data = valid(name)
130    if data then
131        disableaction(data.list,action)
132        data.runner = false
133    end
134end
135
136function tasks.replaceaction(name,group,oldaction,newaction)
137    local data = valid(name)
138    if data then
139        replaceaction(data.list,group,oldaction,newaction)
140        data.runner = false
141    end
142end
143
144do
145
146    local enableaction  = tasks.enableaction
147    local disableaction = tasks.disableaction
148
149    function tasks.setaction(name,action,value)
150        if value then
151            enableaction(name,action)
152        else
153            disableaction(name,action)
154        end
155    end
156
157end
158
159function tasks.enablegroup(name,group)
160    local data = validgroup(name,"enable group")
161    if data then
162        enablegroup(data.list,group)
163        data.runner = false
164    end
165end
166
167function tasks.disablegroup(name,group)
168    local data = validgroup(name,"disable group")
169    if data then
170        disablegroup(data.list,group)
171        data.runner = false
172    end
173end
174
175function tasks.appendaction(name,group,action,where,kind,state)
176    local data = validgroup(name,"append action")
177    if data then
178        local list = data.list
179        appendaction(list,group,action,where,kind)
180        if state == "disabled" or (state == "production" and environment.initex) then
181            disableaction(list,action)
182        end
183        data.runner = false
184    end
185end
186
187function tasks.prependaction(name,group,action,where,kind,state)
188    local data = validgroup(name,"prepend action")
189    if data then
190        local list = data.list
191        prependaction(list,group,action,where,kind)
192        if state == "disabled" or (state == "production" and environment.initex) then
193            disableaction(list,action)
194        end
195        data.runner = false
196    end
197end
198
199function tasks.removeaction(name,group,action)
200    local data = validgroup(name,"remove action")
201    if data then
202        removeaction(data.list,group,action)
203        data.runner = false
204    end
205end
206
207function tasks.showactions(name,group,action,where,kind)
208    local data = valid(name)
209    if data then
210        report_tasks("task %a, list:\n%s",name,nodeprocessor(data.list))
211    end
212end
213
214-- Optimizing for the number of arguments makes sense, but getting rid of
215-- the nested call (no problem but then we also need to register the
216-- callback with this mechanism so that it gets updated) does not save
217-- much time (24K calls on mk.tex).
218
219local created, total = 0, 0
220
221statistics.register("node list callback tasks", function()
222    if total > 0 then
223        return format("%s unique task lists, %s instances (re)created, %s calls",table.count(tasksdata),created,total)
224    else
225        return nil
226    end
227end)
228
229local function create(data,t)
230    created = created + 1
231    local runner = compile(data.list,data.processor,t)
232    if trace_tasks then
233        report_tasks("creating runner %a, %i actions enabled",t.name,data.list.steps or 0)
234    end
235    data.runner = runner
236    return runner
237end
238
239function tasks.actions(name)
240    local data = tasksdata[name]
241    if data then
242        local t = data.templates
243        if t then
244            t.name = data.name
245            return function(...)
246                total = total + 1
247                return (data.runner or create(data,t))(...)
248            end
249        end
250    end
251    return nil
252end
253
254function tasks.table(name) --maybe move this to task-deb.lua
255    local tsk = tasksdata[name]
256    local lst = tsk and tsk.list
257    local HL, NC, NR, bold, type = context.HL, context.NC, context.NR, context.bold, context.type
258    if lst then
259        local list, order = lst.list, lst.order
260        if list and order then
261            context.starttabulate { "|l|l|" }
262            NC() bold("category") NC() bold("function") NC() NR()
263            for i=1,#order do
264                HL()
265                local o = order[i]
266                local l = list[o]
267                if #l == 0 then
268                    NC() type(o) NC() context("unset") NC() NR()
269                else
270                    local done = false
271                    for k, v in table.sortedhash(l) do
272                        NC() if not done then type(o) done = true end NC() type(v) NC() NR()
273                    end
274                end
275            end
276            context.stoptabulate()
277        end
278    end
279end
280
281-- -- shipouts -- --
282
283-- the shipout handlers acts on boxes so we don't need to return something
284-- and also don't need to keep the state (done)
285
286tasks.new {
287    name      = "shipouts",
288    processor = nodeprocessor,
289    sequence  = {
290        "before",      -- users
291        "normalizers", -- system
292        "finishers",   -- system
293        "after",       -- users
294        "wrapup",      -- system
295    },
296    templates = {
297
298default = [[
299return function(head,ispage)
300    return head
301end
302]],
303
304process = [[
305local tonut  = nodes.tonut
306local tonode = nodes.nuts.tonode
307
308%localize%
309
310return function(head,ispage)
311    local nuthead = tonut(head)
312
313%actions%
314    return tonode(nuthead)
315end
316]],
317
318step = [[
319    nuthead = tonut((%action%(tonode(nuthead),ispage)))
320]],
321
322nut  = [[
323    nuthead = %action%(nuthead,ispage)
324]],
325
326nohead = [[
327    %action%(tonode(nuthead),ispage)
328]],
329
330nonut = [[
331    %action%(nuthead,ispage)
332]],
333
334    }
335}
336
337-- -- everypar -- --
338
339tasks.new {
340    name      = "everypar",
341    processor = nodeprocessor,
342    sequence  = {
343        "before",      -- users
344        "normalizers", -- system
345        "after",       -- users
346    },
347    templates = {
348
349default = [[
350return function(head)
351    return head
352end
353]],
354
355process = [[
356local tonut  = nodes.tonut
357local tonode = nodes.nuts.tonode
358
359%localize%
360
361return function(head,mode)
362    local nuthead = tonut(head)
363
364%actions%
365    return tonode(nuthead)
366end
367]],
368
369step = [[
370    nuthead = tonut((%action%(tonode(nuthead),mode)))
371]],
372
373nut  = [[
374    nuthead = %action%(nuthead,mode)
375]],
376
377nohead = [[
378    %action%(tonode(nuthead),mode)
379]],
380
381nonut = [[
382    %action%(nuthead,mode)
383]],
384
385    }
386}
387
388-- -- alignment -- -- gets temp node ! (currently as that might change)
389
390tasks.new {
391    name      = "alignments",
392    processor = nodeprocessor,
393    sequence  = {
394        "before",      -- users
395        "normalizers", -- system
396        "after",       -- users
397    },
398    templates = {
399
400default = [[
401return function(head)
402end
403]],
404
405process = [[
406local tonut  = nodes.tonut
407local tonode = nodes.nuts.tonode
408
409%localize%
410
411return function(head,where,callback,attr,preamble)
412    local nuthead     = tonut(head)
413    local nutattr     = tonut(attr)
414    local nutpreamble = tonut(preamble)
415
416%actions%
417end
418]],
419
420step = [[
421    %action%(head,where,callback,attr,preamble)
422]],
423
424nut  = [[
425    %action%(nuthead,where,callback,nutattr,nutpreamble)
426]],
427
428nohead = [[
429    %action%(head,where,callback,attr,preamble)
430]],
431
432nonut = [[
433    %action%(nuthead,where,callback,nutattr,nutpreamble)
434]],
435
436    }
437}
438
439-- -- finalizers -- --
440
441tasks.new {
442    name      = "finalizers",
443    sequence  = {
444        "before",      -- for users
445        "normalizers",
446        "fonts",
447        "lists",
448        "after",       -- for users
449    },
450    processor = nodeprocessor,
451    templates = {
452
453default = [[
454return function(head)
455    return head
456end
457]],
458
459process = [[
460local tonut  = nodes.tonut
461local tonode = nodes.nuts.tonode
462
463%localize%
464
465return function(head,groupcode)
466    local nuthead = tonut(head)
467
468%actions%
469    return tonode(nuthead)
470end
471]],
472
473step = [[
474    nuthead = tonut((%action%(tonode(nuthead),groupcode)))
475]],
476
477nut  = [[
478    nuthead = %action%(nuthead,groupcode)
479]],
480
481nohead = [[
482    %action%(tonode(nuthead),groupcode)
483]],
484
485nonut = [[
486    %action%(nuthead,groupcode)
487]],
488
489    }
490}
491
492-- -- processors -- --
493
494tasks.new {
495    name      = "processors",
496    processor = nodeprocessor,
497    sequence  = {
498        "before",      -- for users
499        "normalizers",
500        "characters",
501        "words",
502        "fonts",
503        "lists",
504        "after",       -- for users
505    },
506    templates = {
507
508default = [[
509return function(head)
510    return head
511end
512]],
513
514process = [[
515local tonut  = nodes.tonut
516local tonode = nodes.nuts.tonode
517
518%localize%
519
520return function(head,groupcode,direction)
521    local nuthead = tonut(head)
522
523%actions%
524    return tonode(nuthead)
525end
526]],
527
528step = [[
529    nuthead = tonut((%action%(tonode(nuthead),groupcode,direction)))
530]],
531
532nut  = [[
533    nuthead = %action%(nuthead,groupcode,direction)
534]],
535
536nohead = [[
537    %action%(tonode(nuthead),groupcode,direction)
538]],
539
540nonut = [[
541    %action%(nuthead,groupcode,direction)
542]],
543
544    }
545}
546
547-- -- paragraphs -- --
548
549tasks.new {
550    name      = "paragraphs",
551    processor = nodeprocessor,
552    sequence  = {
553        "before",      -- for users
554        "lists",
555        "after",       -- for users
556    },
557    templates = {
558
559default = [[
560return function(head)
561    return head
562end
563]],
564
565process = [[
566local tonut  = nodes.tonut
567local tonode = nodes.nuts.tonode
568
569%localize%
570
571return function(head,groupcode)
572    local nuthead = tonut(head)
573
574%actions%
575    return tonode(nuthead)
576end
577]],
578
579step = [[
580    nuthead = tonut((%action%(tonode(nuthead),groupcode)))
581]],
582
583nut  = [[
584    nuthead = %action%(nuthead,groupcode)
585]],
586
587nohead = [[
588    %action%(tonode(nuthead),groupcode)
589]],
590
591nonut = [[
592    %action%(nuthead,groupcode)
593]],
594
595    }
596}
597
598-- -- hpackers -- --
599
600-- tasks.new {
601--     name      = "processors",
602--     processor = nodeprocessor,
603--     sequence  = {
604--         "before",      -- for users
605--         "normalizers",
606--         "characters",
607--         "words",
608--         "fonts",
609--         "lists",
610--         "after",       -- for users
611--     },
612--     templates = {
613--
614-- default = [[
615-- return function(head)
616--     return head
617-- end
618-- ]],
619--
620-- process = [[
621-- local tonut  = nodes.tonut
622-- local tonode = nodes.nuts.tonode
623--
624-- %localize%
625--
626-- return function(head,groupcode,size,packtype,direction,attributes)
627--     local nuthead = tonut(head)
628--
629-- %actions%
630--     return tonode(nuthead)
631-- end
632-- ]],
633--
634-- step = [[
635--     nuthead = tonut((%action%(tonode(nuthead),groupcode,size,packtype,direction,attributes)))
636-- ]],
637--
638-- nut  = [[
639--     nuthead = %action%(nuthead,groupcode,size,packtype,direction,attributes)
640-- ]],
641--
642-- nohead = [[
643--     %action%(tonode(nuthead),groupcode,size,packtype,direction,attributes)
644-- ]],
645--
646-- nonut = [[
647--     %action%(nuthead,groupcode,size,packtype,direction,attributes)
648-- ]],
649--
650--     }
651-- }
652
653tasks.new {
654    name      = "finalizers",
655    processor = nodeprocessor,
656    sequence  = {
657        "before",      -- for users
658        "normalizers",
659        "fonts",
660        "lists",
661        "after",       -- for users
662    },
663    templates = {
664
665default = [[
666return function(head)
667    return head
668end
669]],
670
671process = [[
672local tonut  = nodes.tonut
673local tonode = nodes.nuts.tonode
674
675%localize%
676
677return function(head)
678    local nuthead = tonut(head)
679
680%actions%
681    return tonode(nuthead)
682end
683]],
684
685step = [[
686    nuthead = tonut((%action%(tonode(nuthead))))
687]],
688
689nut  = [[
690    nuthead = %action%(nuthead)
691]],
692
693nohead = [[
694    %action%(tonode(nuthead))
695]],
696
697nonut = [[
698    %action%(nuthead)
699]],
700
701    }
702}
703
704tasks.new {
705    name      = "mvlbuilders",
706    processor = nodeprocessor,
707    sequence  = {
708        "before",      -- for users
709        "normalizers",
710        "after",       -- for users
711    },
712    templates = {
713
714default = [[
715return function(head)
716    return head
717end
718]],
719
720-- process = [[
721-- local tonut  = nodes.tonut
722-- local tonode = nodes.nuts.tonode
723--
724-- %localize%
725--
726-- return function(head,groupcode)
727--     local nuthead = tonut(head)
728--
729-- return function(nuthead,groupcode)
730--
731-- %actions%
732--     return tonode(nuthead)
733-- end
734-- ]],
735
736process = [[
737local tonut  = nodes.tonut
738local tonode = nodes.nuts.tonode
739
740%localize%
741
742return function(nuthead,groupcode)
743
744%actions%
745    return nuthead
746end
747]],
748
749step = [[
750    nuthead = tonut((%action%(tonode(nuthead),groupcode)))
751]],
752
753nut  = [[
754    nuthead = %action%(nuthead,groupcode)
755]],
756
757nohead = [[
758    %action%(tonode(nuthead),groupcode)
759]],
760
761nonut = [[
762    %action%(nuthead,groupcode)
763]],
764
765    }
766
767}
768
769tasks.new {
770    name      = "vboxbuilders",
771    processor = nodeprocessor,
772    sequence  = {
773        "before",      -- for users
774        "normalizers",
775        "after",       -- for users
776    },
777    templates = {
778
779default = [[
780return function(head)
781    return head
782end
783]],
784
785process = [[
786local tonut  = nodes.tonut
787local tonode = nodes.nuts.tonode
788
789%localize%
790
791return function(head,groupcode,size,packtype,maxdepth,direction)
792    local nuthead = tonut(head)
793
794%actions%
795    return tonode(nuthead)
796end
797]],
798
799step = [[
800    nuthead = tonut((%action%(tonode(nuthead),groupcode,size,packtype,maxdepth,direction)))
801]],
802
803nut  = [[
804    nuthead = %action%(nuthead,groupcode,size,packtype,maxdepth,direction)
805]],
806
807nohead = [[
808    %action%(tonode(nuthead),groupcode,size,packtype,maxdepth,direction)
809]],
810
811nonut = [[
812    %action%(nuthead,groupcode,size,packtype,maxdepth,direction)
813]],
814
815    }
816
817}
818
819tasks.new {
820    name      = "vboxhandlers",
821    processor = nodeprocessor,
822    sequence  = {
823        "before",      -- for users
824        "normalizers",
825        "after",       -- for users
826    },
827    templates = {
828
829default = [[
830return function(head)
831    return head
832end
833]],
834
835process = [[
836local tonut  = nodes.tonut
837local tonode = nodes.nuts.tonode
838
839%localize%
840
841return function(head,groupcode)
842    local nuthead = tonut(head)
843
844%actions%
845    return tonode(nuthead)
846end
847]],
848
849step = [[
850    nuthead = tonut((%action%(tonode(nuthead),groupcode)))
851]],
852
853nut  = [[
854    nuthead = %action%(nuthead,groupcode)
855]],
856
857nohead = [[
858    %action%(tonode(nuthead),groupcode)
859]],
860
861nonut = [[
862    %action%(nuthead,groupcode)
863]],
864
865    }
866
867}
868
869-- these operate on the content on a line, so no injections
870
871tasks.new {
872    name      = "contributers",
873    processor = nodeprocessor,
874    sequence  = {
875        "before",      -- for users
876        "normalizers",
877        "after",       -- for users
878    },
879    templates = {
880
881default = [[
882return function(head)
883    return head
884end
885]],
886
887process = [[
888local tonut  = nodes.tonut
889local tonode = nodes.nuts.tonode
890
891%localize%
892
893-- we operate exclusively on nuts (no index yet)
894
895return function(head,where,tail)
896    local nuthead = tonut(head)
897    local nuttail = tonut(tail)
898
899%actions%
900    return tonode(nuthead)
901end
902]],
903
904step = [[
905    nuthead = tonut((%action%(tonode(nuthead),where,tonode(nuttail))))
906]],
907
908nut  = [[
909    nuthead = %action%(nuthead,where,nuttail)
910]],
911
912nohead = [[
913    %action%(tonode(nuthead),where,tonode(nuttail))
914]],
915
916nonut = [[
917    %action%(nuthead,where,nuttail)
918]],
919
920    }
921
922}
923
924    tasks.new {
925        name      = "adjusters",
926        processor = nodeprocessor,
927        sequence  = {
928            "before",      -- for users
929            "normalizers",
930            "after",       -- for users
931        },
932        templates = {
933
934default = [[
935return function(head)
936    return head
937end
938]],
939
940process = [[
941local tonut    = nodes.tonut
942local tonode   = nodes.nuts.tonode
943local nodetail = nodes.nuts.tail
944
945%localize%
946
947-- we operate exclusively on nuts
948
949return function(head,where,tail,index)
950    local nuthead = tonut(head)
951    local nuttail = tonut(tail)
952
953%actions%
954    return tonode(nuthead)
955end
956]],
957
958step = [[
959    nuthead = tonut((%action%(tonode(nuthead),where,tonode(nuttail),index)))
960    nuttail = nodetail(nuthead)
961]],
962
963nut  = [[
964    nuthead = %action%(nuthead,where,nuttail,index)
965    nuttail = nodetail(nuthead)
966]],
967
968nohead = [[
969    %action%(tonode(nuthead),where,tonode(nuttail),index)
970    nuttail = nodetail(nuthead)
971]],
972
973nonut = [[
974    %action%(nuthead,where,nuttail,index)
975    nuttail = nodetail(nuthead)
976]],
977
978    }
979
980}
981
982-- -- math -- --
983
984tasks.new {
985    name      = "math",
986    processor = nodeprocessor,
987    sequence  = {
988        "before",
989        "normalizers",
990        "builders",
991        "finalizers",
992        "after",
993    },
994    templates = {
995
996default = [[
997return function(head)
998    return head
999end
1000]],
1001
1002process = [[
1003local tonut  = nodes.tonut
1004local tonode = nodes.nuts.tonode
1005
1006%localize%
1007
1008return function(head,style,penalties,beginclass,endclass,level,style)
1009    local nuthead = tonut(head)
1010
1011%actions%
1012    return tonode(nuthead)
1013end
1014]],
1015
1016step = [[
1017    nuthead = tonut((%action%(tonode(nuthead),style,penalties,beginclass,endclass,level,style)))
1018]],
1019
1020nut  = [[
1021    nuthead = %action%(nuthead,style,penalties,beginclass,endclass,level,style)
1022]],
1023
1024nohead = [[
1025    %action%(tonode(nuthead),style,penalties,beginclass,endclass,level,style)
1026]],
1027
1028nonut = [[
1029    %action%(nuthead,style,penalties,beginclass,endclass,level,style)
1030]],
1031
1032    }
1033}
1034
1035-- tasks.new {
1036--     name      = "parbuilders",
1037--     arguments = 1,
1038--     processor = nodeprocessor,
1039--     sequence  = {
1040--         "before",      -- for users
1041--         "lists",
1042--         "after",       -- for users
1043--     }
1044-- }
1045
1046-- tasks.new {
1047--     name      = "pagebuilders",
1048--     arguments = 5,
1049--     processor = nodeprocessor,
1050--     sequence  = {
1051--         "before",      -- for users
1052--         "lists",
1053--         "after",       -- for users
1054--     }
1055-- }
1056
1057tasks.new {
1058    name      = "pagebuilders",
1059    processor = nodeprocessor,
1060    sequence  = {
1061        "before",      -- for users
1062        "normalizers",
1063        "after",       -- for users
1064    },
1065    templates = {
1066
1067default = [[
1068return function(head)
1069    return head
1070end
1071]],
1072
1073process = [[
1074local tonut  = nodes.tonut
1075local tonode = nodes.nuts.tonode
1076
1077%localize%
1078
1079return function(head,groupcode,size,packtype,maxdepth,direction)
1080    local nuthead = tonut(head)
1081
1082%actions%
1083    return tonode(nuthead)
1084end
1085]],
1086
1087step = [[
1088    nuthead = tonut((%action%(tonode(nuthead),groupcode,size,packtype,maxdepth,direction)))
1089]],
1090
1091nut  = [[
1092    nuthead = %action%(nuthead,groupcode,size,packtype,maxdepth,direction)
1093]],
1094
1095nohead = [[
1096    %action%(tonode(nuthead),groupcode,size,packtype,maxdepth,direction)
1097]],
1098
1099nonut = [[
1100    %action%(nuthead,groupcode,size,packtype,maxdepth,direction)
1101]],
1102
1103    }
1104}
1105
1106-- for now quite useless (too fuzzy)
1107--
1108-- tasks.new {
1109--     name            = "listbuilders",
1110--     processor       = nodeprocessor,
1111--     sequence        = {
1112--         "before",      -- for users
1113--         "normalizers",
1114--         "after",       -- for users
1115--     },
1116--     templates       = {
1117-- -- we don't need a default
1118--         default = [[
1119-- return function(box,location,prevdepth)
1120--     return box, prevdepth
1121-- end
1122--         ]],
1123--         process = [[
1124-- %localize%
1125-- return function(box,location,prevdepth,mirrored)
1126--     %actions%
1127--     return box, prevdepth
1128-- end
1129--         ]],
1130--         step = [[
1131-- box, prevdepth = %action%(box,location,prevdepth,mirrored)
1132--         ]],
1133--     },
1134-- }
1135
1136-- -- math -- --
1137
1138-- not really a node processor
1139
1140-- tasks.new {
1141--     name      = "newpar",
1142--     processor = nodeprocessor,
1143--     sequence  = {
1144--         "before",
1145--         "normalizers",
1146--         "after",
1147--     },
1148--     templates = {
1149--
1150-- default = [[
1151-- return function(mode,indent)
1152--     return indent
1153-- end
1154-- ]],
1155--
1156-- process = [[
1157-- %localize%
1158--
1159-- return function(mode,indent)
1160--
1161-- %actions%
1162--     return indent
1163-- end
1164-- ]],
1165--
1166-- step = [[
1167--     indent = %action%(mode,indent)
1168-- ]],
1169--
1170--     }
1171-- }
1172
1173-- -- localboxes -- --
1174
1175tasks.new {
1176    name      = "localboxes",
1177    processor = nodeprocessor,
1178    sequence  = {
1179        "before",      -- for users
1180        "lists",
1181        "after",       -- for users
1182    },
1183    templates = {
1184
1185default = [[
1186return function(head)
1187end
1188]],
1189
1190process = [[
1191local tonut  = nodes.tonut
1192local tonode = nodes.nuts.tonode
1193
1194%localize%
1195
1196-- line,leftbox,rightbox,middlebox,linenumber,leftskip,rightskip,lefthang,righthang,indent,parinitleftskip,parinitrightskip,parfillleftskip,parfillrightskip,overshoot
1197
1198return function(line,leftbox,rightbox,middlebox,...)
1199    nutline      = tonut(line)
1200    nutleftbox   = leftbox  and tonut(leftbox)
1201    nutrightbox  = rightbox and tonut(rightbox)
1202    nutmiddlebox = middlebox and tonut(middlebox)
1203%actions%
1204end
1205]],
1206
1207step = [[
1208    tonut((%action%(line,leftbox,rightbox,middlebox,...)))
1209]],
1210
1211nut  = [[
1212    %action%(nutline,nutleftbox,nutrightbox,nutmiddlebox,...)
1213]],
1214
1215nohead = [[
1216    %action%(line,leftbox,rightbox,middlebox,...)
1217]],
1218
1219nonut = [[
1220    %action%(nutline,nutleftbox,nutrightbox,nutmiddlebox,...)
1221]],
1222
1223    }
1224}
1225
1226-- -- quality -- --
1227
1228tasks.new {
1229    name      = "hquality",
1230    processor = nodeprocessor,
1231    sequence  = {
1232        "before",      -- for users
1233        "system",
1234        "after",       -- for users
1235    },
1236    templates = {
1237
1238default = [[
1239return function(how,detail,nod,first,last,filename)
1240    -- nil
1241end
1242]],
1243
1244process = [[
1245local tonut  = nodes.tonut
1246local tonode = nodes.nuts.tonode
1247
1248%localize%
1249
1250return function(how,detail,nod,first,last,filename)
1251    local nut = tonut(nod)
1252    local rul = nil
1253
1254%actions%
1255
1256    return rul and tonode(rul)
1257end
1258]],
1259
1260step = [[
1261    rul = tonut((%action%(how,detail,nod,first,last,filename,rul and tonode(rul))))
1262]],
1263
1264nut  = [[
1265    rul = %action%(how,detail,nut,first,last,filename,rul)
1266]],
1267
1268nohead = [[
1269    %action%(how,detail,nod,first,last,filename,rul and tonode(rul))
1270]],
1271
1272nonut = [[
1273    %action%(how,detail,nut,first,last,filename,rul)
1274]],
1275
1276    }
1277}
1278
1279tasks.new {
1280    name      = "vquality",
1281    processor = nodeprocessor,
1282    sequence  = {
1283        "before",      -- for users
1284        "system",
1285        "after",       -- for users
1286    },
1287    templates = {
1288
1289default = [[
1290return function(how,detail,nod,first,last,filename)
1291    -- nil
1292end
1293]],
1294
1295process = [[
1296local tonut  = nodes.tonut
1297local tonode = nodes.nuts.tonode
1298
1299%localize%
1300
1301return function(how,detail,nod,first,last,filename)
1302    local nut = tonut(nod)
1303    local rul = nil
1304
1305%actions%
1306    return rul and tonode(rul)
1307end
1308]],
1309
1310step = [[
1311    rul = tonut((%action%(how,detail,nod,first,last,filename,tonode(rul))))
1312]],
1313
1314nut  = [[
1315    rul = %action%(how,detail,nut,first,last,filename,rul)
1316]],
1317
1318nohead = [[
1319    %action%(how,detail,nod,first,last,filename,rul and tonode(rul))
1320]],
1321
1322nonut = [[
1323    %action%(how,detail,nut,first,last,filename,rul)
1324]],
1325
1326    }
1327}
1328