FileDocCategorySizeDatePackage
XPathParser.javaAPI DocJava SE 6 API207971Tue Jun 10 00:22:30 BST 2008com.sun.org.apache.xalan.internal.xsltc.compiler

XPathParser

public class XPathParser extends lr_parser
CUP v0.10j generated parser.
version
Thu Oct 06 10:09:26 PDT 2005

Fields Summary
protected static final short[]
_production_table
Production table.
protected static final short[]
_action_table
Parse-action table.
protected static final short[]
_reduce_table
reduce_goto table.
protected CUP$XPathParser$actions
action_obj
Instance of action encapsulation class.
public static final Vector
EmptyArgs
Used by function calls with no args.
public static final VariableRef
DummyVarRef
Reference to non-existing variable.
private Parser
_parser
Reference to the Parser class.
private XSLTC
_xsltc
private String
_expression
String representation of the expression being parsed.
private int
_lineNumber
Line number where this expression/pattern was declared.
public SymbolTable
_symbolTable
Reference to the symbol table.
Constructors Summary
public XPathParser()
Default constructor.

super();
public XPathParser(Parser parser)


       
        _parser = parser;
	_xsltc = parser.getXSLTC();
        _symbolTable = parser.getSymbolTable();
    
public XPathParser(Scanner s)
Constructor which sets the default scanner.

super(s);
Methods Summary
public intEOF_sym()
EOF Symbol index.

return 0;
public short[][]action_table()
Access to parse-action table.


       
     return _action_table;
public final voidaddError(com.sun.org.apache.xalan.internal.xsltc.compiler.util.ErrorMsg error)

	_parser.reportError(Constants.ERROR, error);
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.StepPatterncreateStepPattern(int axis, java.lang.Object test, java.util.Vector predicates)
This method is similar to findNodeType(int, Object) except that it creates a StepPattern instead of just returning a node type. It also differs in the way it handles "{uri}:*" and "{uri}:@*". The last two patterns are expanded as "*[namespace-uri() = 'uri']" and "@*[namespace-uri() = 'uri']", respectively. This expansion considerably simplifies the grouping of patterns in the Mode class. For this expansion to be correct, the priority of the pattern/template must be set to -0.25 (when no other predicates are present).

	int nodeType;

	if (test == null) {  // "*"
	    nodeType = (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE : 
		(axis == Axis.NAMESPACE) ? -1 : NodeTest.ELEMENT;

	    return new StepPattern(axis, nodeType, predicates);
        }
        else if (test instanceof Integer) {
	    nodeType = ((Integer) test).intValue();

	    return new StepPattern(axis, nodeType, predicates);
        }
        else {
	    QName name = (QName)test;
	    boolean setPriority = false;

	    if (axis == Axis.NAMESPACE) {
		nodeType = (name.toString().equals("*")) ? -1
				: _xsltc.registerNamespacePrefix(name);;
            }
	    else {
		final String uri = name.getNamespace();
		final String local = name.getLocalPart();
		final QName namespace_uri = 
		    _parser.getQNameIgnoreDefaultNs("namespace-uri");

		// Expand {uri}:* to *[namespace-uri() = 'uri'] - same for @*
		if (uri != null && (local.equals("*") || local.equals("@*"))) {
		    if (predicates == null) {
			predicates = new Vector(2);
		    }

		    // Priority is set by hand if no other predicates exist
		    setPriority = (predicates.size() == 0);

		    predicates.add(
			new Predicate(
			    new EqualityExpr(Operators.EQ, 
				new NamespaceUriCall(namespace_uri), 
				new LiteralExpr(uri))));
		}

		if (local.equals("*")) {
		    nodeType = (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE
			: NodeTest.ELEMENT;
		}
		else if (local.equals("@*")) {
		    nodeType = NodeTest.ATTRIBUTE;
		}
		else {
		    nodeType = (axis == Axis.ATTRIBUTE) ? _xsltc.registerAttribute(name)
			: _xsltc.registerElement(name); 
		}
	    }

	    final StepPattern result = new StepPattern(axis, nodeType, predicates); 

	    // Set priority for case prefix:* and prefix:@* (no predicates)
	    if (setPriority) {
		result.setPriority(-0.25);
	    }

	    return result;
	}
    
public com.sun.java_cup.internal.runtime.Symboldo_action(int act_num, com.sun.java_cup.internal.runtime.lr_parser parser, java.util.Stack stack, int top)
Invoke a user supplied parse action.

    /* call code in generated class */
    return action_obj.CUP$XPathParser$do_action(act_num, parser, stack, top);
  
public interror_sym()
error Symbol index.

return 1;
public intfindNodeType(int axis, java.lang.Object test)

	if (test == null) {  // *
	    return (axis == Axis.ATTRIBUTE) ? 
		NodeTest.ATTRIBUTE :
		(axis == Axis.NAMESPACE) ? -1 : NodeTest.ELEMENT;
        }
        else if (test instanceof Integer) {
            return ((Integer)test).intValue();
        }
        else {
	    QName name = (QName)test;

	    if (axis == Axis.NAMESPACE) {
		return (name.toString().equals("*")) ? -1
		    : _xsltc.registerNamespacePrefix(name);
            }

	    if (name.getNamespace() == null) {
		final String local = name.getLocalPart();

		if (local.equals("*")) {
		    return (axis == Axis.ATTRIBUTE) ? NodeTest.ATTRIBUTE
			: NodeTest.ELEMENT;
		}
		else if (local.equals("@*")) {
		    return NodeTest.ATTRIBUTE;
		}
	    }

	    return (axis == Axis.ATTRIBUTE) ? _xsltc.registerAttribute(name)
		: _xsltc.registerElement(name); 
        }
    
public intgetLineNumber()

        return _lineNumber;
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.QNamegetQName(java.lang.String namespace, java.lang.String prefix, java.lang.String localname)

        return _parser.getQName(namespace, prefix, localname);
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.QNamegetQNameIgnoreDefaultNs(java.lang.String name)

          return _parser.getQNameIgnoreDefaultNs(name);
    
protected voidinit_actions()
Action encapsulation object initializer.

      action_obj = new CUP$XPathParser$actions(this);
    
public com.sun.org.apache.xalan.internal.xsltc.compiler.RelativeLocationPathinsertStep(com.sun.org.apache.xalan.internal.xsltc.compiler.Step step, com.sun.org.apache.xalan.internal.xsltc.compiler.RelativeLocationPath rlp)

	if (rlp instanceof Step) {
	    return new ParentLocationPath(step, (Step) rlp);
	}
	else if (rlp instanceof ParentLocationPath) {
	    final ParentLocationPath plp = (ParentLocationPath) rlp;
	    final RelativeLocationPath newrlp = insertStep(step, plp.getPath());
	    return new ParentLocationPath(newrlp, plp.getStep());
	}
	else {
	    addError(new ErrorMsg(ErrorMsg.INTERNAL_ERR, "XPathParser.insertStep"));
	    return rlp;
	}
    
public booleanisElementAxis(int axis)
Returns true if the axis applies to elements only. The axes child, attribute, namespace, descendant result in non-empty nodesets only if the context node is of type element.

	return (axis == Axis.CHILD || axis == Axis.ATTRIBUTE ||
		axis == Axis.NAMESPACE || axis == Axis.DESCENDANT);
    
final com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNodelookupName(com.sun.org.apache.xalan.internal.xsltc.compiler.QName name)
Lookup a variable or parameter in the symbol table given its name.

param
name Name of the symbol being looked up.

        // Is it a local var or param ?
        final SyntaxTreeNode result = _parser.lookupVariable(name);
	if (result != null)
            return(result);
        else
	    return(_symbolTable.lookupName(name));
    
public com.sun.java_cup.internal.runtime.Symbolparse(java.lang.String expression, int lineNumber)
Parse the expression passed to the current scanner. If this expression contains references to local variables and it will be compiled in an external module (not in the main class) request the current template to create a new variable stack frame.

param
lineNumber Line where the current expression is defined.
param
external Set to true if this expression is compiled in a separate module.

        try {
	    _expression = expression;
	    _lineNumber = lineNumber;
	    return super.parse();
        }
        catch (IllegalCharException e) {
            ErrorMsg err = new ErrorMsg(ErrorMsg.ILLEGAL_CHAR_ERR,
                                        lineNumber, e.getMessage());
            _parser.reportError(Constants.FATAL, err);
        }
        return null;
    
public short[][]production_table()
Access to production table.


       
     return _production_table;
public short[][]reduce_table()
Access to reduce_goto table.


       
     return _reduce_table;
public voidreport_error(java.lang.String message, java.lang.Object info)

	final ErrorMsg err = new ErrorMsg(ErrorMsg.SYNTAX_ERR, _lineNumber, 
	    _expression);
	_parser.reportError(Constants.FATAL, err);
    
public voidreport_fatal_error(java.lang.String message, java.lang.Object info)

        // empty
    
public voidsetCallsNodeset(boolean flag)

          _xsltc.setCallsNodeset(flag);
    
public voidsetHasIdCall(boolean flag)

          _xsltc.setHasIdCall(flag); 
    
public voidsetMultiDocument(boolean flag)

          _xsltc.setMultiDocument(flag);
    
public intstart_production()
Indicates start production.

return 0;
public intstart_state()
Indicates start state.

return 0;