Package org.openzen.zenscript.lexer
Class CharStream
java.lang.Object
org.openzen.zenscript.lexer.CharStream
Represents a character stream. Suitable for character by character parsing.
Used in the regular expression parser.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanhasMore()Checks if the end of the stream has been reached.charnext()Returns the next character in the stream.booleanoptional(char ch) Processes an optional character.charoptional(char from, char to) Processes an optional range of characters.charpeek()booleanpeek(char ch) Checks if the next character in the stream equals the specified character.voidrequired(char ch) Processes a required character.charrequired(char from, char to) Processes a required character range.
-
Constructor Details
-
CharStream
Constructs a character stream from a data string.- Parameters:
data- data string
-
-
Method Details
-
peek
public char peek() -
peek
public boolean peek(char ch) Checks if the next character in the stream equals the specified character.- Parameters:
ch- checked character- Returns:
- true if the next character equals the specified character
-
optional
public boolean optional(char ch) Processes an optional character. If the next character does not equal the specified character, nothing will happen.- Parameters:
ch- checked character- Returns:
- true if the next character equals the specified character
-
optional
public char optional(char from, char to) Processes an optional range of characters. If the next character is not within the specified bounds, nothing will happen.- Parameters:
from- lower character value bound, inclusiveto- upper character value bound, inclusive- Returns:
- the processed character
-
required
public void required(char ch) Processes a required character. If the next character does not equal the specified character, an IllegalArgumentException is thrown.- Parameters:
ch- required character
-
required
public char required(char from, char to) Processes a required character range. If the next character is not within the specified bounds, an IllegalArgumentException is thrown.- Parameters:
from- lower character value bound, inclusiveto- upper character value bound, inclusive- Returns:
- the processed character
-
next
public char next()Returns the next character in the stream.- Returns:
- the next character
-
hasMore
public boolean hasMore()Checks if the end of the stream has been reached.- Returns:
- true if there are more characters in the stream
-