|
Class: ReadEvalPrintLoop
Object
|
+--ReadEvalPrintLoop
- Package:
- stx:libbasic
- Category:
- System-Support
- Version:
- rev:
1.170
date: 2023/12/08 13:10:06
- user: cg
- file: ReadEvalPrintLoop.st directory: libbasic
- module: stx stc-classLibrary: libbasic
A simple read-eval-print loop for non-GUI or stscript operation.
Invoked, for example if stx is started with a --repl argument,
or by the MiniDebugger with the 'I' command.
A line starting with '?' shows the usage message.
Lines starting with '#' are directives:
#exit - exit the rep-loop
#show ... - show various infos
#use package - show various infos
type '?' to see more.
The input can be in one of two formats:
1) traditional chunk format (bang-separated chunks, bangs duplicated)
this is the traditional fileIn format, as generated by fileOut from the browser
2) interactive line mode. Chunks are any number of lines up to either an empty line or
a line ending in a period. This is more useful for an interactive REPL, where statements/expressions
are entered linewise by a user.
The input can is switched to non-chunk format whenever a line with a '#' in the first column appears.
Try it (but only if you have a console):
Smalltalk readEvalPrintLoop
copyrightCOPYRIGHT (c) 2006 by eXept Software AG
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
accessing
-
answerPrompt
-
the string shown before the answer
-
answerPrompt: aString
-
set the string shown before the answer
-
compiler: something
-
assign a compiler to use;
can be used to change the language
-
confirmDebugger
-
true if the user is asked for a debugger in case of errors
-
confirmDebugger: aBoolean
-
true if the user is asked for a debugger in case of errors
-
debuggerUsed
-
by default, the miniDebugger is given control in case of an error;
you may want to write (subclass) your own ;-)
-
debuggerUsed: aDebuggerClass
-
by default, the miniDebugger is given control in case of an error;
you may want to write (subclass) your own ;-)
-
defaultPackagePrefix
-
a default to be prepended to #use packages
-
defaultPackagePrefix: aStringOrNil
-
a default to be prepended to #use packages
-
doChunkFormat
-
true if currently reading chunk format
-
doChunkFormat: aBoolean
-
enable/disable chunk format
-
editorCommand
-
the editor command to use with the #edit directive.
Uses the STX_EDITOR or EDITOR shell variables' value, if defined;
if not, the value in the classvar EDITORCOMMAND if non-nil;
otheriwse vi (notepad on windows)
-
errorStream
-
return the current error stream
-
errorStream: aStream
-
assign an error stream
-
input: aStream
-
assign an input stream
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
inputStream
-
get the current input stream
-
inputStream: aStream
-
assign an input stream
-
noDebugger
-
true if no debugger should be activated on errors (aborts)
-
noDebugger: aBoolean
-
true if no debugger should be activated on errors (aborts)
-
output: aStream
-
assign an output stream
** This is an obsolete interface - do not use it (it may vanish in future versions) **
-
outputStream
-
return the current output stream
-
outputStream: aStream
-
assign an output stream
-
printFlag
-
true if the return value of expressions should be printed
-
printFlag: aBoolean
-
true if the return value of expressions should be printed
-
prompt: aString
-
set the string shown as prompt
compiler interface-error handling
-
correctableError: message position: pos1 to: pos2 from: aCompiler
-
compiler notifies us of an error - ignore it
-
correctableSelectorWarning: aString position: relPos to: relEndPos from: aCompiler
-
compiler notifies us of a warning - ignore it
-
correctableWarning: message position: pos1 to: pos2 from: aCompiler
-
compiler notifies us of an error - ignore it
-
error: aString position: relPos to: relEndPos from: aCompiler
-
compiler notifies us of a warning - ignore it
-
unusedVariableWarning: aString position: relPos to: relEndPos from: aCompiler
-
compiler notifies us of a warning - ignore it
-
warning: aString position: relPos to: relEndPos from: aCompiler
-
compiler notifies us of a warning - ignore it
directives
-
askYesNo: message
-
-
cmd_apropos: lineStream
-
apropos directive; i.e.
#apropos collection [;more]
Usage example(s):
self basicNew
input:Stdin;
cmd_apropos:'Array' readStream
self basicNew
input:Stdin;
cmd_apropos:'at:' readStream
self basicNew
input:Stdin;
cmd_apropos:'*at:' readStream
|
-
cmd_break: lineStream
-
breakpoint directive; i.e.
#break <classname> ['class'] <selector>
-
cmd_clear: lineStream
-
-
cmd_debug: lineStream
-
-
cmd_delete: lineStream
-
breakpoint delete directive; i.e.
#delete <classname> ['class'] <selector>
#delete <classname>
#delete all
-
cmd_edit: lineStream
-
edit a class or selector in an external editor
Usage example(s):
Smalltalk readEvalPrintLoop
self new
input:Stdin;
cmd_edit:'MyClass foo' readStream
self new
input:Stdin;
cmd_edit:'Array class new:' readStream
|
-
cmd_exit: lineStream
-
exit directive - leaves the repl
-
cmd_help: lineStream
-
-
cmd_ide: lineStream
-
upen up the ide
-
cmd_language: lineStream
-
language directive; i.e.
#language smalltalk
#language javascript
-
cmd_list: lineStream
-
list directive; i.e.
#list <classname> ['class'] <selector>
Usage example(s):
(ReadEvalPrintLoop basicNew error:Stderr)
input:Stdin;
cmd_list:'Array' readStream
(ReadEvalPrintLoop basicNew error:Stderr)
input:Stdin;
cmd_list:'Array at:put:' readStream
(ReadEvalPrintLoop basicNew error:Stderr)
input:Stdin;
cmd_list:'ReadEvalPrintLoop doIt' readStream
|
-
cmd_qFix: lineStream
-
qFix:
fix for a bug in xQuartz, which locks up my screen completely
from time to time (happens when doing popup views).
It seems that iconifying all views helps (for whatever reason)
to get out of the deadlock which results from a race condition in
grabFocus/grabPointer
-
cmd_read: lineStream
-
read directive; i.e.
#read scriptFile
-
cmd_set: lineStream
-
-
cmd_setOrClear: lineStream to: aBoolean
-
set/clear one of my internal flags
-
cmd_show: lineStream
-
show directive:
show packages
show modules (= loaded packages)
show variables
etc.
Usage example(s):
(ReadEvalPrintLoop basicNew error:Stderr) cmd_show:'packages' readStream
|
-
cmd_usage: lineStream
-
-
cmd_use: lineStream
-
use directive; i.e.
#use stx:goodies/xml
#use exept:mqtt
#use goodies/regression
-
directive: line
-
skip the hash
Usage example(s):
stderr showCR:('Ignored in directive: ', ex description).
|
-
getClassNameAndSelectorFrom: lineStream specialWords: specialWords into: aBlock
-
a helper for list and edit; parses class and selector name.
if the argument is one of the specialWords, return it.
otherwise, returns true if class/selector are ok,
or false if nothing reasonable was entered
-
showBreakpoints
-
(ReadEvalPrintLoop basicNew error:Stderr) showBreakpoints
-
showModules
-
lists loaded packages
Usage example(s):
(ReadEvalPrintLoop basicNew error:Stderr) showModules
|
-
showPackages
-
lists all known packages
Usage example(s):
(ReadEvalPrintLoop basicNew error:Stderr) showPackages
(ReadEvalPrintLoop basicNew error:Stderr) showModules
|
-
showVariables
-
shows GLOBAL workspace variables
Usage example(s):
(ReadEvalPrintLoop basicNew error:Stderr) showVariables
|
evaluation
-
basicReadEvalPrintLoopWithInput: input output: output error: error compiler: compilerClass prompt: doPrompt print: doPrint
-
the core of the interpreter loop;
extracted and parametrized, so it can be called recursively for included scripts.
If chunkFormat is true, chunks are read.
Otherwise, lines up to an empty line (or EOF) or a line ending in '.' are read,
unless the line ends with '\'.
A '#' character appearing in the first column of the first line turns off chunkmode,
which allows for convenient shell scripts containing a #/bin/stx as the first line.
-
compileAndExexute: chunk with: compilerClass doPrompt: doPrompt doPrint: doPrint
-
abortAll is handled, but not asked for here!
-
readEvalPrintLoop
-
simple read-eval-print loop for non-graphical Minitalk.
If the chunkFormat-argument is true, chunks are read.
Otherwise, lines up to an empty line (or EOF) are read.
A '#' character appearing in the first column of the first line
switches to non-chunkMode.
Usage example(s):
(ReadEvalPrintLoop new
doChunkFormat:false;
prompt:'>') readEvalPrintLoop
|
Usage example(s):
Stdin atEnd
Stdin clearEOF
Smalltalk readEvalPrintLoop
(ReadEvalPrintLoop new prompt:'>') readEvalPrintLoop
|
queries
-
autoDefineVariables
-
when evaluating with --eval, auto define any variables
|