import java.util.ArrayList;
import java.util.List;
import java.util.Stack;
+import java.util.stream.Stream;
import static eu.svjatoslav.commons.string.tokenizer.Terminator.TerminationStrategy.DROP;
return this;
}
- public void expectNextToken(final String value)
+ public void expectAndConsumeNextToken(final String value)
throws InvalidSyntaxException {
final TokenizerMatch match = getNextToken();
if (!value.equals(match.token))
return false;
}
+ public TokenizerMatch peekNextToken(){
+ TokenizerMatch result = getNextToken();
+ unreadToken();
+ return result;
+ }
+
+ public boolean peekIsOneOf(String ... possibilities){
+ String nextToken = peekNextToken().token;
+ return Stream.of(possibilities).anyMatch(possibility -> possibility.equals(nextToken));
+ }
+
+ public void peekExpectNoneOf(String ... possibilities) throws InvalidSyntaxException {
+ if (peekIsOneOf(possibilities))
+ throw new InvalidSyntaxException("Not expected \"" + peekNextToken().token + "\" here.");
+ }
+
+
public boolean sequenceMatches(final String sequence) {
if ((currentIndex + sequence.length()) > source.length())
return false;