- return new TokenizerMatch(terminator.startSequence, reminder, terminator);
- } else {
- currentIndex += terminator.startSequence.length();
- return new TokenizerMatch(terminator.startSequence, "", terminator);
- }
+ return new TokenizerMatch(terminator.startSequence, reminder, terminator);
+ }
+
+ /**
+ * @throws InvalidSyntaxException if end of input is reached without finding expected end sequence.
+ */
+ 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;