1 19 20 package org.netbeans.lib.lexer; 21 22 import org.netbeans.api.lexer.TokenId; 23 import org.netbeans.spi.lexer.LexerInput; 24 import org.netbeans.lib.lexer.token.AbstractToken; 25 26 32 33 public class TextLexerInputOperation<T extends TokenId> extends LexerInputOperation<T> { 34 35 38 private final CharSequence inputText; 39 40 private final int inputTextStartOffset; 41 42 45 private int readEndIndex; 46 47 48 public TextLexerInputOperation(TokenList<T> tokenList, CharSequence inputText) { 49 this(tokenList, 0, null, inputText, 0, 0, inputText.length()); 50 } 51 52 public TextLexerInputOperation(TokenList<T> tokenList, int tokenIndex, 53 Object lexerRestartState, CharSequence inputText, int inputTextStartOffset, 54 int startOffset, int endOffset) { 55 super(tokenList, tokenIndex, lexerRestartState); 56 this.inputText = inputText; 57 this.inputTextStartOffset = inputTextStartOffset; 58 59 startOffset -= inputTextStartOffset; 61 endOffset -= inputTextStartOffset; 62 assert (0 <= startOffset) && (startOffset <= endOffset) 63 && (endOffset <= inputText.length()); 64 setTokenStartIndex(startOffset); 65 readEndIndex = endOffset; 66 } 67 68 public int read(int index) { index += tokenStartIndex(); 70 if (index < readEndIndex) { 71 return inputText.charAt(index); 72 } else { return LexerInput.EOF; 74 } 75 } 76 77 public char readExisting(int index) { 78 return inputText.charAt(tokenStartIndex() + index); 79 } 80 81 public void approveToken(AbstractToken<T> token) { 82 int tokenLength = tokenLength(); 83 if (isSkipToken(token)) { 84 preventFlyToken(); 85 86 } else if (token.isFlyweight()) { 87 assert isFlyTokenAllowed(); 88 flyTokenAdded(); 89 90 } else { token.setTokenList(tokenList()); 92 token.setRawOffset(inputTextStartOffset + tokenStartIndex()); 93 clearFlySequence(); 94 } 95 96 tokenApproved(); 97 } 98 99 protected final int readEndIndex() { 100 return readEndIndex; 101 } 102 103 } 104 | Popular Tags |