1 package jfun.parsec.tokens; 2 3 import jfun.parsec.Tokenizer; 4 5 12 public class Tokenizers { 13 14 20 public static <T> Tokenizer forTypedToken(final T type){ 21 return new Tokenizer(){ 22 public Object toToken(CharSequence cs, int from, int len) { 23 return Tokens.createTypedToken(cs.subSequence(from, from+len).toString(), type); 24 } 25 }; 26 } 27 private static final Tokenizer reserved = forTypedToken(TokenType.Reserved); 28 private static final Tokenizer word = forTypedToken(TokenType.Word); 29 private static final Tokenizer integer = forTypedToken(TokenType.Integer); 30 private static final Tokenizer decimal = forTypedToken(TokenType.Decimal); 31 34 public static Tokenizer forReservedWord(){ 35 return reserved; 36 } 37 40 public static Tokenizer forWord(){ 41 return word; 42 } 43 46 public static Tokenizer forInteger(){ 47 return integer; 48 } 49 52 public static Tokenizer forDecimal(){ 53 return decimal; 54 } 55 59 public static Tokenizer forChar(){ 60 return TokenCharLiteral.getTokenizer(); 61 } 62 65 public static Tokenizer forString(){ 66 return TokenString.getTokenizer(); 67 } 68 72 public static Tokenizer forDecLong(){ 73 return TokenLong.getDecTokenizer(); 74 } 75 79 public static Tokenizer forHexLong(){ 80 return TokenLong.getHexTokenizer(); 81 } 82 86 public static Tokenizer forOctLong(){ 87 return TokenLong.getOctTokenizer(); 88 } 89 94 public static Tokenizer forSimpleStringLiteral(){ 95 return TokenStringLiteral.getDoubleQuoteTokenizer(); 96 } 97 102 public static Tokenizer forSqlStringLiteral(){ 103 return TokenStringLiteral.getSqlTokenizer(); 104 } 105 110 public static Tokenizer forQuotedString(char open, char close){ 111 return TokenQuoted.getTokenizer(open, close); 112 } 113 118 public static Tokenizer forQuotedString(String open, String close){ 119 return TokenQuoted.getTokenizer(open, close); 120 } 121 } 122 | Popular Tags |