<* PRAGMA LL *>An
Editor.T is a TextPort.T containing a Juno source module together
with a cache of Juno parse trees. If te is a Juno editor, then src[te]
is the text contained in te and trees[te] is the cache of parse trees.
An editor te is {\it valid} iff trees[te] is the sequence of parse
trees of type JunoAST.Block resulting from successfully parsing
src[te].
INTERFACEEditor ; IMPORT JunoAST, JunoScope; IMPORT TextPort, VBT, Atom; IMPORT Wr, Rd; VAR (*CONST*) PointToolSym, TextToolSym, SetToolSym, ParamSym, TemplToolSym: Atom.T; TYPE T <: Public; Public = TextPort.T OBJECT METHODS init(src: TEXT; readOnly := FALSE): T; txtModified(); <* LL.sup = VBT.mu *> getToolType(nm: Atom.T; VAR (*OUT*) type: Atom.T): BOOLEAN; getMenu(nm: Atom.T): VBT.T END;
NEW(T, txtModified := P).init(src, readOnly) returns a valid T
containing initial source src such that P will be called whenever the
text is modified. The editor is read-only iff readOnly = TRUE.
The txtModified method is called whenever the text of the editor has been
modified since the last time the TextPort's modified bit was reset. The
default txtModified method is a no-op.
The call ed.getToolType(nm, type) sets type to PointToolSym,
TextToolSym, TemplToolSym, or SetToolSym and returns TRUE if nm
is contained in one of these user interface pragmas. Otherwise, it returns
FALSE.
The call ed.getMenu(nm) returns a menu of parameters associated with the
procedure named nm in the editor ed. The menu contains a menu tool for
each value associated with nm in a Param user-interface declaration.
TYPE
Forest <: ForestPublic;
ForestPublic = OBJECT
tree: JunoAST.Block;
next: Forest := NIL;
END;
PROCEDURE Trees(te: T): Forest;
Return trees[te]. PROCEDURE Valid(te: T): BOOLEAN;
ReturnTRUEiffteis valid. After the user makes a modification tosrc[te],teis invalid until the next successful call toParse.
PROCEDURE Parse(te: T; time: VBT.TimeStamp): BOOLEAN;
Ifsrc[te]is a syntactically correct Juno program, settrees[te]to maketevalid and returnTRUE. Otherwise, pretty-print and display an error to the user, and returnFALSE.
PROCEDURE Unparse(te: T; errast: JunoAST.T := NIL; msg: TEXT := NIL; time: VBT.TimeStamp := 0); <* LL.sup < te *>
Unparsetrees[te]tote. Requireserrastandmsgare either bothNILor both non-NIL. Iftime # 0and both are non-NIL, then additionally highlight the unparsed text oferrastusing timestamptimeif it appears in one of the trees, and pop-up an error message box containingmsg.
PROCEDURE AddTree(te: T; ast: JunoAST.T);
Appendastto the end of the list of trees inte, and append an unparsed version ofasttote's source. Ifastis a procedure declaration for a procedure whose name hasCurrCmdas a prefix, then pushastonto the editor's current command stack; if it is a UI declaration, then it must have the correct number of arguments, and any procedure it names must not currently be named in any other UI declaration inte.
PROCEDURE NextCmdNum(te: T): CARDINAL;
Return the number of the next available command on the current command stack.
PROCEDURE NextCmdName(te: T): Atom.T;
Return the name of the next available command on the current command stack.
PROCEDURE PopCurrCmd(te: T; VAR (*OUT*) nm: JunoAST.Id): JunoAST.Cmd; <* LL.sup <= VBT.mu *>
Return the body of the procedure on the top of the current command stack, and setnmto the name of this procedure. If the body is of the formIF VAR ... IN ... END FI, then the outerIF ... FIis stripped off the result. Returns NIL if the stack is empty or if the editor is not valid. In this case, the value ofnmis undefined.
PROCEDURE Width(tp: TextPort.T): CARDINAL;
Return the width in characters of tp. PROCEDURE ModuleName(te: T): Atom.T;
If the first non-comment block oftrees[te] is aJunoAST.Module, return the module name; otherwise, return NIL.
PROCEDURE Compile(
e: T;
time: VBT.TimeStamp;
scp: JunoScope.T;
VAR (*OUT*) modName: JunoAST.Id;
VAR (*OUT*) entity: JunoScope.Mod;
uniqueModName := TRUE): BOOLEAN;
<* LL.sup < e *>
Parses (if necessary) and compiles the contents of the editoreunder the scopescp. If the compilation was successful, setsmodNameto the name of the module (or toNILif there is noMODULEheader), setsentityto a module entity whosepublicandscpscopes have parent scopescpand that contain bindings for public and all declarations, respectively, and returnsTRUE. Otherwise, displays an error to the user using event-timetimeand returnsFALSE.If
uniqueModName = TRUE, then if a module name is specified, it must not appear inscp.This procedure does not pretty-print the contents of
eor process the UI declarations ine. SeeUnparseandEditorUI.CompileUI.If successful, this procedure also has a side-effect on the Juno machine: it stores compiled versions of the predicates, functions and procedures appearing in
ein the global code table. It also builds associations according to theUIpragmas ine.
PROCEDURE SaveSlots(wr: Wr.T);
Write towrthe indexes of any internalJunoRTslots that are stored in the editor.
PROCEDURE RestoreSlots(rd: Rd.T);
Read fromwrthe indexs stored bySaveSlots, and set the internal slots to the values read.
END Editor.