1 16 17 package org.mc4j.console.swing.editor.xml; 18 19 import java.util.regex.Matcher ; 20 21 25 public class RETokenizer { 26 protected StyleTokens types; 27 protected Matcher matcher; 28 29 public RETokenizer(StyleTokens types, String text) { 30 this.types = types; 31 matcher = types.getMatcher(text); 32 } 33 34 46 47 protected Token getToken(int pos) { 48 int count = types.getTokens().length; 49 for (int i = 0; i < types.getTokens().length; i++) { 50 StyleTokens.StyleToken styleToken = types.getTokens()[i]; 51 String token = matcher.group(i+1); 52 if (token != null) { 53 String type = styleToken.name; 54 return new Token(token, type, pos); 55 } 56 } 57 return null; 58 } 59 60 public Token nextToken() { 61 if (matcher.find()) { 62 return getToken(matcher.start()); 63 } 64 return null; 65 } 66 67 public static class Token { 68 public String token; 69 public String type; 70 protected int position; 71 72 public Token(String token, String type, int getPosition) { 73 this.token = token; 74 this.type = type; 75 this.position = getPosition; 76 } 77 78 public String getText() { 79 return token; 80 } 81 82 public String getType() { 83 return type; 84 } 85 86 public int getPosition() { 87 return position; 88 } 89 90 public String toString() { 91 return type + "(" + token + ", " + position + ')'; 92 } 93 } 94 } 95 | Popular Tags |