TTTranslateImpl.mesa
Translates from Tioga tree representation to TEX source code.
Michael Plass, December 13, 1982 3:17 pm
DIRECTORY
Ascii, IO, LooksReader, NameSymbolTable, NodeProps, NodeStyle, Rope, RopeReader, TextLooks, TextNode, TTOutput, TTTranslate;
TTTranslateImpl: PROGRAM
IMPORTS IO, LooksReader, NameSymbolTable, NodeProps, NodeStyle, Rope, RopeReader, TextNode, TTOutput
EXPORTS TTTranslate =
BEGIN
ToTeX: PUBLIC PROCEDURE [textNode: TextNode.Ref, output: TTOutput.Ref] =
BEGIN
children: INT ← textNode.CountChildren[];
THROUGH [0..children) DO
textNode ← textNode.StepForward[];
TextNodeToTeX[textNode, output];
ENDLOOP;
END;
lookName: ARRAY CHAR['a..'z] OF Rope.ROPE ← ["La", "Lb", "Lc", "Ld", "Le", "Lf", "Lg", "Lh", "Li", "Lj", "Lk", "Ll", "Lm", "Ln", "Lo", "Lp", "Lq", "Lr", "Ls", "Lt", "Lu", "Lv", "Lw", "Lx", "Ly", "Lz"];
TextNodeToTeX: PROCEDURE [textNode: TextNode.Ref, output: TTOutput.Ref] =
BEGIN
format: TextNode.TypeName ← textNode.NodeType[];
formatName: Rope.ROPE ← NameSymbolTable.RopeFromName[format];
ropeReader: RopeReader.Ref ← RopeReader.GetRopeReader[];
looksReader: LooksReader.Ref ← LooksReader.GetLooksReader[];
rope: Rope.ROPE ← textNode.NarrowToTextNode[].NodeRope[];
length: INT ← rope.Length[];
runs: TextLooks.Runs ← textNode.NarrowToTextNode[].NodeRuns[];
oldLooks: TextLooks.Looks ← TextLooks.noLooks;
output.EndLine[];
output.BeginGroup[];
IF formatName.Length[]>0 THEN output.ControlSeq[formatName]
ELSE output.ControlSeq["default"];
IF length>0 THEN {
ropeReader.SetPosition[rope, 0];
looksReader.SetPosition[runs, 0];
THROUGH [0..length) DO
looks: TextLooks.Looks ← looksReader.Get[];
char: CHAR ← ropeReader.Get[];
IF looks # oldLooks THEN {
output.ControlSeq["Look"];
FOR look: CHAR IN ['a..'z] DO
IF looks[look] THEN output.ControlSeq[lookName[look]];
ENDLOOP;
oldLooks ← looks;
};
SELECT char FROM
Ascii.CR => output.ControlSeq["NewLine"];
Ascii.SP, Ascii.TAB => output.Space[];
ENDCASE => output.stream.PutChar[char];
ENDLOOP;
output.ControlSeq["par"];
};
ToTeX[textNode, output];
output.EndGroup[];
ropeReader.FreeRopeReader[];
looksReader.FreeLooksReader[];
END;
END.
Michael Plass, December 9, 1982 8:42 am. Created.