eXept Software AG Logo

Smalltalk/X Webserver

Documentation of class 'ReadEvalPrintLoop':

Home

Documentation
www.exept.de
Everywhere
for:
[back]

Class: ReadEvalPrintLoop


Inheritance:

   Object
   |
   +--ReadEvalPrintLoop

Package:
stx:libbasic
Category:
System-Support
Version:
rev: 1.157 date: 2019/05/04 16:30:33
user: cg
file: ReadEvalPrintLoop.st directory: libbasic
module: stx stc-classLibrary: libbasic
Author:
Claus Gittinger

Description:


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


Instance protocol:

accessing
o  answerPrompt
the string shown before the answer

o  answerPrompt: aString
set the string shown before the answer

o  compiler: something
assign a compiler to use;
can be used to change the language

o  confirmDebugger
true if the user is asked for a debugger in case of errors

o  confirmDebugger: aBoolean
true if the user is asked for a debugger in case of errors

o  debuggerUsed
by default, the miniDebugger is given control in case of an error;
you may want to write (subclass) your own ;-)

o  debuggerUsed: aDebuggerClass
by default, the miniDebugger is given control in case of an error;
you may want to write (subclass) your own ;-)

o  defaultPackagePrefix
a default to be prepended to #use packages

o  defaultPackagePrefix: aStringOrNil
a default to be prepended to #use packages

o  doChunkFormat
true if currently reading chunk format

o  doChunkFormat: aBoolean
enable/disable chunk format

o  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)

o  errorStream
return the current error stream

o  errorStream: aStream
assign an error stream

o  input: aStream
assign an input stream

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  inputStream
get the current input stream

o  inputStream: aStream
assign an input stream

o  noDebugger
true if no debugger should be activated on errors (aborts)

o  noDebugger: aBoolean
true if no debugger should be activated on errors (aborts)

o  output: aStream
assign an output stream

** This is an obsolete interface - do not use it (it may vanish in future versions) **

o  outputStream
return the current output stream

o  outputStream: aStream
assign an output stream

o  printFlag
true if the return value of expressions should be printed

o  printFlag: aBoolean
true if the return value of expressions should be printed

o  prompt: aString
set the string shown as prompt

compiler interface-error handling
o  correctableError: message position: pos1 to: pos2 from: aCompiler
compiler notifies us of an error - ignore it

o  correctableSelectorWarning: aString position: relPos to: relEndPos from: aCompiler
compiler notifies us of a warning - ignore it

o  correctableWarning: message position: pos1 to: pos2 from: aCompiler
compiler notifies us of an error - ignore it

o  error: aString position: relPos to: relEndPos from: aCompiler
compiler notifies us of a warning - ignore it

o  unusedVariableWarning: aString position: relPos to: relEndPos from: aCompiler
compiler notifies us of a warning - ignore it

o  warning: aString position: relPos to: relEndPos from: aCompiler
compiler notifies us of a warning - ignore it

directives
o  askYesNo: message

o  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

o  cmd_break: lineStream
breakpoint directive; i.e.
#break <classname> ['class'] <selector>

o  cmd_clear: lineStream

o  cmd_debug: lineStream

o  cmd_delete: lineStream
breakpoint delete directive; i.e.
#delete <classname> ['class'] <selector>
#delete <classname>
#delete all

o  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

o  cmd_exit: lineStream
exit directive - leaves the repl

o  cmd_help: lineStream

o  cmd_ide: lineStream
upen up the ide

o  cmd_language: lineStream
language directive; i.e.
#language smalltalk
#language javascript

o  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

o  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

o  cmd_read: lineStream
read directive; i.e.
#read scriptFile

o  cmd_set: lineStream

o  cmd_setOrClear: lineStream to: aBoolean
set/clear one of my internal flags

o  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

o  cmd_usage: lineStream

o  cmd_use: lineStream
use directive; i.e.
#use stx:goodies/xml
#use exept:mqtt
#use goodies/regression

o  directive: line
skip the hash

usage example(s):

stderr showCR:('Ignored in directive: ', ex description).

o  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

o  showBreakpoints
(ReadEvalPrintLoop basicNew error:Stderr) showBreakpoints

o  showModules
lists loaded packages

usage example(s):

     (ReadEvalPrintLoop basicNew error:Stderr) showModules

o  showPackages
lists all known packages

usage example(s):

     (ReadEvalPrintLoop basicNew error:Stderr) showPackages
     (ReadEvalPrintLoop basicNew error:Stderr) showModules

o  showVariables
(ReadEvalPrintLoop basicNew error:Stderr) showVariables

doit
o  doIt

evaluation
o  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.

o  compileAndExexute: chunk with: compilerClass doPrompt: doPrompt doPrint: doPrint
abortAll is handled, but not asked for here!

o  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
o  autoDefineVariables
when evaluating with --eval, auto define any variables



ST/X 7.2.0.0; WebServer 1.670 at bd0aa1f87cdd.unknown:8081; Thu, 18 Apr 2024 16:02:53 GMT