15 Scripting LanguageThe scripting language of Ada-ASSURED is based on Scheme. The principle reference for Scheme is:
Scheme is a powerful general-purpose programming language derived from LISP. Although its syntax may be unfamiliar to you, it is easy to master. The real benefit of Scheme, however, is not its syntactic simplicity, but its semantic power.
The scripting language is actually a dialect of Scheme known as STk. The principle reference for STk is:
STk implements most of Scheme and has numerous extensions. The STk Reference Manual describes STk by explaining its differences from Scheme.
Although STk extends Scheme with the ability to manipulate windows implemented with the Tk widget set, Ada-ASSURED's scripting language, as of this release, is a dialect of STk known as SNOW, standing for ``Scheme with NO Windows''. Future releases of Ada-ASSURED are likely to support full STk.
GrammaTech has extended SNOW with features specific to Ada-ASSURED, which are described in this chapter. All references to Scheme in this chapter refer to the SNOW dialect of STk.
Scripting plays numerous roles in Ada-ASSURED:
Two environment variables control the search for script files:
.:$STK_LIBRARY/STk:$STK_LIBRARY/dir,where dir is the name of an automatically selected platform-specific directory.
Scripts can be invoked in several ways:
The best way to load a script each time the editor is invoked is to add it to file $AAHOME/scripts/aa.user.stk.
Script execution is synchronous and blocks interaction until the script either terminates or requests interactive input. Scripts terminate either (i) normally, (ii) with an error, or (iii) by asynchronous interruption.
Scripts may request input from the user in three ways: (i) from the *transcript* buffer, (ii) from a dialog box, and (iii) from an *input* buffer.
The *transcript* buffer implements a ``glass teletype interface'' to the script interpreter: if no script is being executed when RETURN is struck in *transcript*, the line is passed to the script interpreter for execution. If a script is being executed when RETURN is struct in *transcript*, the entire line on which the insertion cursor is positioned is sent to the script as input. If no input is available when a script does a read on standard input, the script pauses until the input becomes available. Input not fully consumed is buffered for later reads. While the script is paused for input, all windows of the editor are active.
Procedure sg:make-dialog creates a simple synchronous dialog box for entering string parameters. While the script is paused for input, all windows of the editor are active.
Procedure sg:input creates an *input* buffer initialized with an editable term value. The modified value in the buffer is returned when command terminate-input is invoked. While the script is paused for input, all windows of the editor are active.
Warning: scripts that request input must be written with care because user interaction when the script is paused for input can change the editor's state.
Script output is directed to the *transcript* buffer. Most, but not all, messages sent to standard error are also directed to *transcript*. There are a few exceptions that are directed to the standard error stream of the Ada-ASSURED process, so some messages may appear in the shell window from which the editor was invoked.
When a script is invoked using eval-string, eval-selection, eval-buffer, or if the script was invoked by striking RETURN in *transcript*, then the result of evaluating a script is written to *transcript*.
After a script has been running for a short while, an interruption dialog box is popped up. This gives the user a chance to interrupt a runaway script. Clicking on the Interrupt button causes the script to be interrupted asynchronously. The interrupt dialog box is popped down if a running script pauses for input; it pops up again when the script resumes execution.
In a few rare cases, execution of a script cannot be interrupted using the interruption dialog box. For example, this can occur when the entire Ada-ASSURED process blocks because the script is waiting on an external event such as termination of an active process, or a blocking read from a file descriptor. In such cases, the script can be interrupted by sending the editor process an interrupt. This can be done by typing ^C in the window from which Ada-ASSURED was invoked, or by finding the process id of the editor process and
| X | issuing the command (from UNIX) kill -2 pid. |
| MS | killing the process using the Task Manager. |
The following Scheme variables control the interrupt dialog box:
| sg:interrupt-waittime1 | variable |
| This is an integer value that specifies the number of microseconds to wait before popping up the interrupt dialog box for the first time. The default value specifies that it will appear after one second. | |
| sg:interrupt-waittime2 | variable |
| This is an integer value that specifies how often to check the interrupt dialog box to see whether the interrupt button has been pressed. The default value specifies 200 milliseconds. | |
Termination on Error
A runtime error terminates a script. For example, a script terminates
if a procedure is called with the wrong number of arguments or
arguments of the wrong type. An appropriate error message and stack
trace is directed to *transcript*, after which control returns
to the editor.
Batch mode is initiated by invoking Ada-ASSURED with the -b flag. In batch mode, Ada-ASSURED is controlled wholly by scripts and there is no user interaction. Other differences are:
Argument names are italicized in the sample calls given below for procedures. Thus the line
obj any object list, list1, ... listj, ... list x, x1, ... xj, ... real number k, k1, ... kj, ... exact integer
The simplest scripts just perform sequences of editing operations by invoking procedures that correspond to editing commands.
The procedure for command c is named sg:c. For example, Scheme procedure sg:exit performs the same operation as command exit. Each such procedure returns #t if the command is successful, and #f otherwise. Some commands also set a global status code that can be interrogated to determine additional information about the command's execution. See Section Status.
Most commands have no parameters; the corresponding Scheme procedures also have no parameters. Commands with parameters, i.e., those that pop up dialog boxes, correspond to Scheme procedures with parameters. These are listed below with descriptions of their arguments. See Section Using Ada-ASSURED for full descriptions of the commands.
where string1 and string2 are window names; and string3 is either "Isolate" or "Merge".
where string is a path.
where string is the name of the view; and boolean is #t if a new window is to be created and #f otherwise.
where string is the name of a buffer.
| X | Called sg:delete-buffer. |
where string is a syntactic category.
where string is the entire text of a UNIX [X] or MSDOS [MS] shell command.
where string is a buffer name. Returns the current working directory associated with string. The current buffer is used if the function is called with no arguments.
where string is the name of a buffer.
| MS | Called sg:close-buffer. |
where string is the search string.
where string is the pathname of a file containing Scheme code.
where string is the text of a Scheme expression.
where string is the name of an Ada-ASSURED command.
where string1 is the search string; string2 is the replace string; boolean1 is #t for forward search and #f for backward search; string3 is "Search", "Replace", or "Replace All"; and boolean2 is #t is case is to be respected and #f otherwise.
| X | Called sg:search. |
where string is the name to look for; boolean1 through boolean8 encode the sort (procedure, function, type, exception, task, entry, package, and protected); boolean9 through boolean12 encode the kind (specification, definition, generic, and stub); and boolean13 through boolean15 encode the context employed (with, use, and renames).
where k is a line number in the widget.
where k is an external line number in the file.
where string is text to append to a UNIX grep shell command.
| MS | Not supported. |
where string is the file pathname.
where string is the file pathname.
where string is the tags file pathname; and boolean is #t to merge new names and #f otherwise.
where string1 is the name of the new buffer; string2 is the syntactic category (phylum); and string3 is "Yes", "No", or "Replace All".
where string is the name of the syntactic category (phylum) to be used for reading the file.
where string1 is the file pathname; string2 is the syntactic category (phylum); and string3 is "Yes", "No", or "Replace All".
where string1 is the buffer name; k1 is the number of copies; boolean1 is #t if the entire buffer is to be printed and #f if only the structural selection is to be printed; boolean2 is #t if the entire document is to be printed and #f if only a restricted number of pages are to be printed; k2 is the first page to print; k3 is the last page to print; string2 is the view.
where string1 is the file pathname; string2 is the syntactic category (phylum); k1 is the number of copies; boolean1 is #t if the entire document is to be printed and #f if only a restricted number of pages are to be printed; k2 is the first page to print; k3 is the last page to print; string3 is the view.
where boolean1 is #t for color and #f for black-and-white; boolean2 is #t for landscape mode and #f for portrait mode; boolean3 is #t for 2 columns and #f for 1 column; x1 is the scale factor; string1 is the header control string; string2 is the footer control string; string3 is the position of line numbers: "On Left", "On Right", or "None"; k is the interval between consecutive line numbers; x2 is the paper width; x3 is the paper height; x4 is the top margin; x5 is the left margin; x6 is the bottom margin; x7 is the right margin; boolean4 is #t to use the absolute right margin and #f otherwise; boolean5 is #t to send output to the printer and #f to send it to a file; string4 is the file pathname; string5 is the prologue pathname; string6 is the font metric location; and string7 is the print command.
| MS | The parameters boolean1, boolean2, boolean3, x1, string3, k, x2, x3, boolean5, string4, string5, string6, and string7 are ignored. |
where string1 is "Text", "Structure", or "Attributed"; string2 is the file pathname; and string3 is the view.
where string1 is the name of an attribute, and string2 is the file pathname.
where string1 is "Text", "Structure", or "Attributed"; string2 is the file pathname; and string3 is the view.
where string1 is the search string; string2 is the replace string; boolean1 is #t for forward search and #f for backward search; string3 is "Search", "Replace", or "Replace All"; and boolean2 is #t is case is to be respected and #f otherwise.
| MS | Called sg:find. |
where boolean1 is #t for word wrapping; boolean2 is #t to list commands on command error; boolean3 is #t for auto-placement of new windows; k1 is the number of indentation spaces; k2 is the column number of the absolute right margin; k3 is the space between consecutive tab stops; boolean4 is #t to get a new window on change-view; string1 controls new windows on new, switch-to-buffer, and open: "Yes", "No", or "Replace All"; string2 controls the default file format: "Text", "Structure", or "Attributed"; string3 is the default file view; boolean5 is #t to respect elision on save; boolean6 is #t to enable auto-saving; k4 is the auto-save interval; boolean7 is #t to enable backup files; boolean8 is #t to respect case on search by default; and boolean9 is #t to maintain external line numbers.
| MS | The parameters boolean3 and string1, are ignored. |
where string is the text of a UNIX [X] or MSDOS [MS] shell command line.
where string is the buffer name.
| X | Not supported. |
where string1 is the search string; string2 is the syntactic category (phylum); string3 is the replace string; boolean1 is #t for forward search and #f for backward search; string3 is "Search", "Replace", or "Replace All"; and boolean2 is #t if case is to be respected and #f otherwise.
| X | Called sg:structural-search |
where string1 is the search string; string2 is the syntactic category (phylum); string3 is the replace string; boolean1 is #t for forward search and #f for backward search; string3 is "Search", "Replace", or "Replace All"; and boolean2 is #t if case is to be respected and #f otherwise.
| MS | Called sg:structural-find. |
where string1 is the buffer name; and string2 is "Yes", "No", or "Replace All".
| MS | Not supported. |