megamek.common.util
Class AbstractCommandLineParser

java.lang.Object
  extended by megamek.common.util.AbstractCommandLineParser

public abstract class AbstractCommandLineParser
extends java.lang.Object

Very simple skeleton for the command line parser. Provides basic scanner primitives and token types. Descendants should implement at least start function


Nested Class Summary
static class AbstractCommandLineParser.ParseException
          Exception thrown in case of error
 
Field Summary
protected  java.lang.String OPTION_PREFIX
          Prefix of the option.
protected static int TOK_EOF
          End of input token
protected static int TOK_LITERAL
          Literal (any string that doesn not start with defice actually)
protected static int TOK_OPTION
          Option token
 
Constructor Summary
AbstractCommandLineParser(java.lang.String[] args)
          Constructs new parser
 
Method Summary
protected  void error(java.lang.String message)
          Indicates the parse error
protected  java.lang.String getArgValue()
          Returns current arg
protected  int getPosition()
          Returns String value of the current token
protected  int getToken()
          Returns current token
protected  java.lang.String getTokenValue()
          Returns String value of the current token
protected  void nextArg()
           
protected  void nextToken()
          Reads the next available token.
 void parse()
          Main entry point of the parser
protected  void setToken(int token)
          Sets the current token
protected  void setTokenValue(java.lang.String tokenValue)
          Sets the current token
protected abstract  void start()
          Real entry point of parser
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OPTION_PREFIX

protected java.lang.String OPTION_PREFIX
Prefix of the option. Subclasses may overwrite.


TOK_EOF

protected static final int TOK_EOF
End of input token

See Also:
Constant Field Values

TOK_OPTION

protected static final int TOK_OPTION
Option token

See Also:
Constant Field Values

TOK_LITERAL

protected static final int TOK_LITERAL
Literal (any string that doesn not start with defice actually)

See Also:
Constant Field Values
Constructor Detail

AbstractCommandLineParser

public AbstractCommandLineParser(java.lang.String[] args)
Constructs new parser

Parameters:
args - array of arguments to parse
Method Detail

parse

public void parse()
           throws AbstractCommandLineParser.ParseException
Main entry point of the parser

Throws:
AbstractCommandLineParser.ParseException

getArgValue

protected java.lang.String getArgValue()
Returns current arg

Returns:
current arg

getToken

protected int getToken()
Returns current token

Returns:
current token

setToken

protected void setToken(int token)
Sets the current token

Parameters:
token -

getTokenValue

protected java.lang.String getTokenValue()
Returns String value of the current token

Returns:

setTokenValue

protected void setTokenValue(java.lang.String tokenValue)
Sets the current token

Parameters:
tokenValue -

getPosition

protected int getPosition()
Returns String value of the current token

Returns:

start

protected abstract void start()
                       throws AbstractCommandLineParser.ParseException
Real entry point of parser

Throws:
AbstractCommandLineParser.ParseException

nextToken

protected void nextToken()
Reads the next available token.


nextArg

protected void nextArg()

error

protected void error(java.lang.String message)
              throws AbstractCommandLineParser.ParseException
Indicates the parse error

Parameters:
message -
Throws:
AbstractCommandLineParser.ParseException