Package megamek.common.commandLine
Class AbstractCommandLineParser
java.lang.Object
megamek.common.commandLine.AbstractCommandLineParser
- Direct Known Subclasses:
ClientServerCommandLineParser,MegaMekCommandLineParser
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
Nested ClassesModifier and TypeClassDescriptionstatic classException thrown in case of error -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected StringPrefix of the option.protected static final intEnd of input tokenprotected static final intLiteral (any string that does not start with defice (sp?) actually)protected static final intOption token -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected Stringprotected intprotected intprotected Stringprotected booleanhasNext()abstract Stringhelp()protected voidnextArg()protected voidReads the next available token.voidparse()Main entry point of the parserprotected voidsetToken(int token) protected voidsetTokenValue(String tokenValue) protected abstract voidstart()Real entry point of parser
-
Field Details
-
OPTION_PREFIX
Prefix of the option. Subclasses may overwrite. -
TOK_EOF
protected static final int TOK_EOFEnd of input token- See Also:
-
TOK_OPTION
protected static final int TOK_OPTIONOption token- See Also:
-
TOK_LITERAL
protected static final int TOK_LITERALLiteral (any string that does not start with defice (sp?) actually)- See Also:
-
-
Constructor Details
-
AbstractCommandLineParser
Constructs new parser- Parameters:
args-arrayof arguments to parse
-
-
Method Details
-
parse
Main entry point of the parser- Throws:
AbstractCommandLineParser.ParseException- if it fails to parse
-
getArgValue
- Returns:
- current argument
-
getTokenType
protected int getTokenType()- Returns:
- current token
-
setToken
protected void setToken(int token) - Parameters:
token- to set the current token to
-
getTokenValue
- Returns:
Stringvalue of the current token
-
setTokenValue
- Parameters:
tokenValue- to set the current token to
-
getPosition
protected int getPosition()- Returns:
Stringvalue of the current token
-
start
Real entry point of parser- Throws:
AbstractCommandLineParser.ParseException- if the parser fails
-
help
-
hasNext
protected boolean hasNext() -
nextToken
protected void nextToken()Reads the next available token. -
nextArg
protected void nextArg()
-