1 19 20 package org.netbeans.lib.lexer.test.simple; 21 22 import org.netbeans.api.lexer.Token; 23 import org.netbeans.spi.lexer.Lexer; 24 import org.netbeans.spi.lexer.LexerInput; 25 import org.netbeans.spi.lexer.LexerRestartInfo; 26 import org.netbeans.spi.lexer.TokenFactory; 27 28 34 35 public class SimpleJavadocLexer implements Lexer<SimpleJavadocTokenId> { 36 37 private static final int EOF = LexerInput.EOF; 38 39 private LexerInput input; 40 41 private TokenFactory<SimpleJavadocTokenId> tokenFactory; 42 43 public SimpleJavadocLexer(LexerRestartInfo<SimpleJavadocTokenId> info) { 44 this.input = info.input(); 45 this.tokenFactory = info.tokenFactory(); 46 assert (info.state() == null); } 48 49 public Object state() { 50 return null; 51 } 52 53 public Token<SimpleJavadocTokenId> nextToken() { 54 int ch = input.read(); 55 56 if (ch == EOF) { 57 return null; 58 } 59 60 if (Character.isJavaIdentifierStart(ch)) { 61 while (Character.isJavaIdentifierPart(input.read())) 63 ; 64 65 input.backup(1); 66 return token(SimpleJavadocTokenId.IDENT); 67 } 68 69 if ("@<.#".indexOf(ch) == (-1)) { 70 ch = input.read(); 72 73 while (!Character.isJavaIdentifierStart(ch) && "@<.#".indexOf(ch) == (-1) && ch != EOF) 74 ch = input.read(); 75 76 if (ch != EOF) 77 input.backup(1); 78 return token(SimpleJavadocTokenId.OTHER_TEXT); 79 } 80 81 switch (ch) { 82 case '@': 83 while (true) { 84 ch = input.read(); 85 86 if (!Character.isLetter(ch)) { 87 input.backup(1); 88 return tokenFactory.createToken(SimpleJavadocTokenId.TAG, input.readLength()); 89 } 90 } 91 case '<': 92 while (true) { 93 ch = input.read(); 94 if (ch == '>' || ch == EOF) { 95 return token(SimpleJavadocTokenId.HTML_TAG); 96 } 97 } 98 case '.': 99 return token(SimpleJavadocTokenId.DOT); 100 case '#': 101 return token(SimpleJavadocTokenId.HASH); 102 } 104 assert false; 105 106 return null; 107 } 108 109 private Token<SimpleJavadocTokenId> token(SimpleJavadocTokenId id) { 110 return tokenFactory.createToken(id); 111 } 112 113 public void release() { 114 } 115 116 } 117 | Popular Tags |