1 package org.antlr.works.syntax; 2 3 import org.antlr.works.ate.syntax.generic.ATESyntaxLexer; 4 import org.antlr.works.ate.syntax.misc.ATEToken; 5 import org.antlr.works.syntax.element.ElementToken; 6 7 37 38 public class GrammarSyntaxLexer extends ATESyntaxLexer { 39 40 public static final int TOKEN_REFERENCE = 100; 41 public static final int TOKEN_LABEL = 101; 42 public static final int TOKEN_BLOCK_LABEL = 102; 43 public static final int TOKEN_BLOCK_LIMIT = 103; 44 public static final int TOKEN_REWRITE = 104; 45 public static final int TOKEN_DECL = 105; 46 public static final int TOKEN_OPEN_DOUBLE_ANGLE = 106; 47 public static final int TOKEN_CLOSE_DOUBLE_ANGLE = 107; 48 public static final int TOKEN_INTERNAL_REF = 108; 50 @Override 51 protected ATEToken customMatch() { 52 if(c0 == '@') { 53 return matchID(); 54 } else if(c0 == '-' && c1 == '>') { 55 int sp = position; 56 position++; 57 return createNewToken(TOKEN_REWRITE, sp, position); 58 } else if(c0 == '<' && c1 == '<') { 59 int sp = position; 60 position++; 61 return createNewToken(TOKEN_OPEN_DOUBLE_ANGLE, sp, position); 62 } else if(c0 == '>' && c1 == '>') { 63 int sp = position; 64 position++; 65 return createNewToken(TOKEN_CLOSE_DOUBLE_ANGLE, sp, position); 66 } else { 67 return null; 68 } 69 } 70 71 @Override 72 protected ATEToken matchID() { 73 int sp = position; 74 if(c0 == '@') { 75 while((isID(c1) || c1 == ':') && nextCharacter()) { 78 } 79 } else { 80 while(isID(c1) && nextCharacter()) { 82 } 83 } 84 85 return createNewToken(TOKEN_ID, sp); 86 } 87 88 @Override 89 public ATEToken createNewToken(int type, int start, int end, 90 int startLineNumber, int endLineNumber, 91 int startLineIndex, int endLineIndex) 92 { 93 return new ElementToken(type, start, end, startLineNumber, endLineNumber, startLineIndex, endLineIndex, text); 94 } 95 96 97 } 98 | Popular Tags |