|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectoscript.Shell
An extensible read-eval-print shell implementation. Splits the basic process of read, eval, print and handle errors into individual methods which can be overriden and extended as needed.
NOTE this could probably be split into an abstract base class which
does not implement read()
and print(oscript.data.Value)
, and hence has no
knowledge of input/output/error streams.
Constructor Summary | |
Shell(java.io.BufferedReader in,
java.io.PrintWriter out)
Class Constructor. |
|
Shell(java.io.BufferedReader in,
java.io.PrintWriter out,
java.io.PrintWriter err)
Class Constructor. |
|
Shell(java.lang.String prompt,
java.io.BufferedReader in,
java.io.PrintWriter out,
java.io.PrintWriter err)
Class Constructor. |
Method Summary | |
void |
evalAndPrint(java.lang.String line)
Evaluate and print a line. |
Value |
evalStr(java.lang.String line)
Evaluate a string... |
void |
handleParseException(ParseException e)
Called to handle syntax exceptions. |
void |
handleScriptException(PackagedScriptObjectException e)
Called to handle script exceptions. |
void |
print(Value val)
Print the result. |
void |
prompt()
Print the prompt shown to the user to indicate that we are ready for more input. |
java.lang.String |
read()
Read a line of input. |
void |
run()
The entry point for the read-eval-print loop. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public Shell(java.io.BufferedReader in, java.io.PrintWriter out)
in
- inputout
- outputpublic Shell(java.io.BufferedReader in, java.io.PrintWriter out, java.io.PrintWriter err)
in
- inputout
- outputerr
- error outputpublic Shell(java.lang.String prompt, java.io.BufferedReader in, java.io.PrintWriter out, java.io.PrintWriter err)
prompt
- the prompt to display before the readin
- inputout
- outputerr
- error outputMethod Detail |
public void run() throws java.io.IOException
prompt()
, read()
, and evalAndPrint(java.lang.String)
, which can
each be overridden as needed.
java.io.IOException
public void evalAndPrint(java.lang.String line)
evalStr(java.lang.String)
,
print(oscript.data.Value)
, handleScriptException(oscript.exceptions.PackagedScriptObjectException)
, and
handleParseException(oscript.parser.ParseException)
, which can be overriden as needed.
line
- the line of scriptpublic void prompt()
public java.lang.String read() throws java.io.IOException
\
) by stripping out the backslash and reading the
next line, until there is a line not terminated by a backslash. Also,
as a convenience, this method appends a semicolon to the end of the
input, if needed.
java.io.IOException
public Value evalStr(java.lang.String line) throws ParseException, PackagedScriptObjectException
line
- the script to evaluate
ParseException
PackagedScriptObjectException
public void print(Value val)
val
- the result to printpublic void handleScriptException(PackagedScriptObjectException e)
e
- the exceptionpublic void handleParseException(ParseException e)
e
- the exception
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |