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