Having defined the tangling and weaving processes earlier, the main loop for our literate programming tool is particularly simple. Essentially, it defines all the necessary components
and then repeats over all the files specified on the command-line, tangling and weaving each of them in turn:
group #implied process repeat over #args put #error "%nProcessing %"" || #args || "%" ...%n" using group "tangle" do sgml-parse document scan file #args output "%c" done using group "weave" do sgml-parse document scan file #args output "%c" done again <33 handling a cross-reference>
Note that the process rule is explicitly placed into the #implied group: the tangling process makes no promises on where things will end up in the tangled output. By explicitly putting the process rule in group #implied, we ensure that it doesn't get hidden inside a group that happens to appear before in the tangled output. The same reasoning applies to <33 handling a cross-reference>.
In Knuth's original tool, tangling and weaving were handled by separate programs. However, our tools are so brief that it hardly seems to be worth the trouble splitting them apart. Instead, one execution does both tangling and weaving of its input.
Previous section: Handling Cross-References
Next section: Generating Output Filenames