| Author | Dave Jarvis <email> |
|---|---|
| Date | 2022-08-13 17:00:58 GMT-0700 |
| Commit | 886ac2fd91553299ed26252e463c96779df36acd |
| Parent | a511db7 |
| /** | ||
| - * Returns the total number of characters in the string to iterate. | ||
| - * | ||
| - * @return The string length. | ||
| - */ | ||
| - public int length() { | ||
| - return mLen; | ||
| - } | ||
| - | ||
| - /** | ||
| * Returns the iterated index. The return value is not guaranteed to be | ||
| * within the string bounds. | ||
| final var pos = mPos; | ||
| return pos + 1 < mLen ? mS.charAt( pos + 1 ) : DONE; | ||
| + } | ||
| + | ||
| + /** | ||
| + * Answers whether {@link #next()} followed by {@link #current()} is safe. | ||
| + * | ||
| + * @return {@code true} if there are more characters to be iterated. | ||
| + */ | ||
| + public boolean hasNext() { | ||
| + return mPos < mLen; | ||
| } | ||
| final Consumer<Lexeme> emitter, | ||
| final Consumer<FastCharacterIterator> filter ) { | ||
| - var index = i.index(); | ||
| - var length = i.length(); | ||
| - var curr = ' '; | ||
| - while( index < length ) { | ||
| + while( i.hasNext() ) { | ||
| // Allow filters to skip character sequences (such as XML tags). | ||
| filter.accept( i ); | ||
| - | ||
| - index = i.index(); | ||
| - curr = i.current(); | ||
| + final var index = i.index(); | ||
| + final var curr = i.current(); | ||
| var token = PUNCT; | ||
| } | ||
| else if( curr == '.' ) { | ||
| - final var start = i.index(); | ||
| - | ||
| i.skip( next -> next == '.' || next == ' ' && i.peek() == '.' ); | ||
| - token = i.index() - start == 0 ? PERIOD : ELLIPSIS; | ||
| + token = i.index() - index == 0 ? PERIOD : ELLIPSIS; | ||
| } | ||
| else if( curr == '"' ) { | ||
| emitter.accept( new Lexeme( token, index, i.index() + 1 ) ); | ||
| i.next(); | ||
| - index = i.index(); | ||
| } | ||
| } | ||
| final class Token implements Comparable<Token> { | ||
| private final TokenType mType; | ||
| - final int mBegan; | ||
| - final int mEnded; | ||
| + private final int mBegan; | ||
| + private final int mEnded; | ||
| /** |
| Delta | 15 lines added, 22 lines removed, 7-line decrease |
|---|