RoseTranslateImpl.Mesa
Spreitzer, October 22, 1985 1:25:41 pm PDT
Barth, September 10, 1985 8:26:25 pm PDT
DIRECTORY BasicTime, Commander, CommandTool, FS, IO, Rope, RoseBind, RoseBindPrivate, RoseTranslate, RoseTranslatePrivate;
RoseTranslateImpl: CEDAR PROGRAM
IMPORTS BasicTime, Commander, CommandTool, FS, IO, Rope, RoseBindPrivate, RoseTranslatePrivate
EXPORTS RoseBind, RoseTranslate
=
BEGIN
ROPE: TYPE = Rope.ROPE;
BehaviorClassRec: PUBLIC TYPE = RoseBindPrivate.BehaviorClassRec;
translatorTime: PUBLIC BasicTime.GMT ← BasicTime.Now[];
translatorVersion: PUBLIC ROPE ← GetFileLine["RoseTranslator.version"];
cmdBase: ROPE = "RoseTranslate";
installationDir: ROPE = CommandTool.CurrentWorkingDirectory[];
RoseTranslate: PROC [cmd: Commander.Handle] RETURNS [result: REF ANYNIL, msg: Rope.ROPENIL] --Commander.CommandProc-- = {
commandLineStream: IO.STREAMIO.RIS[cmd.commandLine];
FOR i: INT ← commandLineStream.SkipWhitespace[], commandLineStream.SkipWhitespace[] WHILE NOT commandLineStream.EndOf[] DO
moduleNameRoot: ROPE ← commandLineStream.GetTokenRope[IO.IDProc].token;
moduleRoot: RoseBindPrivate.ModuleRoot ← RoseBindPrivate.EnsureModuleRoot[moduleNameRoot];
IF moduleRoot = NIL THEN {
cmd.err.PutF["Module root %g not found!\n", [rope[moduleNameRoot]]];
RETURN [$Failure];
};
RoseTranslatePrivate.TranslateDefs[moduleRoot];
RoseTranslatePrivate.TranslatePrivates[moduleRoot];
ENDLOOP;
result ← result;
};
GetTranslateCommand: PUBLIC PROC [moduleNameRoot: ROPE] RETURNS [cmd: ROPE] = {
cmd ← Rope.Cat[installationDir, cmdBase, " ", moduleNameRoot];
};
DoMesaFormatting: PROC [tfor: TiogaFileOps.Ref] = {
tnr: TextNode.Ref;
TRUSTED {tnr ← LOOPHOLE[tfor]};
[] ← TEditMesaOps.SetSpanMesaLooks[
span: [[tnr, 0], TextNode.LastLocWithin[tnr]],
event: NIL
];
};
GetFileLine: PROC [fileName: ROPE] RETURNS [line: ROPE] = {
ENABLE FS.Error, IO.Error, IO.EndOfStream => {line ← "Error reading file"; CONTINUE};
from: IO.STREAMFS.StreamOpen[fileName];
[] ← from.SkipWhitespace[];
line ← from.GetLineRope[];
from.Close[];
};
Commander.Register[cmdBase, RoseTranslate, "Generates Rosemary definitions and implementation files"];
END.