gov.sandia.ccaffeine.cmd
Class CmdParse

java.lang.Object
  extended by gov.sandia.ccaffeine.cmd.CmdParse

public class CmdParse
extends java.lang.Object

The Cmd classes implement a simple Vector driven parser for command line applications. by Ben Allan, Sandia National Laboratories, May 1999. This code is based on the ASCEND IV command-line interpreter by Tom Epperly. It should be released to the public domain (or preferably the GNU License domain) as soon as possible. CmdContext is an abstract class for application specific data that will be defined in more detail by the application programmer. CmdAction is an interface class used in defining individual command objects. An interpreter is a collection of such objects sharing a common assumption about the subclass of CmdContext they are called in. CmdParse defines the interpreter which provides argument marshaling and checking services, supports command abbreviations, and provides help functionality. The overall scheme is that the application defines a bunch of CmdAction objects and hands them to the interpreter. This is not a highly intelligent scheme. It does keep a "hand-coded" interactive command-line manageable as each major command gets a separate class and implementation, and the control loop logic is abstracted. Unlike lex/yacc, it scales easily to multiple developers.


Constructor Summary
CmdParse(CmdContext icc)
          Actions in the constructed parser will be called with icc as their context.
 
Method Summary
 void addAction(CmdAction c)
          Adds a command to the parser.
 CmdAction getAction(java.lang.String s)
          Returns the nearest match (by leading characters) of commands stored in the list.
 void parse(BuilderClientMonitor monitor)
          Main command-line processing loop.
 void parse(java.lang.String read)
          Parse one line of text.
 void setContextVerbose(boolean noisyHelp)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CmdParse

public CmdParse(CmdContext icc)
Actions in the constructed parser will be called with icc as their context.

Method Detail

addAction

public void addAction(CmdAction c)
Adds a command to the parser. Presently does not check the sanity of the command. This function needs to do some insertion with checking for duplicates if we're paranoid. As it is, this comes out in the wash at getAction. Duplication will make commands useless.


getAction

public CmdAction getAction(java.lang.String s)
Returns the nearest match (by leading characters) of commands stored in the list.


setContextVerbose

public void setContextVerbose(boolean noisyHelp)

parse

public void parse(BuilderClientMonitor monitor)
           throws java.io.IOException
Main command-line processing loop. Throws an IOException if app. readLine fails. Returns if the exit command throws an EOFException.

Throws:
java.io.IOException

parse

public void parse(java.lang.String read)
           throws EndOfFileException,
                  java.io.IOException
Parse one line of text.

Parameters:
read - one line of text that is to be parsed.
Throws:
EndOfFileException - Thrown when we enounter the end-of-file.
java.io.IOException - Thrown if an io error occurs.