1 package persistence.antlr; 2 3 8 9 class StringLiteralElement extends GrammarAtom { 10 protected String processedAtomText; 12 13 14 public StringLiteralElement(Grammar g, Token t, int autoGenType) { 15 super(g, t, autoGenType); 16 if (!(g instanceof LexerGrammar)) { 17 TokenSymbol ts = grammar.tokenManager.getTokenSymbol(atomText); 19 if (ts == null) { 20 g.antlrTool.error("Undefined literal: " + atomText, grammar.getFilename(), t.getLine(), t.getColumn()); 21 } 22 else { 23 tokenType = ts.getTokenType(); 24 } 25 } 26 line = t.getLine(); 27 28 processedAtomText = new String (); 31 for (int i = 1; i < atomText.length() - 1; i++) { 32 char c = atomText.charAt(i); 33 if (c == '\\') { 34 if (i + 1 < atomText.length() - 1) { 35 i++; 36 c = atomText.charAt(i); 37 switch (c) { 38 case 'n': 39 c = '\n'; 40 break; 41 case 'r': 42 c = '\r'; 43 break; 44 case 't': 45 c = '\t'; 46 break; 47 } 48 } 49 } 50 if (g instanceof LexerGrammar) { 51 ((LexerGrammar)g).charVocabulary.add(c); 52 } 53 processedAtomText += c; 54 } 55 } 56 57 public void generate() { 58 grammar.generator.gen(this); 59 } 60 61 public Lookahead look(int k) { 62 return grammar.theLLkAnalyzer.look(k, this); 63 } 64 } 65 | Popular Tags |