|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||
See:
Description
| Interface Summary | |
|---|---|
| CharScannerSyntax | This is the interface used to define the syntax to scan characters. |
| CharStreamScanner | This is the interface for a scanner that can be used to parse a stream or sequence of characters. |
| Class Summary | |
|---|---|
| AbstractCharScannerSyntax | This is the abstract base implementation of the CharScannerSyntax
interface. |
| CharSequenceScanner | This class represents a String or better a sequence of characters (char[])
together with a position in that sequence. |
| SimpleCharScannerSyntax | This class is a simple container for the special characters of a syntax to scan. |
Contains scanners to parse character sequences efficient and easily.
javacc or antlr.CharStreamScanner is an interface
that covers typical tasks when paring strings or streams and therefore makes
your life a lot easier. You can concentrate on the syntax you want to parse
and do NOT need to repeat checks if the end is already reached all the time.
For parsing strings there is the implementation
CharSequenceScanner that bundles the
string together with the state (parsing position) so you can easily delegate
a step to another method or class. Otherwise you would need to pass the current
position to that method and return the new one from there. This is tricky if
the method should already return something else.
String input = getInputString();
int i = 0;
boolean colonFound = false;
while (i < input.length()) {
char c = input.charAt(i++);
if (c == ':') {
colonFound = true;
break;
}
}
if (!colonFound) {
throw new IllegalArgumentException("Expected character ':' not found!");
}
String key = input.substring(0, i - 1);
String value = null;
if (i < input.length()) {
while ((i < input.length()) && (input.charAt(i) == ' ')) {
i++;
}
int start = i;
while (i < input.length()) {
char c = input.charAt(i);
if ((c < '0') || (c > '9')) {
break;
}
i++;
}
value = input.substring(start, i);
}
Here is the same thing when using CharSequenceScanner:
String input = getInputString();CharSequenceScannerscanner = newCharSequenceScanner(input); String key = scanner.readUntil(':', false); if (key == null) { throw new IllegalArgumentException("Expected character ':' not found!"); } scanner.skipWhile(' '); String value = scanner.readWhile(CharFilter.LATIN_DIGIT_FILTER);
|
||||||||||
| PREV PACKAGE NEXT PACKAGE | FRAMES NO FRAMES | |||||||||