FileDocCategorySizeDatePackage
ParserCore.javaAPI DocphoneME MR2 API (J2ME)5179Wed May 02 18:00:42 BST 2007gov.nist.core

ParserCore

public abstract class ParserCore extends Object
Generic parser class. All parsers inherit this class.
version
JAIN-SIP-1.1 This code is in the public domain.

Fields Summary
public static final boolean
debug
Flag to indicate parsing diagnostics should be logged.
protected static int
nesting_level
Current nesting level int recursive parsing.
protected LexerCore
lexer
Current lexer engine.
Constructors Summary
Methods Summary
protected voiddbg_enter(java.lang.String rule)
Beginning of debug operation.

param
rule the name of the rule being evaluated

        StringBuffer stringBuffer = new StringBuffer();
        
        for (int i = 0; i < nesting_level; i++)
            stringBuffer.append(">");

        if (debug)  {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
                    stringBuffer + rule +
                    "\nlexer buffer = \n" +
                    lexer.getRest());
        }
        nesting_level++;
    
protected voiddbg_leave(java.lang.String rule)
Completion of diagnostic operation.

param
rule name of the rule being evaluated

        StringBuffer stringBuffer = new StringBuffer();
        for (int i = 0; i < nesting_level; i++)
            stringBuffer.append("<");

        if (debug)  {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
                    stringBuffer +
                    rule +
                    "\nlexer buffer = \n" +
                    lexer.getRest());
        }
        nesting_level --;
    
protected NameValuenameValue(char separator)
Gets a name value pair with the specified separator.

param
separator character to use int encoded return value
return
encoded name value text string.
exception
ParseException if a parsing error occurs


                                        
           
        if (debug)
            dbg_enter("nameValue");
        try {

            lexer.match(LexerCore.ID);
            Token name = lexer.getNextToken();
            // eat white space.
            lexer.SPorHT();
            try {
                boolean quoted = false;
                char la = lexer.lookAhead(0);

                if (la == separator) {
                    lexer.consume(1);
                    lexer.SPorHT();
                    String str = null;
                    if (lexer.lookAhead(0) == '\"")  {
                        str = lexer.quotedString();
                        quoted = true;
                    } else {
                        lexer.match(LexerCore.ID);
                        Token value = lexer.getNextToken();
                        str = value.tokenValue;
                    }
                    NameValue nv =
                            new NameValue(name.tokenValue, str);
                    if (quoted) nv.setQuotedValue();
                    return nv;
                } else {
                    // if the parameter has no value, an empty string is used
                    return new NameValue(name.tokenValue, "");
                }
            } catch (ParseException ex) {
                return new NameValue(name.tokenValue, "");
            }

        } finally {
            if (debug) dbg_leave("nameValue");
        }


    
protected NameValuenameValue()
Gets name value token using '=' as a separator.

return
the name value token
exception
ParseException if a parsing error occurs

        return nameValue('=");
    
protected voidpeekLine(java.lang.String rule)
Peeks at the next line.

param
rule the name of the lexer rule to apply

        if (ParserCore.debug) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_JSR180,
                rule + " " + lexer.peekLine());
        }