groovy.ui
Class InteractiveShell

java.lang.Object
  extended bygroovy.ui.InteractiveShell

public class InteractiveShell
extends java.lang.Object

A simple interactive shell for evaluating groovy expressions on the command line

Version:
$Revision: 1.19 $
Author:
James Strachan, Chris Poirier, Yuri Schimke, Brian McCallistair, Guillaume Laforge

Field Summary
private  java.lang.StringBuffer accepted
           
private static java.util.Map COMMAND_HELP
           
private static int COMMAND_ID_BINDING
           
private static int COMMAND_ID_DISCARD
           
private static int COMMAND_ID_DISPLAY
           
private static int COMMAND_ID_EXECUTE
           
private static int COMMAND_ID_EXIT
           
private static int COMMAND_ID_EXPLAIN
           
private static int COMMAND_ID_HELP
           
private static java.util.Map COMMAND_MAPPINGS
           
private static java.lang.String[] COMMANDS
           
private  java.io.PrintStream err
           
private  java.lang.Exception error
           
private  java.io.InputStream in
           
private static int LAST_COMMAND_ID
           
private  int line
           
private  java.io.PrintStream out
           
private  SourceUnit parser
           
private  java.lang.String pending
           
private  Prompt prompt
           
private  GroovyShell shell
           
private  boolean stale
           
private  TokenStream stream
           
private  CSTNode tree
           
 
Constructor Summary
InteractiveShell()
          Default constructor.
InteractiveShell(Binding binding, java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
           
InteractiveShell(java.io.InputStream in, java.io.PrintStream out, java.io.PrintStream err)
           
 
Method Summary
private  void accept()
          Accepts the pending text into the statement.
private  java.lang.String accepted(boolean complete)
          Returns the accepted statement as a string.
protected  void close()
           
private  java.lang.String current()
          Returns the current statement, including pending text.
private  void displayBinding()
          Displays the current binding used when instanciating the shell.
private  void displayHelp()
          Displays help text about available commands.
private  void displayStatement()
          Displays the accepted statement.
private  void explainStatement()
          Attempts to parse the accepted statement and display the parse tree for it.
private  void freshen()
          Clears accepted if stale.
static void main(java.lang.String[] args)
          Entry point when called directly.
private  boolean parse(java.lang.String code, int tolerance)
          Attempts to parse the specified code with the specified tolerance.
protected  java.lang.String read()
          Reads a single statement from the command line.
private  void report()
          Reports the last parsing error to the user.
protected  void reset()
          Resets the command-line processing machinery after use.
 void run(java.lang.String[] args)
          Reads commands and statements from input stream and processes them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

shell

private final GroovyShell shell

prompt

private final Prompt prompt

in

private final java.io.InputStream in

out

private final java.io.PrintStream out

err

private final java.io.PrintStream err

accepted

private java.lang.StringBuffer accepted

pending

private java.lang.String pending

line

private int line

stale

private boolean stale

parser

private SourceUnit parser

stream

private TokenStream stream

error

private java.lang.Exception error

tree

private CSTNode tree

COMMAND_ID_EXIT

private static final int COMMAND_ID_EXIT
See Also:
Constant Field Values

COMMAND_ID_HELP

private static final int COMMAND_ID_HELP
See Also:
Constant Field Values

COMMAND_ID_DISCARD

private static final int COMMAND_ID_DISCARD
See Also:
Constant Field Values

COMMAND_ID_DISPLAY

private static final int COMMAND_ID_DISPLAY
See Also:
Constant Field Values

COMMAND_ID_EXPLAIN

private static final int COMMAND_ID_EXPLAIN
See Also:
Constant Field Values

COMMAND_ID_EXECUTE

private static final int COMMAND_ID_EXECUTE
See Also:
Constant Field Values

COMMAND_ID_BINDING

private static final int COMMAND_ID_BINDING
See Also:
Constant Field Values

LAST_COMMAND_ID

private static final int LAST_COMMAND_ID
See Also:
Constant Field Values

COMMANDS

private static final java.lang.String[] COMMANDS

COMMAND_MAPPINGS

private static final java.util.Map COMMAND_MAPPINGS

COMMAND_HELP

private static final java.util.Map COMMAND_HELP
Constructor Detail

InteractiveShell

public InteractiveShell()
Default constructor.


InteractiveShell

public InteractiveShell(java.io.InputStream in,
                        java.io.PrintStream out,
                        java.io.PrintStream err)

InteractiveShell

public InteractiveShell(Binding binding,
                        java.io.InputStream in,
                        java.io.PrintStream out,
                        java.io.PrintStream err)
Method Detail

main

public static void main(java.lang.String[] args)
Entry point when called directly.


run

public void run(java.lang.String[] args)
         throws java.lang.Exception
Reads commands and statements from input stream and processes them.

Throws:
java.lang.Exception

close

protected void close()

reset

protected void reset()
Resets the command-line processing machinery after use.


read

protected java.lang.String read()
Reads a single statement from the command line. Also identifies and processes command shell commands. Returns the command text on success, or null when command processing is complete.

NOTE: Changed, for now, to read until 'execute' is issued. At 'execute', the statement must be complete.


accepted

private java.lang.String accepted(boolean complete)
Returns the accepted statement as a string. If not complete, returns the empty string.


current

private java.lang.String current()
Returns the current statement, including pending text.


accept

private void accept()
Accepts the pending text into the statement.


freshen

private void freshen()
Clears accepted if stale.


parse

private boolean parse(java.lang.String code,
                      int tolerance)
Attempts to parse the specified code with the specified tolerance. Updates the parser and error members appropriately. Returns true if the text parsed, false otherwise. The attempts to identify and suppress errors resulting from the unfinished source text.


report

private void report()
Reports the last parsing error to the user.


displayHelp

private void displayHelp()
Displays help text about available commands.


displayStatement

private void displayStatement()
Displays the accepted statement.


displayBinding

private void displayBinding()
Displays the current binding used when instanciating the shell.


explainStatement

private void explainStatement()
Attempts to parse the accepted statement and display the parse tree for it.



Copyright © 2003-2005 The Codehaus. All Rights Reserved.