FileDocCategorySizeDatePackage
StringLiteralElement.javaAPI DocGlassfish v2 API2099Wed Aug 30 15:34:10 BST 2006persistence.antlr

StringLiteralElement

public class StringLiteralElement extends GrammarAtom

Fields Summary
protected String
processedAtomText
Constructors Summary
public StringLiteralElement(Grammar g, Token t, int autoGenType)

        super(g, t, autoGenType);
        if (!(g instanceof LexerGrammar)) {
            // lexer does not have token types for string literals
            TokenSymbol ts = grammar.tokenManager.getTokenSymbol(atomText);
            if (ts == null) {
                g.antlrTool.error("Undefined literal: " + atomText, grammar.getFilename(), t.getLine(), t.getColumn());
            }
            else {
                tokenType = ts.getTokenType();
            }
        }
        line = t.getLine();

        // process the string literal text by removing quotes and escaping chars
        // If a lexical grammar, add the characters to the char vocabulary
        processedAtomText = new String();
        for (int i = 1; i < atomText.length() - 1; i++) {
            char c = atomText.charAt(i);
            if (c == '\\") {
                if (i + 1 < atomText.length() - 1) {
                    i++;
                    c = atomText.charAt(i);
                    switch (c) {
                        case 'n":
                            c = '\n";
                            break;
                        case 'r":
                            c = '\r";
                            break;
                        case 't":
                            c = '\t";
                            break;
                    }
                }
            }
            if (g instanceof LexerGrammar) {
                ((LexerGrammar)g).charVocabulary.add(c);
            }
            processedAtomText += c;
        }
    
Methods Summary
public voidgenerate()

        grammar.generator.gen(this);
    
public persistence.antlr.Lookaheadlook(int k)

        return grammar.theLLkAnalyzer.look(k, this);