- private TokenizerMatch buildSimplePreservedToken(Terminator terminator) {
- currentIndex += terminator.startSequence.length();
- return new TokenizerMatch(terminator.startSequence, null, terminator);
- }
-
- private TokenizerMatch buildComplexPreservedToken(Terminator terminator) throws InvalidSyntaxException {
- int endSequenceIndex = getEndSequenceIndex(terminator);
- String reminder = source.substring(currentIndex + terminator.startSequence.length(), endSequenceIndex);
- currentIndex = endSequenceIndex + terminator.endSequence.length();
-
- return new TokenizerMatch(terminator.startSequence, reminder, terminator);
- }
-
- private int getEndSequenceIndex(Terminator terminator) throws InvalidSyntaxException {
- int endSequenceIndex = source.indexOf(terminator.endSequence,
- currentIndex + terminator.startSequence.length());
-
- if (endSequenceIndex < 0)
- throw new InvalidSyntaxException("Expected \"" + terminator.endSequence + "\" but not found.");
-
- return endSequenceIndex;
- }
-
- private boolean hasAccumulatedToken(StringBuilder token) {
- return token.length() > 0;
+ public TokenizerMatch findTerminatorMatch(){
+ for (Terminator terminator : terminators)
+ if (terminator.active) {
+ Matcher match = terminator.match(source, currentIndex);
+ if (match.find()) {
+ String token = source.substring(match.start(), match.end());
+ return new TokenizerMatch(token, terminator, match, this);
+ }
+ }
+ return null;