Package jasima.core.util.converter
Class ArgListTokenizer
- java.lang.Object
-
- jasima.core.util.converter.ArgListTokenizer
-
public class ArgListTokenizer extends Object
Splits an input string in tokens, so lists and parameter lists can be recognized. This class recognizes (quoted) Strings with back-slash as an escape character, white space, and as special one-character tokens: "(", ")", ";", "=".- Author:
- Torsten Hildebrandt
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classArgListTokenizer.ParseExceptionAParseExceptionis thrown if there were problems splitting the input string into tokens.static classArgListTokenizer.TokenTypeThe recognized tokens.
-
Constructor Summary
Constructors Constructor Description ArgListTokenizer()ArgListTokenizer(String input)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassureTokenTypes(ArgListTokenizer.TokenType actual, ArgListTokenizer.TokenType... expected)Checks whether the actual token's type matches a certain set of expected types.intcurrTokenEnd()intcurrTokenStart()StringcurrTokenText()Returns the portion of the input text that is associated with the current token.ArgListTokenizer.TokenTypecurrTokenType()static StringescapeString(String raw)ArgListTokenizer.TokenTypenextToken()Returns the next token in the input String.ArgListTokenizer.TokenTypenextTokenNoWhitespace()Returns the next token that is not whitespace.voidpushBackToken()Resets the current reading position back to beginning of the current token, sonextToken()will see the same token again.static StringquoteString(String raw)protected voidreset()voidsetInput(String input)Sets the input string to work on.
-
-
-
Constructor Detail
-
ArgListTokenizer
public ArgListTokenizer()
-
ArgListTokenizer
public ArgListTokenizer(String input)
-
-
Method Detail
-
reset
protected void reset()
-
nextTokenNoWhitespace
public ArgListTokenizer.TokenType nextTokenNoWhitespace()
Returns the next token that is not whitespace.- Returns:
- The type of the next token that is not
WHITE_SPACE.
-
nextToken
public ArgListTokenizer.TokenType nextToken()
Returns the next token in the input String. This is on of the values ofArgListTokenizer.TokenType, ornull, if the end of the input was reached. This method can throw the uncheckedArgListTokenizer.ParseException, if there was a problem splitting the input string in tokens.- Returns:
- The current token's type.
-
currTokenText
public String currTokenText()
Returns the portion of the input text that is associated with the current token. This method does not return surrounding quotes of a quotedSTRINGand unescapes any escaped characters.- Returns:
- The current token's text.
-
currTokenType
public ArgListTokenizer.TokenType currTokenType()
-
currTokenStart
public int currTokenStart()
-
currTokenEnd
public int currTokenEnd()
-
pushBackToken
public void pushBackToken()
Resets the current reading position back to beginning of the current token, sonextToken()will see the same token again. This is useful, if a parser detects a token he can't handle but has to pass back to a parent parser for proper processing.
-
setInput
public void setInput(String input)
Sets the input string to work on.- Parameters:
input- The input string.
-
assureTokenTypes
public void assureTokenTypes(ArgListTokenizer.TokenType actual, ArgListTokenizer.TokenType... expected) throws ArgListTokenizer.ParseException
Checks whether the actual token's type matches a certain set of expected types. If the types do not match, then aArgListTokenizer.ParseExceptionis raised.- Parameters:
actual- The current token's type.expected- All token types that are currently valid.- Throws:
ArgListTokenizer.ParseException- Ifactualif not contained inexpected.
-
-