<* 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;
ReturnTRUE
iffte
is valid. After the user makes a modification tosrc[te]
,te
is 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 makete
valid 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
. Requireserrast
andmsg
are either bothNIL
or both non-NIL
. Iftime # 0
and both are non-NIL
, then additionally highlight the unparsed text oferrast
using timestamptime
if it appears in one of the trees, and pop-up an error message box containingmsg
.
PROCEDURE AddTree(te: T; ast: JunoAST.T);
Appendast
to the end of the list of trees inte
, and append an unparsed version ofast
tote
's source. Ifast
is a procedure declaration for a procedure whose name hasCurrCmd
as a prefix, then pushast
onto 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 setnm
to the name of this procedure. If the body is of the formIF VAR ... IN ... END FI
, then the outerIF ... FI
is stripped off the result. Returns NIL if the stack is empty or if the editor is not valid. In this case, the value ofnm
is 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 a
JunoAST.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 editore
under the scopescp
. If the compilation was successful, setsmodName
to the name of the module (or toNIL
if there is noMODULE
header), setsentity
to a module entity whosepublic
andscp
scopes have parent scopescp
and that contain bindings for public and all declarations, respectively, and returnsTRUE
. Otherwise, displays an error to the user using event-timetime
and 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
e
or process the UI declarations ine
. SeeUnparse
andEditorUI.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
e
in the global code table. It also builds associations according to theUI
pragmas ine
.
PROCEDURE SaveSlots(wr: Wr.T);
Write towr
the indexes of any internalJunoRT
slots that are stored in the editor.
PROCEDURE RestoreSlots(rd: Rd.T);
Read fromwr
the indexs stored bySaveSlots
, and set the internal slots to the values read.
END Editor.