nl.pbemengine.engine.ng.tools
Class LineParser

java.lang.Object
  extended by nl.pbemengine.engine.ng.tools.LineParser

public class LineParser
extends java.lang.Object

Takes a line contained in a String, and gives the ability to parse that string to see if it matches a sequence of tokens. The first word of the string is extracted, and treated separately.

Author:
Jeroen Steenbeeke

Constructor Summary
LineParser(java.lang.String line)
          Creates a new instance of LineParser, identifying the first word as the so-called command, and matching the rest by a given set of Tokens
 
Method Summary
 char getNextChar()
          Returns the first character of the remaining string and increases the search index
 java.lang.Object[] getResults()
          Retrieve the results created by the last parsing rounds.
 boolean hasMoreChars()
          Determines whether or not we've reached the end of the parseable string
 boolean match(Token[] tokens)
          Match the given sequence of tokens to an array of Tokens
 boolean match(TokenSequence seq)
          Match the given sequence of tokens to a TokenSequence
 char peekNextChar()
          Returns the first character of the remaining string without increasing the search index
 void skipWhiteSpaces()
          Skips any whitespaces in the line until a non-whitespace char is encountered
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LineParser

public LineParser(java.lang.String line)
Creates a new instance of LineParser, identifying the first word as the so-called command, and matching the rest by a given set of Tokens

Parameters:
line - The line to parse
Method Detail

getNextChar

public char getNextChar()
Returns the first character of the remaining string and increases the search index

Returns:
A char containing the next character in the string, or a NUL char if trying to read beyond the string length

peekNextChar

public char peekNextChar()
Returns the first character of the remaining string without increasing the search index

Returns:
A char containing the next character in the string, or a NUL char if trying to read beyond the string length

hasMoreChars

public boolean hasMoreChars()
Determines whether or not we've reached the end of the parseable string

Returns:
true if there are still chars remaining in the string, false otherwise.

skipWhiteSpaces

public void skipWhiteSpaces()
Skips any whitespaces in the line until a non-whitespace char is encountered


match

public boolean match(Token[] tokens)
Match the given sequence of tokens to an array of Tokens

Parameters:
tokens - The array of tokens to match
Returns:
true if the sequence of Tokens matches this string false otherwise

match

public boolean match(TokenSequence seq)
Match the given sequence of tokens to a TokenSequence

Parameters:
seq - The TokenSequence to match this line to
Returns:
true if the sequence of Tokens matches this string false otherwise

getResults

public java.lang.Object[] getResults()
Retrieve the results created by the last parsing rounds. Note that if the parse was unsuccesful, the content of the given array is undefined. If this method is called before any parse took place, an empty array is returned.

Returns:
An array of TokenValues


Copyright © 2008. All Rights Reserved.