jaxp/src/com/sun/org/apache/xpath/internal/compiler/XPathParser.java
author lana
Tue, 18 Mar 2014 17:49:48 -0700
changeset 23377 2af1ddf102a4
parent 12457 c348e06f0e82
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
7f561c08de6b Initial load
duke
parents:
diff changeset
     1
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     2
 * reserved comment block
7f561c08de6b Initial load
duke
parents:
diff changeset
     3
 * DO NOT REMOVE OR ALTER!
7f561c08de6b Initial load
duke
parents:
diff changeset
     4
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
     5
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
     6
 * Copyright 1999-2004 The Apache Software Foundation.
7f561c08de6b Initial load
duke
parents:
diff changeset
     7
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
     8
 * Licensed under the Apache License, Version 2.0 (the "License");
7f561c08de6b Initial load
duke
parents:
diff changeset
     9
 * you may not use this file except in compliance with the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    10
 * You may obtain a copy of the License at
7f561c08de6b Initial load
duke
parents:
diff changeset
    11
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    12
 *     http://www.apache.org/licenses/LICENSE-2.0
7f561c08de6b Initial load
duke
parents:
diff changeset
    13
 *
7f561c08de6b Initial load
duke
parents:
diff changeset
    14
 * Unless required by applicable law or agreed to in writing, software
7f561c08de6b Initial load
duke
parents:
diff changeset
    15
 * distributed under the License is distributed on an "AS IS" BASIS,
7f561c08de6b Initial load
duke
parents:
diff changeset
    16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
7f561c08de6b Initial load
duke
parents:
diff changeset
    17
 * See the License for the specific language governing permissions and
7f561c08de6b Initial load
duke
parents:
diff changeset
    18
 * limitations under the License.
7f561c08de6b Initial load
duke
parents:
diff changeset
    19
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    20
/*
7f561c08de6b Initial load
duke
parents:
diff changeset
    21
 * $Id: XPathParser.java,v 1.2.4.1 2005/09/14 19:46:02 jeffsuttor Exp $
7f561c08de6b Initial load
duke
parents:
diff changeset
    22
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    23
package com.sun.org.apache.xpath.internal.compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
    24
7f561c08de6b Initial load
duke
parents:
diff changeset
    25
import javax.xml.transform.ErrorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
    26
import javax.xml.transform.TransformerException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    27
7f561c08de6b Initial load
duke
parents:
diff changeset
    28
import com.sun.org.apache.xalan.internal.res.XSLMessages;
7f561c08de6b Initial load
duke
parents:
diff changeset
    29
import com.sun.org.apache.xml.internal.utils.PrefixResolver;
7f561c08de6b Initial load
duke
parents:
diff changeset
    30
import com.sun.org.apache.xpath.internal.XPathProcessorException;
7f561c08de6b Initial load
duke
parents:
diff changeset
    31
import com.sun.org.apache.xpath.internal.domapi.XPathStylesheetDOM3Exception;
7f561c08de6b Initial load
duke
parents:
diff changeset
    32
import com.sun.org.apache.xpath.internal.objects.XNumber;
7f561c08de6b Initial load
duke
parents:
diff changeset
    33
import com.sun.org.apache.xpath.internal.objects.XString;
7f561c08de6b Initial load
duke
parents:
diff changeset
    34
import com.sun.org.apache.xpath.internal.res.XPATHErrorResources;
7f561c08de6b Initial load
duke
parents:
diff changeset
    35
7f561c08de6b Initial load
duke
parents:
diff changeset
    36
/**
7f561c08de6b Initial load
duke
parents:
diff changeset
    37
 * Tokenizes and parses XPath expressions. This should really be named
7f561c08de6b Initial load
duke
parents:
diff changeset
    38
 * XPathParserImpl, and may be renamed in the future.
7f561c08de6b Initial load
duke
parents:
diff changeset
    39
 * @xsl.usage general
7f561c08de6b Initial load
duke
parents:
diff changeset
    40
 */
7f561c08de6b Initial load
duke
parents:
diff changeset
    41
public class XPathParser
7f561c08de6b Initial load
duke
parents:
diff changeset
    42
{
7f561c08de6b Initial load
duke
parents:
diff changeset
    43
        // %REVIEW% Is there a better way of doing this?
7f561c08de6b Initial load
duke
parents:
diff changeset
    44
        // Upside is minimum object churn. Downside is that we don't have a useful
7f561c08de6b Initial load
duke
parents:
diff changeset
    45
        // backtrace in the exception itself -- but we don't expect to need one.
7f561c08de6b Initial load
duke
parents:
diff changeset
    46
        static public final String CONTINUE_AFTER_FATAL_ERROR="CONTINUE_AFTER_FATAL_ERROR";
7f561c08de6b Initial load
duke
parents:
diff changeset
    47
7f561c08de6b Initial load
duke
parents:
diff changeset
    48
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    49
   * The XPath to be processed.
7f561c08de6b Initial load
duke
parents:
diff changeset
    50
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    51
  private OpMap m_ops;
7f561c08de6b Initial load
duke
parents:
diff changeset
    52
7f561c08de6b Initial load
duke
parents:
diff changeset
    53
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    54
   * The next token in the pattern.
7f561c08de6b Initial load
duke
parents:
diff changeset
    55
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    56
  transient String m_token;
7f561c08de6b Initial load
duke
parents:
diff changeset
    57
7f561c08de6b Initial load
duke
parents:
diff changeset
    58
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    59
   * The first char in m_token, the theory being that this
7f561c08de6b Initial load
duke
parents:
diff changeset
    60
   * is an optimization because we won't have to do charAt(0) as
7f561c08de6b Initial load
duke
parents:
diff changeset
    61
   * often.
7f561c08de6b Initial load
duke
parents:
diff changeset
    62
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    63
  transient char m_tokenChar = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    64
7f561c08de6b Initial load
duke
parents:
diff changeset
    65
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    66
   * The position in the token queue is tracked by m_queueMark.
7f561c08de6b Initial load
duke
parents:
diff changeset
    67
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    68
  int m_queueMark = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    69
7f561c08de6b Initial load
duke
parents:
diff changeset
    70
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    71
   * Results from checking FilterExpr syntax
7f561c08de6b Initial load
duke
parents:
diff changeset
    72
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    73
  protected final static int FILTER_MATCH_FAILED     = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
    74
  protected final static int FILTER_MATCH_PRIMARY    = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
    75
  protected final static int FILTER_MATCH_PREDICATES = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
    76
7f561c08de6b Initial load
duke
parents:
diff changeset
    77
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    78
   * The parser constructor.
7f561c08de6b Initial load
duke
parents:
diff changeset
    79
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    80
  public XPathParser(ErrorListener errorListener, javax.xml.transform.SourceLocator sourceLocator)
7f561c08de6b Initial load
duke
parents:
diff changeset
    81
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
    82
    m_errorListener = errorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
    83
    m_sourceLocator = sourceLocator;
7f561c08de6b Initial load
duke
parents:
diff changeset
    84
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
    85
7f561c08de6b Initial load
duke
parents:
diff changeset
    86
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    87
   * The prefix resolver to map prefixes to namespaces in the OpMap.
7f561c08de6b Initial load
duke
parents:
diff changeset
    88
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
    89
  PrefixResolver m_namespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
    90
7f561c08de6b Initial load
duke
parents:
diff changeset
    91
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
    92
   * Given an string, init an XPath object for selections,
7f561c08de6b Initial load
duke
parents:
diff changeset
    93
   * in order that a parse doesn't
7f561c08de6b Initial load
duke
parents:
diff changeset
    94
   * have to be done each time the expression is evaluated.
7f561c08de6b Initial load
duke
parents:
diff changeset
    95
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
    96
   * @param compiler The compiler object.
7f561c08de6b Initial load
duke
parents:
diff changeset
    97
   * @param expression A string conforming to the XPath grammar.
7f561c08de6b Initial load
duke
parents:
diff changeset
    98
   * @param namespaceContext An object that is able to resolve prefixes in
7f561c08de6b Initial load
duke
parents:
diff changeset
    99
   * the XPath to namespaces.
7f561c08de6b Initial load
duke
parents:
diff changeset
   100
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   101
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   102
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   103
  public void initXPath(
7f561c08de6b Initial load
duke
parents:
diff changeset
   104
          Compiler compiler, String expression, PrefixResolver namespaceContext)
7f561c08de6b Initial load
duke
parents:
diff changeset
   105
            throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   106
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   107
7f561c08de6b Initial load
duke
parents:
diff changeset
   108
    m_ops = compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   109
    m_namespaceContext = namespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
   110
    m_functionTable = compiler.getFunctionTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   111
7f561c08de6b Initial load
duke
parents:
diff changeset
   112
    Lexer lexer = new Lexer(compiler, namespaceContext, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   113
7f561c08de6b Initial load
duke
parents:
diff changeset
   114
    lexer.tokenize(expression);
7f561c08de6b Initial load
duke
parents:
diff changeset
   115
7f561c08de6b Initial load
duke
parents:
diff changeset
   116
    m_ops.setOp(0,OpCodes.OP_XPATH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   117
    m_ops.setOp(OpMap.MAPINDEX_LENGTH,2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   118
7f561c08de6b Initial load
duke
parents:
diff changeset
   119
7f561c08de6b Initial load
duke
parents:
diff changeset
   120
        // Patch for Christine's gripe. She wants her errorHandler to return from
7f561c08de6b Initial load
duke
parents:
diff changeset
   121
        // a fatal error and continue trying to parse, rather than throwing an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   122
        // Without the patch, that put us into an endless loop.
7f561c08de6b Initial load
duke
parents:
diff changeset
   123
        //
7f561c08de6b Initial load
duke
parents:
diff changeset
   124
        // %REVIEW% Is there a better way of doing this?
7f561c08de6b Initial load
duke
parents:
diff changeset
   125
        // %REVIEW% Are there any other cases which need the safety net?
7f561c08de6b Initial load
duke
parents:
diff changeset
   126
        //      (and if so do we care right now, or should we rewrite the XPath
7f561c08de6b Initial load
duke
parents:
diff changeset
   127
        //      grammar engine and can fix it at that time?)
7f561c08de6b Initial load
duke
parents:
diff changeset
   128
        try {
7f561c08de6b Initial load
duke
parents:
diff changeset
   129
7f561c08de6b Initial load
duke
parents:
diff changeset
   130
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   131
      Expr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   132
7f561c08de6b Initial load
duke
parents:
diff changeset
   133
      if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   134
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   135
        String extraTokens = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   136
7f561c08de6b Initial load
duke
parents:
diff changeset
   137
        while (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   138
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   139
          extraTokens += "'" + m_token + "'";
7f561c08de6b Initial load
duke
parents:
diff changeset
   140
7f561c08de6b Initial load
duke
parents:
diff changeset
   141
          nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   142
7f561c08de6b Initial load
duke
parents:
diff changeset
   143
          if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   144
            extraTokens += ", ";
7f561c08de6b Initial load
duke
parents:
diff changeset
   145
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   146
7f561c08de6b Initial load
duke
parents:
diff changeset
   147
        error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   148
              new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
7f561c08de6b Initial load
duke
parents:
diff changeset
   149
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   150
7f561c08de6b Initial load
duke
parents:
diff changeset
   151
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   152
    catch (com.sun.org.apache.xpath.internal.XPathProcessorException e)
7f561c08de6b Initial load
duke
parents:
diff changeset
   153
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   154
          if(CONTINUE_AFTER_FATAL_ERROR.equals(e.getMessage()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   155
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
   156
                // What I _want_ to do is null out this XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   157
                // I doubt this has the desired effect, but I'm not sure what else to do.
7f561c08de6b Initial load
duke
parents:
diff changeset
   158
                // %REVIEW%!!!
7f561c08de6b Initial load
duke
parents:
diff changeset
   159
                initXPath(compiler, "/..",  namespaceContext);
7f561c08de6b Initial load
duke
parents:
diff changeset
   160
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
   161
          else
7f561c08de6b Initial load
duke
parents:
diff changeset
   162
                throw e;
7f561c08de6b Initial load
duke
parents:
diff changeset
   163
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   164
7f561c08de6b Initial load
duke
parents:
diff changeset
   165
    compiler.shrink();
7f561c08de6b Initial load
duke
parents:
diff changeset
   166
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   167
7f561c08de6b Initial load
duke
parents:
diff changeset
   168
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   169
   * Given an string, init an XPath object for pattern matches,
7f561c08de6b Initial load
duke
parents:
diff changeset
   170
   * in order that a parse doesn't
7f561c08de6b Initial load
duke
parents:
diff changeset
   171
   * have to be done each time the expression is evaluated.
7f561c08de6b Initial load
duke
parents:
diff changeset
   172
   * @param compiler The XPath object to be initialized.
7f561c08de6b Initial load
duke
parents:
diff changeset
   173
   * @param expression A String representing the XPath.
7f561c08de6b Initial load
duke
parents:
diff changeset
   174
   * @param namespaceContext An object that is able to resolve prefixes in
7f561c08de6b Initial load
duke
parents:
diff changeset
   175
   * the XPath to namespaces.
7f561c08de6b Initial load
duke
parents:
diff changeset
   176
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   177
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   178
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   179
  public void initMatchPattern(
7f561c08de6b Initial load
duke
parents:
diff changeset
   180
          Compiler compiler, String expression, PrefixResolver namespaceContext)
7f561c08de6b Initial load
duke
parents:
diff changeset
   181
            throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   182
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   183
7f561c08de6b Initial load
duke
parents:
diff changeset
   184
    m_ops = compiler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   185
    m_namespaceContext = namespaceContext;
7f561c08de6b Initial load
duke
parents:
diff changeset
   186
    m_functionTable = compiler.getFunctionTable();
7f561c08de6b Initial load
duke
parents:
diff changeset
   187
7f561c08de6b Initial load
duke
parents:
diff changeset
   188
    Lexer lexer = new Lexer(compiler, namespaceContext, this);
7f561c08de6b Initial load
duke
parents:
diff changeset
   189
7f561c08de6b Initial load
duke
parents:
diff changeset
   190
    lexer.tokenize(expression);
7f561c08de6b Initial load
duke
parents:
diff changeset
   191
7f561c08de6b Initial load
duke
parents:
diff changeset
   192
    m_ops.setOp(0, OpCodes.OP_MATCHPATTERN);
7f561c08de6b Initial load
duke
parents:
diff changeset
   193
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, 2);
7f561c08de6b Initial load
duke
parents:
diff changeset
   194
7f561c08de6b Initial load
duke
parents:
diff changeset
   195
    nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   196
    Pattern();
7f561c08de6b Initial load
duke
parents:
diff changeset
   197
7f561c08de6b Initial load
duke
parents:
diff changeset
   198
    if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   199
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   200
      String extraTokens = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   201
7f561c08de6b Initial load
duke
parents:
diff changeset
   202
      while (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   203
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   204
        extraTokens += "'" + m_token + "'";
7f561c08de6b Initial load
duke
parents:
diff changeset
   205
7f561c08de6b Initial load
duke
parents:
diff changeset
   206
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   207
7f561c08de6b Initial load
duke
parents:
diff changeset
   208
        if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   209
          extraTokens += ", ";
7f561c08de6b Initial load
duke
parents:
diff changeset
   210
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   211
7f561c08de6b Initial load
duke
parents:
diff changeset
   212
      error(XPATHErrorResources.ER_EXTRA_ILLEGAL_TOKENS,
7f561c08de6b Initial load
duke
parents:
diff changeset
   213
            new Object[]{ extraTokens });  //"Extra illegal tokens: "+extraTokens);
7f561c08de6b Initial load
duke
parents:
diff changeset
   214
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   215
7f561c08de6b Initial load
duke
parents:
diff changeset
   216
    // Terminate for safety.
7f561c08de6b Initial load
duke
parents:
diff changeset
   217
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
   218
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH)+1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   219
7f561c08de6b Initial load
duke
parents:
diff changeset
   220
    m_ops.shrink();
7f561c08de6b Initial load
duke
parents:
diff changeset
   221
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   222
7f561c08de6b Initial load
duke
parents:
diff changeset
   223
  /** The error listener where syntax errors are to be sent.
7f561c08de6b Initial load
duke
parents:
diff changeset
   224
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   225
  private ErrorListener m_errorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   226
7f561c08de6b Initial load
duke
parents:
diff changeset
   227
  /** The source location of the XPath. */
7f561c08de6b Initial load
duke
parents:
diff changeset
   228
  javax.xml.transform.SourceLocator m_sourceLocator;
7f561c08de6b Initial load
duke
parents:
diff changeset
   229
7f561c08de6b Initial load
duke
parents:
diff changeset
   230
  /** The table contains build-in functions and customized functions */
7f561c08de6b Initial load
duke
parents:
diff changeset
   231
  private FunctionTable m_functionTable;
7f561c08de6b Initial load
duke
parents:
diff changeset
   232
7f561c08de6b Initial load
duke
parents:
diff changeset
   233
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   234
   * Allow an application to register an error event handler, where syntax
7f561c08de6b Initial load
duke
parents:
diff changeset
   235
   * errors will be sent.  If the error listener is not set, syntax errors
7f561c08de6b Initial load
duke
parents:
diff changeset
   236
   * will be sent to System.err.
7f561c08de6b Initial load
duke
parents:
diff changeset
   237
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   238
   * @param handler Reference to error listener where syntax errors will be
7f561c08de6b Initial load
duke
parents:
diff changeset
   239
   *                sent.
7f561c08de6b Initial load
duke
parents:
diff changeset
   240
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   241
  public void setErrorHandler(ErrorListener handler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   242
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   243
    m_errorListener = handler;
7f561c08de6b Initial load
duke
parents:
diff changeset
   244
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   245
7f561c08de6b Initial load
duke
parents:
diff changeset
   246
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   247
   * Return the current error listener.
7f561c08de6b Initial load
duke
parents:
diff changeset
   248
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   249
   * @return The error listener, which should not normally be null, but may be.
7f561c08de6b Initial load
duke
parents:
diff changeset
   250
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   251
  public ErrorListener getErrorListener()
7f561c08de6b Initial load
duke
parents:
diff changeset
   252
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   253
    return m_errorListener;
7f561c08de6b Initial load
duke
parents:
diff changeset
   254
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   255
7f561c08de6b Initial load
duke
parents:
diff changeset
   256
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   257
   * Check whether m_token matches the target string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   258
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   259
   * @param s A string reference or null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   260
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   261
   * @return If m_token is null, returns false (or true if s is also null), or
7f561c08de6b Initial load
duke
parents:
diff changeset
   262
   * return true if the current token matches the string, else false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   263
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   264
  final boolean tokenIs(String s)
7f561c08de6b Initial load
duke
parents:
diff changeset
   265
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   266
    return (m_token != null) ? (m_token.equals(s)) : (s == null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   267
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   268
7f561c08de6b Initial load
duke
parents:
diff changeset
   269
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   270
   * Check whether m_tokenChar==c.
7f561c08de6b Initial load
duke
parents:
diff changeset
   271
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   272
   * @param c A character to be tested.
7f561c08de6b Initial load
duke
parents:
diff changeset
   273
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   274
   * @return If m_token is null, returns false, or return true if c matches
7f561c08de6b Initial load
duke
parents:
diff changeset
   275
   *         the current token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   276
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   277
  final boolean tokenIs(char c)
7f561c08de6b Initial load
duke
parents:
diff changeset
   278
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   279
    return (m_token != null) ? (m_tokenChar == c) : false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   280
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   281
7f561c08de6b Initial load
duke
parents:
diff changeset
   282
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   283
   * Look ahead of the current token in order to
7f561c08de6b Initial load
duke
parents:
diff changeset
   284
   * make a branching decision.
7f561c08de6b Initial load
duke
parents:
diff changeset
   285
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   286
   * @param c the character to be tested for.
7f561c08de6b Initial load
duke
parents:
diff changeset
   287
   * @param n number of tokens to look ahead.  Must be
7f561c08de6b Initial load
duke
parents:
diff changeset
   288
   * greater than 1.
7f561c08de6b Initial load
duke
parents:
diff changeset
   289
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   290
   * @return true if the next token matches the character argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   291
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   292
  final boolean lookahead(char c, int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   293
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   294
7f561c08de6b Initial load
duke
parents:
diff changeset
   295
    int pos = (m_queueMark + n);
7f561c08de6b Initial load
duke
parents:
diff changeset
   296
    boolean b;
7f561c08de6b Initial load
duke
parents:
diff changeset
   297
7f561c08de6b Initial load
duke
parents:
diff changeset
   298
    if ((pos <= m_ops.getTokenQueueSize()) && (pos > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   299
            && (m_ops.getTokenQueueSize() != 0))
7f561c08de6b Initial load
duke
parents:
diff changeset
   300
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   301
      String tok = ((String) m_ops.m_tokenQueue.elementAt(pos - 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   302
7f561c08de6b Initial load
duke
parents:
diff changeset
   303
      b = (tok.length() == 1) ? (tok.charAt(0) == c) : false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   304
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   305
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   306
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   307
      b = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   308
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   309
7f561c08de6b Initial load
duke
parents:
diff changeset
   310
    return b;
7f561c08de6b Initial load
duke
parents:
diff changeset
   311
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   312
7f561c08de6b Initial load
duke
parents:
diff changeset
   313
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   314
   * Look behind the first character of the current token in order to
7f561c08de6b Initial load
duke
parents:
diff changeset
   315
   * make a branching decision.
7f561c08de6b Initial load
duke
parents:
diff changeset
   316
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   317
   * @param c the character to compare it to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   318
   * @param n number of tokens to look behind.  Must be
7f561c08de6b Initial load
duke
parents:
diff changeset
   319
   * greater than 1.  Note that the look behind terminates
7f561c08de6b Initial load
duke
parents:
diff changeset
   320
   * at either the beginning of the string or on a '|'
7f561c08de6b Initial load
duke
parents:
diff changeset
   321
   * character.  Because of this, this method should only
7f561c08de6b Initial load
duke
parents:
diff changeset
   322
   * be used for pattern matching.
7f561c08de6b Initial load
duke
parents:
diff changeset
   323
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   324
   * @return true if the token behind the current token matches the character
7f561c08de6b Initial load
duke
parents:
diff changeset
   325
   *         argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   326
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   327
  private final boolean lookbehind(char c, int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   328
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   329
7f561c08de6b Initial load
duke
parents:
diff changeset
   330
    boolean isToken;
7f561c08de6b Initial load
duke
parents:
diff changeset
   331
    int lookBehindPos = m_queueMark - (n + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   332
7f561c08de6b Initial load
duke
parents:
diff changeset
   333
    if (lookBehindPos >= 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   334
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   335
      String lookbehind = (String) m_ops.m_tokenQueue.elementAt(lookBehindPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   336
7f561c08de6b Initial load
duke
parents:
diff changeset
   337
      if (lookbehind.length() == 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
   338
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   339
        char c0 = (lookbehind == null) ? '|' : lookbehind.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   340
7f561c08de6b Initial load
duke
parents:
diff changeset
   341
        isToken = (c0 == '|') ? false : (c0 == c);
7f561c08de6b Initial load
duke
parents:
diff changeset
   342
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   343
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
   344
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   345
        isToken = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   346
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   347
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   348
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   349
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   350
      isToken = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   351
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   352
7f561c08de6b Initial load
duke
parents:
diff changeset
   353
    return isToken;
7f561c08de6b Initial load
duke
parents:
diff changeset
   354
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   355
7f561c08de6b Initial load
duke
parents:
diff changeset
   356
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   357
   * look behind the current token in order to
7f561c08de6b Initial load
duke
parents:
diff changeset
   358
   * see if there is a useable token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   359
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   360
   * @param n number of tokens to look behind.  Must be
7f561c08de6b Initial load
duke
parents:
diff changeset
   361
   * greater than 1.  Note that the look behind terminates
7f561c08de6b Initial load
duke
parents:
diff changeset
   362
   * at either the beginning of the string or on a '|'
7f561c08de6b Initial load
duke
parents:
diff changeset
   363
   * character.  Because of this, this method should only
7f561c08de6b Initial load
duke
parents:
diff changeset
   364
   * be used for pattern matching.
7f561c08de6b Initial load
duke
parents:
diff changeset
   365
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   366
   * @return true if look behind has a token, false otherwise.
7f561c08de6b Initial load
duke
parents:
diff changeset
   367
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   368
  private final boolean lookbehindHasToken(int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   369
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   370
7f561c08de6b Initial load
duke
parents:
diff changeset
   371
    boolean hasToken;
7f561c08de6b Initial load
duke
parents:
diff changeset
   372
7f561c08de6b Initial load
duke
parents:
diff changeset
   373
    if ((m_queueMark - n) > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   374
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   375
      String lookbehind = (String) m_ops.m_tokenQueue.elementAt(m_queueMark - (n - 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   376
      char c0 = (lookbehind == null) ? '|' : lookbehind.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   377
7f561c08de6b Initial load
duke
parents:
diff changeset
   378
      hasToken = (c0 == '|') ? false : true;
7f561c08de6b Initial load
duke
parents:
diff changeset
   379
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   380
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   381
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   382
      hasToken = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
   383
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   384
7f561c08de6b Initial load
duke
parents:
diff changeset
   385
    return hasToken;
7f561c08de6b Initial load
duke
parents:
diff changeset
   386
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   387
7f561c08de6b Initial load
duke
parents:
diff changeset
   388
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   389
   * Look ahead of the current token in order to
7f561c08de6b Initial load
duke
parents:
diff changeset
   390
   * make a branching decision.
7f561c08de6b Initial load
duke
parents:
diff changeset
   391
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   392
   * @param s the string to compare it to.
7f561c08de6b Initial load
duke
parents:
diff changeset
   393
   * @param n number of tokens to lookahead.  Must be
7f561c08de6b Initial load
duke
parents:
diff changeset
   394
   * greater than 1.
7f561c08de6b Initial load
duke
parents:
diff changeset
   395
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   396
   * @return true if the token behind the current token matches the string
7f561c08de6b Initial load
duke
parents:
diff changeset
   397
   *         argument.
7f561c08de6b Initial load
duke
parents:
diff changeset
   398
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   399
  private final boolean lookahead(String s, int n)
7f561c08de6b Initial load
duke
parents:
diff changeset
   400
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   401
7f561c08de6b Initial load
duke
parents:
diff changeset
   402
    boolean isToken;
7f561c08de6b Initial load
duke
parents:
diff changeset
   403
7f561c08de6b Initial load
duke
parents:
diff changeset
   404
    if ((m_queueMark + n) <= m_ops.getTokenQueueSize())
7f561c08de6b Initial load
duke
parents:
diff changeset
   405
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   406
      String lookahead = (String) m_ops.m_tokenQueue.elementAt(m_queueMark + (n - 1));
7f561c08de6b Initial load
duke
parents:
diff changeset
   407
7f561c08de6b Initial load
duke
parents:
diff changeset
   408
      isToken = (lookahead != null) ? lookahead.equals(s) : (s == null);
7f561c08de6b Initial load
duke
parents:
diff changeset
   409
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   410
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   411
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   412
      isToken = (null == s);
7f561c08de6b Initial load
duke
parents:
diff changeset
   413
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   414
7f561c08de6b Initial load
duke
parents:
diff changeset
   415
    return isToken;
7f561c08de6b Initial load
duke
parents:
diff changeset
   416
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   417
7f561c08de6b Initial load
duke
parents:
diff changeset
   418
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   419
   * Retrieve the next token from the command and
7f561c08de6b Initial load
duke
parents:
diff changeset
   420
   * store it in m_token string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   421
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   422
  private final void nextToken()
7f561c08de6b Initial load
duke
parents:
diff changeset
   423
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   424
7f561c08de6b Initial load
duke
parents:
diff changeset
   425
    if (m_queueMark < m_ops.getTokenQueueSize())
7f561c08de6b Initial load
duke
parents:
diff changeset
   426
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   427
      m_token = (String) m_ops.m_tokenQueue.elementAt(m_queueMark++);
7f561c08de6b Initial load
duke
parents:
diff changeset
   428
      m_tokenChar = m_token.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   429
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   430
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   431
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   432
      m_token = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   433
      m_tokenChar = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   434
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   435
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   436
7f561c08de6b Initial load
duke
parents:
diff changeset
   437
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   438
   * Retrieve a token relative to the current token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   439
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   440
   * @param i Position relative to current token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   441
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   442
   * @return The string at the given index, or null if the index is out
7f561c08de6b Initial load
duke
parents:
diff changeset
   443
   *         of range.
7f561c08de6b Initial load
duke
parents:
diff changeset
   444
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   445
  private final String getTokenRelative(int i)
7f561c08de6b Initial load
duke
parents:
diff changeset
   446
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   447
7f561c08de6b Initial load
duke
parents:
diff changeset
   448
    String tok;
7f561c08de6b Initial load
duke
parents:
diff changeset
   449
    int relative = m_queueMark + i;
7f561c08de6b Initial load
duke
parents:
diff changeset
   450
7f561c08de6b Initial load
duke
parents:
diff changeset
   451
    if ((relative > 0) && (relative < m_ops.getTokenQueueSize()))
7f561c08de6b Initial load
duke
parents:
diff changeset
   452
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   453
      tok = (String) m_ops.m_tokenQueue.elementAt(relative);
7f561c08de6b Initial load
duke
parents:
diff changeset
   454
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   455
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   456
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   457
      tok = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   458
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   459
7f561c08de6b Initial load
duke
parents:
diff changeset
   460
    return tok;
7f561c08de6b Initial load
duke
parents:
diff changeset
   461
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   462
7f561c08de6b Initial load
duke
parents:
diff changeset
   463
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   464
   * Retrieve the previous token from the command and
7f561c08de6b Initial load
duke
parents:
diff changeset
   465
   * store it in m_token string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   466
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   467
  private final void prevToken()
7f561c08de6b Initial load
duke
parents:
diff changeset
   468
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   469
7f561c08de6b Initial load
duke
parents:
diff changeset
   470
    if (m_queueMark > 0)
7f561c08de6b Initial load
duke
parents:
diff changeset
   471
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   472
      m_queueMark--;
7f561c08de6b Initial load
duke
parents:
diff changeset
   473
7f561c08de6b Initial load
duke
parents:
diff changeset
   474
      m_token = (String) m_ops.m_tokenQueue.elementAt(m_queueMark);
7f561c08de6b Initial load
duke
parents:
diff changeset
   475
      m_tokenChar = m_token.charAt(0);
7f561c08de6b Initial load
duke
parents:
diff changeset
   476
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   477
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   478
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   479
      m_token = null;
7f561c08de6b Initial load
duke
parents:
diff changeset
   480
      m_tokenChar = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
   481
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   482
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   483
7f561c08de6b Initial load
duke
parents:
diff changeset
   484
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   485
   * Consume an expected token, throwing an exception if it
7f561c08de6b Initial load
duke
parents:
diff changeset
   486
   * isn't there.
7f561c08de6b Initial load
duke
parents:
diff changeset
   487
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   488
   * @param expected The string to be expected.
7f561c08de6b Initial load
duke
parents:
diff changeset
   489
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   490
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   491
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   492
  private final void consumeExpected(String expected)
7f561c08de6b Initial load
duke
parents:
diff changeset
   493
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   494
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   495
7f561c08de6b Initial load
duke
parents:
diff changeset
   496
    if (tokenIs(expected))
7f561c08de6b Initial load
duke
parents:
diff changeset
   497
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   498
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   499
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   500
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   501
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   502
      error(XPATHErrorResources.ER_EXPECTED_BUT_FOUND, new Object[]{ expected,
7f561c08de6b Initial load
duke
parents:
diff changeset
   503
                                                                     m_token });  //"Expected "+expected+", but found: "+m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
   504
7f561c08de6b Initial load
duke
parents:
diff changeset
   505
          // Patch for Christina's gripe. She wants her errorHandler to return from
7f561c08de6b Initial load
duke
parents:
diff changeset
   506
          // this error and continue trying to parse, rather than throwing an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   507
          // Without the patch, that put us into an endless loop.
7f561c08de6b Initial load
duke
parents:
diff changeset
   508
                throw new XPathProcessorException(CONTINUE_AFTER_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   509
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   510
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   511
7f561c08de6b Initial load
duke
parents:
diff changeset
   512
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   513
   * Consume an expected token, throwing an exception if it
7f561c08de6b Initial load
duke
parents:
diff changeset
   514
   * isn't there.
7f561c08de6b Initial load
duke
parents:
diff changeset
   515
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   516
   * @param expected the character to be expected.
7f561c08de6b Initial load
duke
parents:
diff changeset
   517
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   518
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   519
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   520
  private final void consumeExpected(char expected)
7f561c08de6b Initial load
duke
parents:
diff changeset
   521
          throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   522
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   523
7f561c08de6b Initial load
duke
parents:
diff changeset
   524
    if (tokenIs(expected))
7f561c08de6b Initial load
duke
parents:
diff changeset
   525
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   526
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   527
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   528
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   529
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   530
      error(XPATHErrorResources.ER_EXPECTED_BUT_FOUND,
7f561c08de6b Initial load
duke
parents:
diff changeset
   531
            new Object[]{ String.valueOf(expected),
7f561c08de6b Initial load
duke
parents:
diff changeset
   532
                          m_token });  //"Expected "+expected+", but found: "+m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
   533
7f561c08de6b Initial load
duke
parents:
diff changeset
   534
          // Patch for Christina's gripe. She wants her errorHandler to return from
7f561c08de6b Initial load
duke
parents:
diff changeset
   535
          // this error and continue trying to parse, rather than throwing an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   536
          // Without the patch, that put us into an endless loop.
7f561c08de6b Initial load
duke
parents:
diff changeset
   537
                throw new XPathProcessorException(CONTINUE_AFTER_FATAL_ERROR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   538
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   539
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   540
7f561c08de6b Initial load
duke
parents:
diff changeset
   541
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   542
   * Warn the user of a problem.
7f561c08de6b Initial load
duke
parents:
diff changeset
   543
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   544
   * @param msg An error msgkey that corresponds to one of the constants found
7f561c08de6b Initial load
duke
parents:
diff changeset
   545
   *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
7f561c08de6b Initial load
duke
parents:
diff changeset
   546
   *            a key for a format string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   547
   * @param args An array of arguments represented in the format string, which
7f561c08de6b Initial load
duke
parents:
diff changeset
   548
   *             may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   549
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   550
   * @throws TransformerException if the current ErrorListoner determines to
7f561c08de6b Initial load
duke
parents:
diff changeset
   551
   *                              throw an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   552
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   553
  void warn(String msg, Object[] args) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   554
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   555
7f561c08de6b Initial load
duke
parents:
diff changeset
   556
    String fmsg = XSLMessages.createXPATHWarning(msg, args);
7f561c08de6b Initial load
duke
parents:
diff changeset
   557
    ErrorListener ehandler = this.getErrorListener();
7f561c08de6b Initial load
duke
parents:
diff changeset
   558
7f561c08de6b Initial load
duke
parents:
diff changeset
   559
    if (null != ehandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   560
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   561
      // TO DO: Need to get stylesheet Locator from here.
7f561c08de6b Initial load
duke
parents:
diff changeset
   562
      ehandler.warning(new TransformerException(fmsg, m_sourceLocator));
7f561c08de6b Initial load
duke
parents:
diff changeset
   563
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   564
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   565
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   566
      // Should never happen.
7f561c08de6b Initial load
duke
parents:
diff changeset
   567
      System.err.println(fmsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   568
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   569
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   570
7f561c08de6b Initial load
duke
parents:
diff changeset
   571
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   572
   * Notify the user of an assertion error, and probably throw an
7f561c08de6b Initial load
duke
parents:
diff changeset
   573
   * exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   574
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   575
   * @param b  If false, a runtime exception will be thrown.
7f561c08de6b Initial load
duke
parents:
diff changeset
   576
   * @param msg The assertion message, which should be informative.
7f561c08de6b Initial load
duke
parents:
diff changeset
   577
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   578
   * @throws RuntimeException if the b argument is false.
7f561c08de6b Initial load
duke
parents:
diff changeset
   579
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   580
  private void assertion(boolean b, String msg)
7f561c08de6b Initial load
duke
parents:
diff changeset
   581
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   582
7f561c08de6b Initial load
duke
parents:
diff changeset
   583
    if (!b)
7f561c08de6b Initial load
duke
parents:
diff changeset
   584
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   585
      String fMsg = XSLMessages.createXPATHMessage(
7f561c08de6b Initial load
duke
parents:
diff changeset
   586
        XPATHErrorResources.ER_INCORRECT_PROGRAMMER_ASSERTION,
7f561c08de6b Initial load
duke
parents:
diff changeset
   587
        new Object[]{ msg });
7f561c08de6b Initial load
duke
parents:
diff changeset
   588
7f561c08de6b Initial load
duke
parents:
diff changeset
   589
      throw new RuntimeException(fMsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   590
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   591
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   592
7f561c08de6b Initial load
duke
parents:
diff changeset
   593
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   594
   * Notify the user of an error, and probably throw an
7f561c08de6b Initial load
duke
parents:
diff changeset
   595
   * exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   596
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   597
   * @param msg An error msgkey that corresponds to one of the constants found
7f561c08de6b Initial load
duke
parents:
diff changeset
   598
   *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
7f561c08de6b Initial load
duke
parents:
diff changeset
   599
   *            a key for a format string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   600
   * @param args An array of arguments represented in the format string, which
7f561c08de6b Initial load
duke
parents:
diff changeset
   601
   *             may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   602
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   603
   * @throws TransformerException if the current ErrorListoner determines to
7f561c08de6b Initial load
duke
parents:
diff changeset
   604
   *                              throw an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   605
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   606
  void error(String msg, Object[] args) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   607
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   608
7f561c08de6b Initial load
duke
parents:
diff changeset
   609
    String fmsg = XSLMessages.createXPATHMessage(msg, args);
7f561c08de6b Initial load
duke
parents:
diff changeset
   610
    ErrorListener ehandler = this.getErrorListener();
7f561c08de6b Initial load
duke
parents:
diff changeset
   611
7f561c08de6b Initial load
duke
parents:
diff changeset
   612
    TransformerException te = new TransformerException(fmsg, m_sourceLocator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   613
    if (null != ehandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   614
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   615
      // TO DO: Need to get stylesheet Locator from here.
7f561c08de6b Initial load
duke
parents:
diff changeset
   616
      ehandler.fatalError(te);
7f561c08de6b Initial load
duke
parents:
diff changeset
   617
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   618
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   619
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   620
      // System.err.println(fmsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   621
      throw te;
7f561c08de6b Initial load
duke
parents:
diff changeset
   622
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   623
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   624
7f561c08de6b Initial load
duke
parents:
diff changeset
   625
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   626
   * This method is added to support DOM 3 XPath API.
7f561c08de6b Initial load
duke
parents:
diff changeset
   627
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   628
   * This method is exactly like error(String, Object[]); except that
7f561c08de6b Initial load
duke
parents:
diff changeset
   629
   * the underlying TransformerException is
7f561c08de6b Initial load
duke
parents:
diff changeset
   630
   * XpathStylesheetDOM3Exception (which extends TransformerException).
7f561c08de6b Initial load
duke
parents:
diff changeset
   631
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   632
   * So older XPath code in Xalan is not affected by this. To older XPath code
7f561c08de6b Initial load
duke
parents:
diff changeset
   633
   * the behavior of whether error() or errorForDOM3() is called because it is
7f561c08de6b Initial load
duke
parents:
diff changeset
   634
   * always catching TransformerException objects and is oblivious to
7f561c08de6b Initial load
duke
parents:
diff changeset
   635
   * the new subclass of XPathStylesheetDOM3Exception. Older XPath code
7f561c08de6b Initial load
duke
parents:
diff changeset
   636
   * runs as before.
7f561c08de6b Initial load
duke
parents:
diff changeset
   637
   * <p>
7f561c08de6b Initial load
duke
parents:
diff changeset
   638
   * However, newer DOM3 XPath code upon catching a TransformerException can
7f561c08de6b Initial load
duke
parents:
diff changeset
   639
   * can check if the exception is an instance of XPathStylesheetDOM3Exception
7f561c08de6b Initial load
duke
parents:
diff changeset
   640
   * and take appropriate action.
7f561c08de6b Initial load
duke
parents:
diff changeset
   641
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   642
   * @param msg An error msgkey that corresponds to one of the constants found
7f561c08de6b Initial load
duke
parents:
diff changeset
   643
   *            in {@link com.sun.org.apache.xpath.internal.res.XPATHErrorResources}, which is
7f561c08de6b Initial load
duke
parents:
diff changeset
   644
   *            a key for a format string.
7f561c08de6b Initial load
duke
parents:
diff changeset
   645
   * @param args An array of arguments represented in the format string, which
7f561c08de6b Initial load
duke
parents:
diff changeset
   646
   *             may be null.
7f561c08de6b Initial load
duke
parents:
diff changeset
   647
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   648
   * @throws TransformerException if the current ErrorListoner determines to
7f561c08de6b Initial load
duke
parents:
diff changeset
   649
   *                              throw an exception.
7f561c08de6b Initial load
duke
parents:
diff changeset
   650
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   651
  void errorForDOM3(String msg, Object[] args) throws TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   652
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   653
7f561c08de6b Initial load
duke
parents:
diff changeset
   654
        String fmsg = XSLMessages.createXPATHMessage(msg, args);
7f561c08de6b Initial load
duke
parents:
diff changeset
   655
        ErrorListener ehandler = this.getErrorListener();
7f561c08de6b Initial load
duke
parents:
diff changeset
   656
7f561c08de6b Initial load
duke
parents:
diff changeset
   657
        TransformerException te = new XPathStylesheetDOM3Exception(fmsg, m_sourceLocator);
7f561c08de6b Initial load
duke
parents:
diff changeset
   658
        if (null != ehandler)
7f561c08de6b Initial load
duke
parents:
diff changeset
   659
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   660
          // TO DO: Need to get stylesheet Locator from here.
7f561c08de6b Initial load
duke
parents:
diff changeset
   661
          ehandler.fatalError(te);
7f561c08de6b Initial load
duke
parents:
diff changeset
   662
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   663
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   664
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   665
          // System.err.println(fmsg);
7f561c08de6b Initial load
duke
parents:
diff changeset
   666
          throw te;
7f561c08de6b Initial load
duke
parents:
diff changeset
   667
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   668
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   669
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   670
   * Dump the remaining token queue.
7f561c08de6b Initial load
duke
parents:
diff changeset
   671
   * Thanks to Craig for this.
7f561c08de6b Initial load
duke
parents:
diff changeset
   672
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   673
   * @return A dump of the remaining token queue, which may be appended to
7f561c08de6b Initial load
duke
parents:
diff changeset
   674
   *         an error message.
7f561c08de6b Initial load
duke
parents:
diff changeset
   675
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   676
  protected String dumpRemainingTokenQueue()
7f561c08de6b Initial load
duke
parents:
diff changeset
   677
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   678
7f561c08de6b Initial load
duke
parents:
diff changeset
   679
    int q = m_queueMark;
7f561c08de6b Initial load
duke
parents:
diff changeset
   680
    String returnMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
   681
7f561c08de6b Initial load
duke
parents:
diff changeset
   682
    if (q < m_ops.getTokenQueueSize())
7f561c08de6b Initial load
duke
parents:
diff changeset
   683
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   684
      String msg = "\n Remaining tokens: (";
7f561c08de6b Initial load
duke
parents:
diff changeset
   685
7f561c08de6b Initial load
duke
parents:
diff changeset
   686
      while (q < m_ops.getTokenQueueSize())
7f561c08de6b Initial load
duke
parents:
diff changeset
   687
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   688
        String t = (String) m_ops.m_tokenQueue.elementAt(q++);
7f561c08de6b Initial load
duke
parents:
diff changeset
   689
7f561c08de6b Initial load
duke
parents:
diff changeset
   690
        msg += (" '" + t + "'");
7f561c08de6b Initial load
duke
parents:
diff changeset
   691
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   692
7f561c08de6b Initial load
duke
parents:
diff changeset
   693
      returnMsg = msg + ")";
7f561c08de6b Initial load
duke
parents:
diff changeset
   694
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   695
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
   696
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   697
      returnMsg = "";
7f561c08de6b Initial load
duke
parents:
diff changeset
   698
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   699
7f561c08de6b Initial load
duke
parents:
diff changeset
   700
    return returnMsg;
7f561c08de6b Initial load
duke
parents:
diff changeset
   701
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   702
7f561c08de6b Initial load
duke
parents:
diff changeset
   703
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   704
   * Given a string, return the corresponding function token.
7f561c08de6b Initial load
duke
parents:
diff changeset
   705
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   706
   * @param key A local name of a function.
7f561c08de6b Initial load
duke
parents:
diff changeset
   707
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   708
   * @return   The function ID, which may correspond to one of the FUNC_XXX
7f561c08de6b Initial load
duke
parents:
diff changeset
   709
   *    values found in {@link com.sun.org.apache.xpath.internal.compiler.FunctionTable}, but may
7f561c08de6b Initial load
duke
parents:
diff changeset
   710
   *    be a value installed by an external module.
7f561c08de6b Initial load
duke
parents:
diff changeset
   711
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   712
  final int getFunctionToken(String key)
7f561c08de6b Initial load
duke
parents:
diff changeset
   713
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   714
7f561c08de6b Initial load
duke
parents:
diff changeset
   715
    int tok;
7f561c08de6b Initial load
duke
parents:
diff changeset
   716
7f561c08de6b Initial load
duke
parents:
diff changeset
   717
    Object id;
7f561c08de6b Initial load
duke
parents:
diff changeset
   718
7f561c08de6b Initial load
duke
parents:
diff changeset
   719
    try
7f561c08de6b Initial load
duke
parents:
diff changeset
   720
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   721
      // These are nodetests, xpathparser treats them as functions when parsing
7f561c08de6b Initial load
duke
parents:
diff changeset
   722
      // a FilterExpr.
7f561c08de6b Initial load
duke
parents:
diff changeset
   723
      id = Keywords.lookupNodeTest(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   724
      if (null == id) id = m_functionTable.getFunctionID(key);
7f561c08de6b Initial load
duke
parents:
diff changeset
   725
      tok = ((Integer) id).intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
   726
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   727
    catch (NullPointerException npe)
7f561c08de6b Initial load
duke
parents:
diff changeset
   728
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   729
      tok = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   730
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   731
    catch (ClassCastException cce)
7f561c08de6b Initial load
duke
parents:
diff changeset
   732
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   733
      tok = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
   734
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   735
7f561c08de6b Initial load
duke
parents:
diff changeset
   736
    return tok;
7f561c08de6b Initial load
duke
parents:
diff changeset
   737
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   738
7f561c08de6b Initial load
duke
parents:
diff changeset
   739
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   740
   * Insert room for operation.  This will NOT set
7f561c08de6b Initial load
duke
parents:
diff changeset
   741
   * the length value of the operation, but will update
7f561c08de6b Initial load
duke
parents:
diff changeset
   742
   * the length value for the total expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   743
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   744
   * @param pos The position where the op is to be inserted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   745
   * @param length The length of the operation space in the op map.
7f561c08de6b Initial load
duke
parents:
diff changeset
   746
   * @param op The op code to the inserted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   747
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   748
  void insertOp(int pos, int length, int op)
7f561c08de6b Initial load
duke
parents:
diff changeset
   749
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   750
7f561c08de6b Initial load
duke
parents:
diff changeset
   751
    int totalLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   752
7f561c08de6b Initial load
duke
parents:
diff changeset
   753
    for (int i = totalLen - 1; i >= pos; i--)
7f561c08de6b Initial load
duke
parents:
diff changeset
   754
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   755
      m_ops.setOp(i + length, m_ops.getOp(i));
7f561c08de6b Initial load
duke
parents:
diff changeset
   756
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   757
7f561c08de6b Initial load
duke
parents:
diff changeset
   758
    m_ops.setOp(pos,op);
7f561c08de6b Initial load
duke
parents:
diff changeset
   759
    m_ops.setOp(OpMap.MAPINDEX_LENGTH,totalLen + length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   760
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   761
7f561c08de6b Initial load
duke
parents:
diff changeset
   762
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   763
   * Insert room for operation.  This WILL set
7f561c08de6b Initial load
duke
parents:
diff changeset
   764
   * the length value of the operation, and will update
7f561c08de6b Initial load
duke
parents:
diff changeset
   765
   * the length value for the total expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   766
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   767
   * @param length The length of the operation.
7f561c08de6b Initial load
duke
parents:
diff changeset
   768
   * @param op The op code to the inserted.
7f561c08de6b Initial load
duke
parents:
diff changeset
   769
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   770
  void appendOp(int length, int op)
7f561c08de6b Initial load
duke
parents:
diff changeset
   771
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   772
7f561c08de6b Initial load
duke
parents:
diff changeset
   773
    int totalLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   774
7f561c08de6b Initial load
duke
parents:
diff changeset
   775
    m_ops.setOp(totalLen, op);
7f561c08de6b Initial load
duke
parents:
diff changeset
   776
    m_ops.setOp(totalLen + OpMap.MAPINDEX_LENGTH, length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   777
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, totalLen + length);
7f561c08de6b Initial load
duke
parents:
diff changeset
   778
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   779
7f561c08de6b Initial load
duke
parents:
diff changeset
   780
  // ============= EXPRESSIONS FUNCTIONS =================
7f561c08de6b Initial load
duke
parents:
diff changeset
   781
7f561c08de6b Initial load
duke
parents:
diff changeset
   782
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   783
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   784
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   785
   * Expr  ::=  OrExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   786
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   787
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   788
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   789
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   790
  protected void Expr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   791
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   792
    OrExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   793
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   794
7f561c08de6b Initial load
duke
parents:
diff changeset
   795
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   796
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   797
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   798
   * OrExpr  ::=  AndExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   799
   * | OrExpr 'or' AndExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   800
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   801
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   802
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   803
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   804
  protected void OrExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   805
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   806
7f561c08de6b Initial load
duke
parents:
diff changeset
   807
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   808
7f561c08de6b Initial load
duke
parents:
diff changeset
   809
    AndExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   810
7f561c08de6b Initial load
duke
parents:
diff changeset
   811
    if ((null != m_token) && tokenIs("or"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   812
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   813
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   814
      insertOp(opPos, 2, OpCodes.OP_OR);
7f561c08de6b Initial load
duke
parents:
diff changeset
   815
      OrExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   816
7f561c08de6b Initial load
duke
parents:
diff changeset
   817
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
   818
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   819
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   820
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   821
7f561c08de6b Initial load
duke
parents:
diff changeset
   822
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   823
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   824
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   825
   * AndExpr  ::=  EqualityExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   826
   * | AndExpr 'and' EqualityExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   827
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   828
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   829
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   830
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   831
  protected void AndExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   832
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   833
7f561c08de6b Initial load
duke
parents:
diff changeset
   834
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   835
7f561c08de6b Initial load
duke
parents:
diff changeset
   836
    EqualityExpr(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   837
7f561c08de6b Initial load
duke
parents:
diff changeset
   838
    if ((null != m_token) && tokenIs("and"))
7f561c08de6b Initial load
duke
parents:
diff changeset
   839
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   840
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   841
      insertOp(opPos, 2, OpCodes.OP_AND);
7f561c08de6b Initial load
duke
parents:
diff changeset
   842
      AndExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
   843
7f561c08de6b Initial load
duke
parents:
diff changeset
   844
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
   845
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   846
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   847
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   848
7f561c08de6b Initial load
duke
parents:
diff changeset
   849
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   850
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   851
   * @returns an Object which is either a String, a Number, a Boolean, or a vector
7f561c08de6b Initial load
duke
parents:
diff changeset
   852
   * of nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   853
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   854
   * EqualityExpr  ::=  RelationalExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   855
   * | EqualityExpr '=' RelationalExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   856
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   857
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   858
   * @param addPos Position where expression is to be added, or -1 for append.
7f561c08de6b Initial load
duke
parents:
diff changeset
   859
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   860
   * @return the position at the end of the equality expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   861
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   862
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   863
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   864
  protected int EqualityExpr(int addPos) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   865
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   866
7f561c08de6b Initial load
duke
parents:
diff changeset
   867
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   868
7f561c08de6b Initial load
duke
parents:
diff changeset
   869
    if (-1 == addPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   870
      addPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   871
7f561c08de6b Initial load
duke
parents:
diff changeset
   872
    RelationalExpr(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   873
7f561c08de6b Initial load
duke
parents:
diff changeset
   874
    if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   875
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   876
      if (tokenIs('!') && lookahead('=', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
   877
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   878
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   879
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   880
        insertOp(addPos, 2, OpCodes.OP_NOTEQUALS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   881
7f561c08de6b Initial load
duke
parents:
diff changeset
   882
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   883
7f561c08de6b Initial load
duke
parents:
diff changeset
   884
        addPos = EqualityExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   885
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
   886
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   887
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   888
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   889
      else if (tokenIs('='))
7f561c08de6b Initial load
duke
parents:
diff changeset
   890
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   891
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   892
        insertOp(addPos, 2, OpCodes.OP_EQUALS);
7f561c08de6b Initial load
duke
parents:
diff changeset
   893
7f561c08de6b Initial load
duke
parents:
diff changeset
   894
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   895
7f561c08de6b Initial load
duke
parents:
diff changeset
   896
        addPos = EqualityExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   897
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
   898
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   899
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   900
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   901
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   902
7f561c08de6b Initial load
duke
parents:
diff changeset
   903
    return addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   904
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   905
7f561c08de6b Initial load
duke
parents:
diff changeset
   906
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   907
   * .
7f561c08de6b Initial load
duke
parents:
diff changeset
   908
   * @returns an Object which is either a String, a Number, a Boolean, or a vector
7f561c08de6b Initial load
duke
parents:
diff changeset
   909
   * of nodes.
7f561c08de6b Initial load
duke
parents:
diff changeset
   910
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   911
   * RelationalExpr  ::=  AdditiveExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   912
   * | RelationalExpr '<' AdditiveExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   913
   * | RelationalExpr '>' AdditiveExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   914
   * | RelationalExpr '<=' AdditiveExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   915
   * | RelationalExpr '>=' AdditiveExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   916
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   917
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   918
   * @param addPos Position where expression is to be added, or -1 for append.
7f561c08de6b Initial load
duke
parents:
diff changeset
   919
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   920
   * @return the position at the end of the relational expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   921
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   922
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   923
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   924
  protected int RelationalExpr(int addPos) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   925
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
   926
7f561c08de6b Initial load
duke
parents:
diff changeset
   927
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
   928
7f561c08de6b Initial load
duke
parents:
diff changeset
   929
    if (-1 == addPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
   930
      addPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   931
7f561c08de6b Initial load
duke
parents:
diff changeset
   932
    AdditiveExpr(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
   933
7f561c08de6b Initial load
duke
parents:
diff changeset
   934
    if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
   935
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
   936
      if (tokenIs('<'))
7f561c08de6b Initial load
duke
parents:
diff changeset
   937
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   938
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   939
7f561c08de6b Initial load
duke
parents:
diff changeset
   940
        if (tokenIs('='))
7f561c08de6b Initial load
duke
parents:
diff changeset
   941
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   942
          nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   943
          insertOp(addPos, 2, OpCodes.OP_LTE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   944
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   945
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   946
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   947
          insertOp(addPos, 2, OpCodes.OP_LT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   948
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   949
7f561c08de6b Initial load
duke
parents:
diff changeset
   950
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   951
7f561c08de6b Initial load
duke
parents:
diff changeset
   952
        addPos = RelationalExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   953
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
   954
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   955
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   956
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   957
      else if (tokenIs('>'))
7f561c08de6b Initial load
duke
parents:
diff changeset
   958
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
   959
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   960
7f561c08de6b Initial load
duke
parents:
diff changeset
   961
        if (tokenIs('='))
7f561c08de6b Initial load
duke
parents:
diff changeset
   962
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   963
          nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
   964
          insertOp(addPos, 2, OpCodes.OP_GTE);
7f561c08de6b Initial load
duke
parents:
diff changeset
   965
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   966
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
   967
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
   968
          insertOp(addPos, 2, OpCodes.OP_GT);
7f561c08de6b Initial load
duke
parents:
diff changeset
   969
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
   970
7f561c08de6b Initial load
duke
parents:
diff changeset
   971
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   972
7f561c08de6b Initial load
duke
parents:
diff changeset
   973
        addPos = RelationalExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
   974
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
   975
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
   976
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
   977
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
   978
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
   979
7f561c08de6b Initial load
duke
parents:
diff changeset
   980
    return addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
   981
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
   982
7f561c08de6b Initial load
duke
parents:
diff changeset
   983
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
   984
   * This has to handle construction of the operations so that they are evaluated
7f561c08de6b Initial load
duke
parents:
diff changeset
   985
   * in pre-fix order.  So, for 9+7-6, instead of |+|9|-|7|6|, this needs to be
7f561c08de6b Initial load
duke
parents:
diff changeset
   986
   * evaluated as |-|+|9|7|6|.
7f561c08de6b Initial load
duke
parents:
diff changeset
   987
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   988
   * AdditiveExpr  ::=  MultiplicativeExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   989
   * | AdditiveExpr '+' MultiplicativeExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   990
   * | AdditiveExpr '-' MultiplicativeExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
   991
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   992
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   993
   * @param addPos Position where expression is to be added, or -1 for append.
7f561c08de6b Initial load
duke
parents:
diff changeset
   994
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   995
   * @return the position at the end of the equality expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
   996
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
   997
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
   998
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
   999
  protected int AdditiveExpr(int addPos) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1000
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1001
7f561c08de6b Initial load
duke
parents:
diff changeset
  1002
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1003
7f561c08de6b Initial load
duke
parents:
diff changeset
  1004
    if (-1 == addPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1005
      addPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1006
7f561c08de6b Initial load
duke
parents:
diff changeset
  1007
    MultiplicativeExpr(-1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1008
7f561c08de6b Initial load
duke
parents:
diff changeset
  1009
    if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1010
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1011
      if (tokenIs('+'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1012
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1013
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1014
        insertOp(addPos, 2, OpCodes.OP_PLUS);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1015
7f561c08de6b Initial load
duke
parents:
diff changeset
  1016
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1017
7f561c08de6b Initial load
duke
parents:
diff changeset
  1018
        addPos = AdditiveExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1019
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1020
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1021
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1022
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1023
      else if (tokenIs('-'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1024
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1025
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1026
        insertOp(addPos, 2, OpCodes.OP_MINUS);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1027
7f561c08de6b Initial load
duke
parents:
diff changeset
  1028
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1029
7f561c08de6b Initial load
duke
parents:
diff changeset
  1030
        addPos = AdditiveExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1031
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1032
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1033
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1034
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1035
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1036
7f561c08de6b Initial load
duke
parents:
diff changeset
  1037
    return addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1038
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1039
7f561c08de6b Initial load
duke
parents:
diff changeset
  1040
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1041
   * This has to handle construction of the operations so that they are evaluated
7f561c08de6b Initial load
duke
parents:
diff changeset
  1042
   * in pre-fix order.  So, for 9+7-6, instead of |+|9|-|7|6|, this needs to be
7f561c08de6b Initial load
duke
parents:
diff changeset
  1043
   * evaluated as |-|+|9|7|6|.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1044
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1045
   * MultiplicativeExpr  ::=  UnaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1046
   * | MultiplicativeExpr MultiplyOperator UnaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1047
   * | MultiplicativeExpr 'div' UnaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1048
   * | MultiplicativeExpr 'mod' UnaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1049
   * | MultiplicativeExpr 'quo' UnaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1050
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1051
   * @param addPos Position where expression is to be added, or -1 for append.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1052
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1053
   * @return the position at the end of the equality expression.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1054
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1055
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1056
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1057
  protected int MultiplicativeExpr(int addPos) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1058
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1059
7f561c08de6b Initial load
duke
parents:
diff changeset
  1060
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1061
7f561c08de6b Initial load
duke
parents:
diff changeset
  1062
    if (-1 == addPos)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1063
      addPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1064
7f561c08de6b Initial load
duke
parents:
diff changeset
  1065
    UnaryExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1066
7f561c08de6b Initial load
duke
parents:
diff changeset
  1067
    if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1068
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1069
      if (tokenIs('*'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1070
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1071
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1072
        insertOp(addPos, 2, OpCodes.OP_MULT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1073
7f561c08de6b Initial load
duke
parents:
diff changeset
  1074
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1075
7f561c08de6b Initial load
duke
parents:
diff changeset
  1076
        addPos = MultiplicativeExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1077
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1078
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1079
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1080
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1081
      else if (tokenIs("div"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1082
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1083
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1084
        insertOp(addPos, 2, OpCodes.OP_DIV);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1085
7f561c08de6b Initial load
duke
parents:
diff changeset
  1086
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1087
7f561c08de6b Initial load
duke
parents:
diff changeset
  1088
        addPos = MultiplicativeExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1089
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1090
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1091
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1092
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1093
      else if (tokenIs("mod"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1094
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1095
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1096
        insertOp(addPos, 2, OpCodes.OP_MOD);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1097
7f561c08de6b Initial load
duke
parents:
diff changeset
  1098
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1099
7f561c08de6b Initial load
duke
parents:
diff changeset
  1100
        addPos = MultiplicativeExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1101
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1102
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1103
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1104
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1105
      else if (tokenIs("quo"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1106
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1107
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1108
        insertOp(addPos, 2, OpCodes.OP_QUO);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1109
7f561c08de6b Initial load
duke
parents:
diff changeset
  1110
        int opPlusLeftHandLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1111
7f561c08de6b Initial load
duke
parents:
diff changeset
  1112
        addPos = MultiplicativeExpr(addPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1113
        m_ops.setOp(addPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1114
          m_ops.getOp(addPos + opPlusLeftHandLen + 1) + opPlusLeftHandLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1115
        addPos += 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1116
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1117
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1118
7f561c08de6b Initial load
duke
parents:
diff changeset
  1119
    return addPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1120
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1121
7f561c08de6b Initial load
duke
parents:
diff changeset
  1122
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1123
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1124
   * UnaryExpr  ::=  UnionExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1125
   * | '-' UnaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1126
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1127
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1128
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1129
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1130
  protected void UnaryExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1131
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1132
7f561c08de6b Initial load
duke
parents:
diff changeset
  1133
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1134
    boolean isNeg = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1135
7f561c08de6b Initial load
duke
parents:
diff changeset
  1136
    if (m_tokenChar == '-')
7f561c08de6b Initial load
duke
parents:
diff changeset
  1137
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1138
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1139
      appendOp(2, OpCodes.OP_NEG);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1140
7f561c08de6b Initial load
duke
parents:
diff changeset
  1141
      isNeg = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1142
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1143
7f561c08de6b Initial load
duke
parents:
diff changeset
  1144
    UnionExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1145
7f561c08de6b Initial load
duke
parents:
diff changeset
  1146
    if (isNeg)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1147
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1148
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1149
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1150
7f561c08de6b Initial load
duke
parents:
diff changeset
  1151
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1152
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1153
   * StringExpr  ::=  Expr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1154
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1155
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1156
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1157
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1158
  protected void StringExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1159
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1160
7f561c08de6b Initial load
duke
parents:
diff changeset
  1161
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1162
7f561c08de6b Initial load
duke
parents:
diff changeset
  1163
    appendOp(2, OpCodes.OP_STRING);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1164
    Expr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1165
7f561c08de6b Initial load
duke
parents:
diff changeset
  1166
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1167
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1168
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1169
7f561c08de6b Initial load
duke
parents:
diff changeset
  1170
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1171
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1172
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1173
   * StringExpr  ::=  Expr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1174
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1175
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1176
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1177
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1178
  protected void BooleanExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1179
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1180
7f561c08de6b Initial load
duke
parents:
diff changeset
  1181
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1182
7f561c08de6b Initial load
duke
parents:
diff changeset
  1183
    appendOp(2, OpCodes.OP_BOOL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1184
    Expr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1185
7f561c08de6b Initial load
duke
parents:
diff changeset
  1186
    int opLen = m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1187
7f561c08de6b Initial load
duke
parents:
diff changeset
  1188
    if (opLen == 2)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1189
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1190
      error(XPATHErrorResources.ER_BOOLEAN_ARG_NO_LONGER_OPTIONAL, null);  //"boolean(...) argument is no longer optional with 19990709 XPath draft.");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1191
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1192
7f561c08de6b Initial load
duke
parents:
diff changeset
  1193
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH, opLen);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1194
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1195
7f561c08de6b Initial load
duke
parents:
diff changeset
  1196
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1197
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1198
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1199
   * NumberExpr  ::=  Expr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1200
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1201
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1202
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1203
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1204
  protected void NumberExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1205
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1206
7f561c08de6b Initial load
duke
parents:
diff changeset
  1207
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1208
7f561c08de6b Initial load
duke
parents:
diff changeset
  1209
    appendOp(2, OpCodes.OP_NUMBER);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1210
    Expr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1211
7f561c08de6b Initial load
duke
parents:
diff changeset
  1212
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1213
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1214
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1215
7f561c08de6b Initial load
duke
parents:
diff changeset
  1216
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1217
   * The context of the right hand side expressions is the context of the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1218
   * left hand side expression. The results of the right hand side expressions
7f561c08de6b Initial load
duke
parents:
diff changeset
  1219
   * are node sets. The result of the left hand side UnionExpr is the union
7f561c08de6b Initial load
duke
parents:
diff changeset
  1220
   * of the results of the right hand side expressions.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1221
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1222
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1223
   * UnionExpr    ::=    PathExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1224
   * | UnionExpr '|' PathExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1225
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1226
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1227
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1228
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1229
  protected void UnionExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1230
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1231
7f561c08de6b Initial load
duke
parents:
diff changeset
  1232
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1233
    boolean continueOrLoop = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1234
    boolean foundUnion = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1235
7f561c08de6b Initial load
duke
parents:
diff changeset
  1236
    do
7f561c08de6b Initial load
duke
parents:
diff changeset
  1237
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1238
      PathExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1239
7f561c08de6b Initial load
duke
parents:
diff changeset
  1240
      if (tokenIs('|'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1241
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1242
        if (false == foundUnion)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1243
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1244
          foundUnion = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1245
7f561c08de6b Initial load
duke
parents:
diff changeset
  1246
          insertOp(opPos, 2, OpCodes.OP_UNION);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1247
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1248
7f561c08de6b Initial load
duke
parents:
diff changeset
  1249
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1250
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1251
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1252
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1253
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1254
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1255
7f561c08de6b Initial load
duke
parents:
diff changeset
  1256
      // this.m_testForDocOrder = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1257
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1258
    while (continueOrLoop);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1259
7f561c08de6b Initial load
duke
parents:
diff changeset
  1260
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1261
          m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1262
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1263
7f561c08de6b Initial load
duke
parents:
diff changeset
  1264
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1265
   * PathExpr  ::=  LocationPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  1266
   * | FilterExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1267
   * | FilterExpr '/' RelativeLocationPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  1268
   * | FilterExpr '//' RelativeLocationPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  1269
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1270
   * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
7f561c08de6b Initial load
duke
parents:
diff changeset
  1271
   * the error condition is severe enough to halt processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1272
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1273
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1274
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1275
  protected void PathExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1276
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1277
7f561c08de6b Initial load
duke
parents:
diff changeset
  1278
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1279
7f561c08de6b Initial load
duke
parents:
diff changeset
  1280
    int filterExprMatch = FilterExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1281
7f561c08de6b Initial load
duke
parents:
diff changeset
  1282
    if (filterExprMatch != FILTER_MATCH_FAILED)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1283
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1284
      // If FilterExpr had Predicates, a OP_LOCATIONPATH opcode would already
7f561c08de6b Initial load
duke
parents:
diff changeset
  1285
      // have been inserted.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1286
      boolean locationPathStarted = (filterExprMatch==FILTER_MATCH_PREDICATES);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1287
7f561c08de6b Initial load
duke
parents:
diff changeset
  1288
      if (tokenIs('/'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1289
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1290
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1291
7f561c08de6b Initial load
duke
parents:
diff changeset
  1292
        if (!locationPathStarted)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1293
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1294
          // int locationPathOpPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1295
          insertOp(opPos, 2, OpCodes.OP_LOCATIONPATH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1296
7f561c08de6b Initial load
duke
parents:
diff changeset
  1297
          locationPathStarted = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1298
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1299
7f561c08de6b Initial load
duke
parents:
diff changeset
  1300
        if (!RelativeLocationPath())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1301
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1302
          // "Relative location path expected following '/' or '//'"
7f561c08de6b Initial load
duke
parents:
diff changeset
  1303
          error(XPATHErrorResources.ER_EXPECTED_REL_LOC_PATH, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1304
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1305
7f561c08de6b Initial load
duke
parents:
diff changeset
  1306
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1307
7f561c08de6b Initial load
duke
parents:
diff changeset
  1308
      // Terminate for safety.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1309
      if (locationPathStarted)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1310
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1311
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1312
        m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1313
        m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1314
          m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1315
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1316
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1317
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1318
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1319
      LocationPath();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1320
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1321
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1322
7f561c08de6b Initial load
duke
parents:
diff changeset
  1323
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1324
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1325
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1326
   * FilterExpr  ::=  PrimaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1327
   * | FilterExpr Predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1328
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1329
   * @throws XSLProcessorException thrown if the active ProblemListener and XPathContext decide
7f561c08de6b Initial load
duke
parents:
diff changeset
  1330
   * the error condition is severe enough to halt processing.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1331
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1332
   * @return  FILTER_MATCH_PREDICATES, if this method successfully matched a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1333
   *          FilterExpr with one or more Predicates;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1334
   *          FILTER_MATCH_PRIMARY, if this method successfully matched a
7f561c08de6b Initial load
duke
parents:
diff changeset
  1335
   *          FilterExpr that was just a PrimaryExpr; or
7f561c08de6b Initial load
duke
parents:
diff changeset
  1336
   *          FILTER_MATCH_FAILED, if this method did not match a FilterExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1337
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1338
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1339
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1340
  protected int FilterExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1341
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1342
7f561c08de6b Initial load
duke
parents:
diff changeset
  1343
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1344
7f561c08de6b Initial load
duke
parents:
diff changeset
  1345
    int filterMatch;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1346
7f561c08de6b Initial load
duke
parents:
diff changeset
  1347
    if (PrimaryExpr())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1348
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1349
      if (tokenIs('['))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1350
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1351
7f561c08de6b Initial load
duke
parents:
diff changeset
  1352
        // int locationPathOpPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1353
        insertOp(opPos, 2, OpCodes.OP_LOCATIONPATH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1354
7f561c08de6b Initial load
duke
parents:
diff changeset
  1355
        while (tokenIs('['))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1356
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1357
          Predicate();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1358
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1359
7f561c08de6b Initial load
duke
parents:
diff changeset
  1360
        filterMatch = FILTER_MATCH_PREDICATES;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1361
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1362
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1363
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1364
        filterMatch = FILTER_MATCH_PRIMARY;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1365
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1366
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1367
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1368
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1369
      filterMatch = FILTER_MATCH_FAILED;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1370
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1371
7f561c08de6b Initial load
duke
parents:
diff changeset
  1372
    return filterMatch;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1373
7f561c08de6b Initial load
duke
parents:
diff changeset
  1374
    /*
7f561c08de6b Initial load
duke
parents:
diff changeset
  1375
     * if(tokenIs('['))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1376
     * {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1377
     *   Predicate();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1378
     *   m_ops.m_opMap[opPos + OpMap.MAPINDEX_LENGTH] = m_ops.m_opMap[OpMap.MAPINDEX_LENGTH] - opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1379
     * }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1380
     */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1381
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1382
7f561c08de6b Initial load
duke
parents:
diff changeset
  1383
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1384
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1385
   * PrimaryExpr  ::=  VariableReference
7f561c08de6b Initial load
duke
parents:
diff changeset
  1386
   * | '(' Expr ')'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1387
   * | Literal
7f561c08de6b Initial load
duke
parents:
diff changeset
  1388
   * | Number
7f561c08de6b Initial load
duke
parents:
diff changeset
  1389
   * | FunctionCall
7f561c08de6b Initial load
duke
parents:
diff changeset
  1390
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1391
   * @return true if this method successfully matched a PrimaryExpr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1392
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1393
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1394
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1395
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1396
  protected boolean PrimaryExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1397
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1398
7f561c08de6b Initial load
duke
parents:
diff changeset
  1399
    boolean matchFound;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1400
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1401
7f561c08de6b Initial load
duke
parents:
diff changeset
  1402
    if ((m_tokenChar == '\'') || (m_tokenChar == '"'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1403
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1404
      appendOp(2, OpCodes.OP_LITERAL);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1405
      Literal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1406
7f561c08de6b Initial load
duke
parents:
diff changeset
  1407
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1408
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1409
7f561c08de6b Initial load
duke
parents:
diff changeset
  1410
      matchFound = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1411
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1412
    else if (m_tokenChar == '$')
7f561c08de6b Initial load
duke
parents:
diff changeset
  1413
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1414
      nextToken();  // consume '$'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1415
      appendOp(2, OpCodes.OP_VARIABLE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1416
      QName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1417
7f561c08de6b Initial load
duke
parents:
diff changeset
  1418
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1419
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1420
7f561c08de6b Initial load
duke
parents:
diff changeset
  1421
      matchFound = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1422
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1423
    else if (m_tokenChar == '(')
7f561c08de6b Initial load
duke
parents:
diff changeset
  1424
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1425
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1426
      appendOp(2, OpCodes.OP_GROUP);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1427
      Expr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1428
      consumeExpected(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1429
7f561c08de6b Initial load
duke
parents:
diff changeset
  1430
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1431
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1432
7f561c08de6b Initial load
duke
parents:
diff changeset
  1433
      matchFound = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1434
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1435
    else if ((null != m_token) && ((('.' == m_tokenChar) && (m_token.length() > 1) && Character.isDigit(
7f561c08de6b Initial load
duke
parents:
diff changeset
  1436
            m_token.charAt(1))) || Character.isDigit(m_tokenChar)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1437
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1438
      appendOp(2, OpCodes.OP_NUMBERLIT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1439
      Number();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1440
7f561c08de6b Initial load
duke
parents:
diff changeset
  1441
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1442
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1443
7f561c08de6b Initial load
duke
parents:
diff changeset
  1444
      matchFound = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1445
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1446
    else if (lookahead('(', 1) || (lookahead(':', 1) && lookahead('(', 3)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1447
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1448
      matchFound = FunctionCall();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1449
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1450
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1451
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1452
      matchFound = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1453
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1454
7f561c08de6b Initial load
duke
parents:
diff changeset
  1455
    return matchFound;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1456
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1457
7f561c08de6b Initial load
duke
parents:
diff changeset
  1458
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1459
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1460
   * Argument    ::=    Expr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1461
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1462
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1463
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1464
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1465
  protected void Argument() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1466
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1467
7f561c08de6b Initial load
duke
parents:
diff changeset
  1468
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1469
7f561c08de6b Initial load
duke
parents:
diff changeset
  1470
    appendOp(2, OpCodes.OP_ARGUMENT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1471
    Expr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1472
7f561c08de6b Initial load
duke
parents:
diff changeset
  1473
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1474
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1475
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1476
7f561c08de6b Initial load
duke
parents:
diff changeset
  1477
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1478
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1479
   * FunctionCall    ::=    FunctionName '(' ( Argument ( ',' Argument)*)? ')'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1480
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1481
   * @return true if, and only if, a FunctionCall was matched
7f561c08de6b Initial load
duke
parents:
diff changeset
  1482
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1483
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1484
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1485
  protected boolean FunctionCall() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1486
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1487
7f561c08de6b Initial load
duke
parents:
diff changeset
  1488
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1489
7f561c08de6b Initial load
duke
parents:
diff changeset
  1490
    if (lookahead(':', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1491
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1492
      appendOp(4, OpCodes.OP_EXTFUNCTION);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1493
7f561c08de6b Initial load
duke
parents:
diff changeset
  1494
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1495
7f561c08de6b Initial load
duke
parents:
diff changeset
  1496
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1497
      consumeExpected(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1498
7f561c08de6b Initial load
duke
parents:
diff changeset
  1499
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 2, m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1500
7f561c08de6b Initial load
duke
parents:
diff changeset
  1501
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1502
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1503
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1504
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1505
      int funcTok = getFunctionToken(m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1506
7f561c08de6b Initial load
duke
parents:
diff changeset
  1507
      if (-1 == funcTok)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1508
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1509
        error(XPATHErrorResources.ER_COULDNOT_FIND_FUNCTION,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1510
              new Object[]{ m_token });  //"Could not find function: "+m_token+"()");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1511
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1512
7f561c08de6b Initial load
duke
parents:
diff changeset
  1513
      switch (funcTok)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1514
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1515
      case OpCodes.NODETYPE_PI :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1516
      case OpCodes.NODETYPE_COMMENT :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1517
      case OpCodes.NODETYPE_TEXT :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1518
      case OpCodes.NODETYPE_NODE :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1519
        // Node type tests look like function calls, but they're not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1520
        return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1521
      default :
7f561c08de6b Initial load
duke
parents:
diff changeset
  1522
        appendOp(3, OpCodes.OP_FUNCTION);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1523
7f561c08de6b Initial load
duke
parents:
diff changeset
  1524
        m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1, funcTok);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1525
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1526
7f561c08de6b Initial load
duke
parents:
diff changeset
  1527
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1528
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1529
7f561c08de6b Initial load
duke
parents:
diff changeset
  1530
    consumeExpected('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1531
7f561c08de6b Initial load
duke
parents:
diff changeset
  1532
    while (!tokenIs(')') && m_token != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1533
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1534
      if (tokenIs(','))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1535
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1536
        error(XPATHErrorResources.ER_FOUND_COMMA_BUT_NO_PRECEDING_ARG, null);  //"Found ',' but no preceding argument!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1537
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1538
7f561c08de6b Initial load
duke
parents:
diff changeset
  1539
      Argument();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1540
7f561c08de6b Initial load
duke
parents:
diff changeset
  1541
      if (!tokenIs(')'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1542
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1543
        consumeExpected(',');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1544
7f561c08de6b Initial load
duke
parents:
diff changeset
  1545
        if (tokenIs(')'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1546
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1547
          error(XPATHErrorResources.ER_FOUND_COMMA_BUT_NO_FOLLOWING_ARG,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1548
                null);  //"Found ',' but no following argument!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1549
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1550
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1551
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1552
7f561c08de6b Initial load
duke
parents:
diff changeset
  1553
    consumeExpected(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1554
7f561c08de6b Initial load
duke
parents:
diff changeset
  1555
    // Terminate for safety.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1556
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1557
    m_ops.setOp(OpMap.MAPINDEX_LENGTH,m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1558
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1559
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1560
7f561c08de6b Initial load
duke
parents:
diff changeset
  1561
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1562
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1563
7f561c08de6b Initial load
duke
parents:
diff changeset
  1564
  // ============= GRAMMAR FUNCTIONS =================
7f561c08de6b Initial load
duke
parents:
diff changeset
  1565
7f561c08de6b Initial load
duke
parents:
diff changeset
  1566
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1567
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1568
   * LocationPath ::= RelativeLocationPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  1569
   * | AbsoluteLocationPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  1570
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1571
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1572
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1573
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1574
  protected void LocationPath() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1575
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1576
7f561c08de6b Initial load
duke
parents:
diff changeset
  1577
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1578
7f561c08de6b Initial load
duke
parents:
diff changeset
  1579
    // int locationPathOpPos = opPos;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1580
    appendOp(2, OpCodes.OP_LOCATIONPATH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1581
7f561c08de6b Initial load
duke
parents:
diff changeset
  1582
    boolean seenSlash = tokenIs('/');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1583
7f561c08de6b Initial load
duke
parents:
diff changeset
  1584
    if (seenSlash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1585
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1586
      appendOp(4, OpCodes.FROM_ROOT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1587
7f561c08de6b Initial load
duke
parents:
diff changeset
  1588
      // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1589
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 2, 4);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1590
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 1, OpCodes.NODETYPE_ROOT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1591
7f561c08de6b Initial load
duke
parents:
diff changeset
  1592
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1593
    } else if (m_token == null) {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1594
      error(XPATHErrorResources.ER_EXPECTED_LOC_PATH_AT_END_EXPR, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1595
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1596
7f561c08de6b Initial load
duke
parents:
diff changeset
  1597
    if (m_token != null)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1598
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1599
      if (!RelativeLocationPath() && !seenSlash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1600
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1601
        // Neither a '/' nor a RelativeLocationPath - i.e., matched nothing
7f561c08de6b Initial load
duke
parents:
diff changeset
  1602
        // "Location path expected, but found "+m_token+" was encountered."
7f561c08de6b Initial load
duke
parents:
diff changeset
  1603
        error(XPATHErrorResources.ER_EXPECTED_LOC_PATH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1604
              new Object [] {m_token});
7f561c08de6b Initial load
duke
parents:
diff changeset
  1605
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1606
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1607
7f561c08de6b Initial load
duke
parents:
diff changeset
  1608
    // Terminate for safety.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1609
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1610
    m_ops.setOp(OpMap.MAPINDEX_LENGTH,m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1611
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1612
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1613
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1614
7f561c08de6b Initial load
duke
parents:
diff changeset
  1615
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1616
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1617
   * RelativeLocationPath ::= Step
7f561c08de6b Initial load
duke
parents:
diff changeset
  1618
   * | RelativeLocationPath '/' Step
7f561c08de6b Initial load
duke
parents:
diff changeset
  1619
   * | AbbreviatedRelativeLocationPath
7f561c08de6b Initial load
duke
parents:
diff changeset
  1620
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1621
   * @returns true if, and only if, a RelativeLocationPath was matched
7f561c08de6b Initial load
duke
parents:
diff changeset
  1622
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1623
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1624
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1625
  protected boolean RelativeLocationPath()
7f561c08de6b Initial load
duke
parents:
diff changeset
  1626
               throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1627
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1628
    if (!Step())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1629
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1630
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1631
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1632
7f561c08de6b Initial load
duke
parents:
diff changeset
  1633
    while (tokenIs('/'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1634
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1635
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1636
7f561c08de6b Initial load
duke
parents:
diff changeset
  1637
      if (!Step())
7f561c08de6b Initial load
duke
parents:
diff changeset
  1638
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1639
        // RelativeLocationPath can't end with a trailing '/'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1640
        // "Location step expected following '/' or '//'"
7f561c08de6b Initial load
duke
parents:
diff changeset
  1641
        error(XPATHErrorResources.ER_EXPECTED_LOC_STEP, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1642
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1643
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1644
7f561c08de6b Initial load
duke
parents:
diff changeset
  1645
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1646
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1647
7f561c08de6b Initial load
duke
parents:
diff changeset
  1648
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1649
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1650
   * Step    ::=    Basis Predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1651
   * | AbbreviatedStep
7f561c08de6b Initial load
duke
parents:
diff changeset
  1652
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1653
   * @returns false if step was empty (or only a '/'); true, otherwise
7f561c08de6b Initial load
duke
parents:
diff changeset
  1654
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1655
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1656
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1657
  protected boolean Step() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1658
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1659
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1660
7f561c08de6b Initial load
duke
parents:
diff changeset
  1661
    boolean doubleSlash = tokenIs('/');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1662
7f561c08de6b Initial load
duke
parents:
diff changeset
  1663
    // At most a single '/' before each Step is consumed by caller; if the
7f561c08de6b Initial load
duke
parents:
diff changeset
  1664
    // first thing is a '/', that means we had '//' and the Step must not
7f561c08de6b Initial load
duke
parents:
diff changeset
  1665
    // be empty.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1666
    if (doubleSlash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1667
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1668
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1669
7f561c08de6b Initial load
duke
parents:
diff changeset
  1670
      appendOp(2, OpCodes.FROM_DESCENDANTS_OR_SELF);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1671
7f561c08de6b Initial load
duke
parents:
diff changeset
  1672
      // Have to fix up for patterns such as '//@foo' or '//attribute::foo',
7f561c08de6b Initial load
duke
parents:
diff changeset
  1673
      // which translate to 'descendant-or-self::node()/attribute::foo'.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1674
      // notice I leave the '/' on the queue, so the next will be processed
7f561c08de6b Initial load
duke
parents:
diff changeset
  1675
      // by a regular step pattern.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1676
7f561c08de6b Initial load
duke
parents:
diff changeset
  1677
      // Make room for telling how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1678
      m_ops.setOp(OpMap.MAPINDEX_LENGTH,m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1679
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.NODETYPE_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1680
      m_ops.setOp(OpMap.MAPINDEX_LENGTH,m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1681
7f561c08de6b Initial load
duke
parents:
diff changeset
  1682
      // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1683
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1684
          m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1685
7f561c08de6b Initial load
duke
parents:
diff changeset
  1686
      // Tell how long the step is with the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1687
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1688
          m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1689
7f561c08de6b Initial load
duke
parents:
diff changeset
  1690
      opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1691
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1692
7f561c08de6b Initial load
duke
parents:
diff changeset
  1693
    if (tokenIs("."))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1694
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1695
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1696
7f561c08de6b Initial load
duke
parents:
diff changeset
  1697
      if (tokenIs('['))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1698
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1699
        error(XPATHErrorResources.ER_PREDICATE_ILLEGAL_SYNTAX, null);  //"'..[predicate]' or '.[predicate]' is illegal syntax.  Use 'self::node()[predicate]' instead.");
7f561c08de6b Initial load
duke
parents:
diff changeset
  1700
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1701
7f561c08de6b Initial load
duke
parents:
diff changeset
  1702
      appendOp(4, OpCodes.FROM_SELF);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1703
7f561c08de6b Initial load
duke
parents:
diff changeset
  1704
      // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1705
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 2,4);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1706
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 1, OpCodes.NODETYPE_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1707
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1708
    else if (tokenIs(".."))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1709
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1710
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1711
      appendOp(4, OpCodes.FROM_PARENT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1712
7f561c08de6b Initial load
duke
parents:
diff changeset
  1713
      // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1714
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 2,4);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1715
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 1, OpCodes.NODETYPE_NODE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1716
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1717
7f561c08de6b Initial load
duke
parents:
diff changeset
  1718
    // There is probably a better way to test for this
7f561c08de6b Initial load
duke
parents:
diff changeset
  1719
    // transition... but it gets real hairy if you try
7f561c08de6b Initial load
duke
parents:
diff changeset
  1720
    // to do it in basis().
7f561c08de6b Initial load
duke
parents:
diff changeset
  1721
    else if (tokenIs('*') || tokenIs('@') || tokenIs('_')
7f561c08de6b Initial load
duke
parents:
diff changeset
  1722
             || (m_token!= null && Character.isLetter(m_token.charAt(0))))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1723
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1724
      Basis();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1725
7f561c08de6b Initial load
duke
parents:
diff changeset
  1726
      while (tokenIs('['))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1727
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1728
        Predicate();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1729
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1730
7f561c08de6b Initial load
duke
parents:
diff changeset
  1731
      // Tell how long the entire step is.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1732
      m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1733
        m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1734
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1735
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1736
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1737
      // No Step matched - that's an error if previous thing was a '//'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1738
      if (doubleSlash)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1739
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1740
        // "Location step expected following '/' or '//'"
7f561c08de6b Initial load
duke
parents:
diff changeset
  1741
        error(XPATHErrorResources.ER_EXPECTED_LOC_STEP, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1742
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1743
7f561c08de6b Initial load
duke
parents:
diff changeset
  1744
      return false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1745
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1746
7f561c08de6b Initial load
duke
parents:
diff changeset
  1747
    return true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1748
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1749
7f561c08de6b Initial load
duke
parents:
diff changeset
  1750
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1751
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1752
   * Basis    ::=    AxisName '::' NodeTest
7f561c08de6b Initial load
duke
parents:
diff changeset
  1753
   * | AbbreviatedBasis
7f561c08de6b Initial load
duke
parents:
diff changeset
  1754
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1755
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1756
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1757
  protected void Basis() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1758
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1759
7f561c08de6b Initial load
duke
parents:
diff changeset
  1760
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1761
    int axesType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1762
7f561c08de6b Initial load
duke
parents:
diff changeset
  1763
    // The next blocks guarantee that a FROM_XXX will be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1764
    if (lookahead("::", 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1765
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1766
      axesType = AxisName();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1767
7f561c08de6b Initial load
duke
parents:
diff changeset
  1768
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1769
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1770
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1771
    else if (tokenIs('@'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1772
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1773
      axesType = OpCodes.FROM_ATTRIBUTES;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1774
7f561c08de6b Initial load
duke
parents:
diff changeset
  1775
      appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1776
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1777
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1778
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1779
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1780
      axesType = OpCodes.FROM_CHILDREN;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1781
7f561c08de6b Initial load
duke
parents:
diff changeset
  1782
      appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1783
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1784
7f561c08de6b Initial load
duke
parents:
diff changeset
  1785
    // Make room for telling how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1786
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1787
7f561c08de6b Initial load
duke
parents:
diff changeset
  1788
    NodeTest(axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1789
7f561c08de6b Initial load
duke
parents:
diff changeset
  1790
    // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  1791
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1792
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1793
   }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1794
7f561c08de6b Initial load
duke
parents:
diff changeset
  1795
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1796
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1797
   * Basis    ::=    AxisName '::' NodeTest
7f561c08de6b Initial load
duke
parents:
diff changeset
  1798
   * | AbbreviatedBasis
7f561c08de6b Initial load
duke
parents:
diff changeset
  1799
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1800
   * @return FROM_XXX axes type, found in {@link com.sun.org.apache.xpath.internal.compiler.Keywords}.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1801
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1802
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1803
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1804
  protected int AxisName() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1805
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1806
7f561c08de6b Initial load
duke
parents:
diff changeset
  1807
    Object val = Keywords.getAxisName(m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1808
7f561c08de6b Initial load
duke
parents:
diff changeset
  1809
    if (null == val)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1810
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1811
      error(XPATHErrorResources.ER_ILLEGAL_AXIS_NAME,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1812
            new Object[]{ m_token });  //"illegal axis name: "+m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1813
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1814
7f561c08de6b Initial load
duke
parents:
diff changeset
  1815
    int axesType = ((Integer) val).intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1816
7f561c08de6b Initial load
duke
parents:
diff changeset
  1817
    appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1818
7f561c08de6b Initial load
duke
parents:
diff changeset
  1819
    return axesType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  1820
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1821
7f561c08de6b Initial load
duke
parents:
diff changeset
  1822
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1823
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1824
   * NodeTest    ::=    WildcardName
7f561c08de6b Initial load
duke
parents:
diff changeset
  1825
   * | NodeType '(' ')'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1826
   * | 'processing-instruction' '(' Literal ')'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1827
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1828
   * @param axesType FROM_XXX axes type, found in {@link com.sun.org.apache.xpath.internal.compiler.Keywords}.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1829
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1830
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1831
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1832
  protected void NodeTest(int axesType) throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1833
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1834
7f561c08de6b Initial load
duke
parents:
diff changeset
  1835
    if (lookahead('(', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1836
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1837
      Object nodeTestOp = Keywords.getNodeType(m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1838
7f561c08de6b Initial load
duke
parents:
diff changeset
  1839
      if (null == nodeTestOp)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1840
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1841
        error(XPATHErrorResources.ER_UNKNOWN_NODETYPE,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1842
              new Object[]{ m_token });  //"Unknown nodetype: "+m_token);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1843
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1844
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1845
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1846
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1847
7f561c08de6b Initial load
duke
parents:
diff changeset
  1848
        int nt = ((Integer) nodeTestOp).intValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1849
7f561c08de6b Initial load
duke
parents:
diff changeset
  1850
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), nt);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1851
        m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1852
7f561c08de6b Initial load
duke
parents:
diff changeset
  1853
        consumeExpected('(');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1854
7f561c08de6b Initial load
duke
parents:
diff changeset
  1855
        if (OpCodes.NODETYPE_PI == nt)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1856
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1857
          if (!tokenIs(')'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1858
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1859
            Literal();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1860
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1861
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1862
7f561c08de6b Initial load
duke
parents:
diff changeset
  1863
        consumeExpected(')');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1864
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1865
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1866
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1867
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1868
7f561c08de6b Initial load
duke
parents:
diff changeset
  1869
      // Assume name of attribute or element.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1870
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.NODENAME);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1871
      m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1872
7f561c08de6b Initial load
duke
parents:
diff changeset
  1873
      if (lookahead(':', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1874
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1875
        if (tokenIs('*'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1876
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1877
          m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ELEMWILDCARD);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1878
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1879
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1880
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1881
          m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1882
7f561c08de6b Initial load
duke
parents:
diff changeset
  1883
          // Minimalist check for an NCName - just check first character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1884
          // to distinguish from other possible tokens
7f561c08de6b Initial load
duke
parents:
diff changeset
  1885
          if (!Character.isLetter(m_tokenChar) && !tokenIs('_'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1886
          {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1887
            // "Node test that matches either NCName:* or QName was expected."
7f561c08de6b Initial load
duke
parents:
diff changeset
  1888
            error(XPATHErrorResources.ER_EXPECTED_NODE_TEST, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1889
          }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1890
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1891
7f561c08de6b Initial load
duke
parents:
diff changeset
  1892
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1893
        consumeExpected(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1894
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1895
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1896
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1897
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.EMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1898
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1899
7f561c08de6b Initial load
duke
parents:
diff changeset
  1900
      m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1901
7f561c08de6b Initial load
duke
parents:
diff changeset
  1902
      if (tokenIs('*'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1903
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1904
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ELEMWILDCARD);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1905
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1906
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1907
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1908
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1909
7f561c08de6b Initial load
duke
parents:
diff changeset
  1910
        // Minimalist check for an NCName - just check first character
7f561c08de6b Initial load
duke
parents:
diff changeset
  1911
        // to distinguish from other possible tokens
7f561c08de6b Initial load
duke
parents:
diff changeset
  1912
        if (!Character.isLetter(m_tokenChar) && !tokenIs('_'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1913
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1914
          // "Node test that matches either NCName:* or QName was expected."
7f561c08de6b Initial load
duke
parents:
diff changeset
  1915
          error(XPATHErrorResources.ER_EXPECTED_NODE_TEST, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1916
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1917
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1918
7f561c08de6b Initial load
duke
parents:
diff changeset
  1919
      m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1920
7f561c08de6b Initial load
duke
parents:
diff changeset
  1921
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1922
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1923
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1924
7f561c08de6b Initial load
duke
parents:
diff changeset
  1925
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1926
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1927
   * Predicate ::= '[' PredicateExpr ']'
7f561c08de6b Initial load
duke
parents:
diff changeset
  1928
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1929
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1930
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1931
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1932
  protected void Predicate() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1933
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1934
7f561c08de6b Initial load
duke
parents:
diff changeset
  1935
    if (tokenIs('['))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1936
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1937
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1938
      PredicateExpr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1939
      consumeExpected(']');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1940
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1941
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1942
7f561c08de6b Initial load
duke
parents:
diff changeset
  1943
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1944
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1945
   * PredicateExpr ::= Expr
7f561c08de6b Initial load
duke
parents:
diff changeset
  1946
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1947
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1948
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1949
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1950
  protected void PredicateExpr() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1951
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1952
7f561c08de6b Initial load
duke
parents:
diff changeset
  1953
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1954
7f561c08de6b Initial load
duke
parents:
diff changeset
  1955
    appendOp(2, OpCodes.OP_PREDICATE);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1956
    Expr();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1957
7f561c08de6b Initial load
duke
parents:
diff changeset
  1958
    // Terminate for safety.
7f561c08de6b Initial load
duke
parents:
diff changeset
  1959
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1960
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1961
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  1962
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1963
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1964
7f561c08de6b Initial load
duke
parents:
diff changeset
  1965
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1966
   * QName ::=  (Prefix ':')? LocalPart
7f561c08de6b Initial load
duke
parents:
diff changeset
  1967
   * Prefix ::=  NCName
7f561c08de6b Initial load
duke
parents:
diff changeset
  1968
   * LocalPart ::=  NCName
7f561c08de6b Initial load
duke
parents:
diff changeset
  1969
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  1970
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1971
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  1972
  protected void QName() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  1973
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1974
    // Namespace
7f561c08de6b Initial load
duke
parents:
diff changeset
  1975
    if(lookahead(':', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  1976
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1977
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1978
      m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1979
7f561c08de6b Initial load
duke
parents:
diff changeset
  1980
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1981
      consumeExpected(':');
7f561c08de6b Initial load
duke
parents:
diff changeset
  1982
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1983
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  1984
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  1985
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.EMPTY);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1986
      m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1987
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1988
7f561c08de6b Initial load
duke
parents:
diff changeset
  1989
    // Local name
7f561c08de6b Initial load
duke
parents:
diff changeset
  1990
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1991
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  1992
7f561c08de6b Initial load
duke
parents:
diff changeset
  1993
    nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  1994
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  1995
7f561c08de6b Initial load
duke
parents:
diff changeset
  1996
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  1997
   * NCName ::=  (Letter | '_') (NCNameChar)
7f561c08de6b Initial load
duke
parents:
diff changeset
  1998
   * NCNameChar ::=  Letter | Digit | '.' | '-' | '_' | CombiningChar | Extender
7f561c08de6b Initial load
duke
parents:
diff changeset
  1999
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2000
  protected void NCName()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2001
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2002
7f561c08de6b Initial load
duke
parents:
diff changeset
  2003
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2004
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2005
7f561c08de6b Initial load
duke
parents:
diff changeset
  2006
    nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2007
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2008
7f561c08de6b Initial load
duke
parents:
diff changeset
  2009
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2010
   * The value of the Literal is the sequence of characters inside
7f561c08de6b Initial load
duke
parents:
diff changeset
  2011
   * the " or ' characters>.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2012
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2013
   * Literal  ::=  '"' [^"]* '"'
7f561c08de6b Initial load
duke
parents:
diff changeset
  2014
   * | "'" [^']* "'"
7f561c08de6b Initial load
duke
parents:
diff changeset
  2015
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2016
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2017
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2018
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2019
  protected void Literal() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2020
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2021
7f561c08de6b Initial load
duke
parents:
diff changeset
  2022
    int last = m_token.length() - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2023
    char c0 = m_tokenChar;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2024
    char cX = m_token.charAt(last);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2025
7f561c08de6b Initial load
duke
parents:
diff changeset
  2026
    if (((c0 == '\"') && (cX == '\"')) || ((c0 == '\'') && (cX == '\'')))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2027
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2028
7f561c08de6b Initial load
duke
parents:
diff changeset
  2029
      // Mutate the token to remove the quotes and have the XString object
7f561c08de6b Initial load
duke
parents:
diff changeset
  2030
      // already made.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2031
      int tokenQueuePos = m_queueMark - 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2032
7f561c08de6b Initial load
duke
parents:
diff changeset
  2033
      m_ops.m_tokenQueue.setElementAt(null,tokenQueuePos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2034
7f561c08de6b Initial load
duke
parents:
diff changeset
  2035
      Object obj = new XString(m_token.substring(1, last));
7f561c08de6b Initial load
duke
parents:
diff changeset
  2036
7f561c08de6b Initial load
duke
parents:
diff changeset
  2037
      m_ops.m_tokenQueue.setElementAt(obj,tokenQueuePos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2038
7f561c08de6b Initial load
duke
parents:
diff changeset
  2039
      // lit = m_token.substring(1, last);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2040
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), tokenQueuePos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2041
      m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2042
7f561c08de6b Initial load
duke
parents:
diff changeset
  2043
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2044
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2045
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2046
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2047
      error(XPATHErrorResources.ER_PATTERN_LITERAL_NEEDS_BE_QUOTED,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2048
            new Object[]{ m_token });  //"Pattern literal ("+m_token+") needs to be quoted!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2049
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2050
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2051
7f561c08de6b Initial load
duke
parents:
diff changeset
  2052
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2053
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2054
   * Number ::= [0-9]+('.'[0-9]+)? | '.'[0-9]+
7f561c08de6b Initial load
duke
parents:
diff changeset
  2055
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2056
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2057
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2058
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2059
  protected void Number() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2060
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2061
7f561c08de6b Initial load
duke
parents:
diff changeset
  2062
    if (null != m_token)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2063
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2064
7f561c08de6b Initial load
duke
parents:
diff changeset
  2065
      // Mutate the token to remove the quotes and have the XNumber object
7f561c08de6b Initial load
duke
parents:
diff changeset
  2066
      // already made.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2067
      double num;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2068
7f561c08de6b Initial load
duke
parents:
diff changeset
  2069
      try
7f561c08de6b Initial load
duke
parents:
diff changeset
  2070
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2071
        // XPath 1.0 does not support number in exp notation
7f561c08de6b Initial load
duke
parents:
diff changeset
  2072
        if ((m_token.indexOf('e') > -1)||(m_token.indexOf('E') > -1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2073
                throw new NumberFormatException();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2074
        num = Double.valueOf(m_token).doubleValue();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2075
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2076
      catch (NumberFormatException nfe)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2077
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2078
        num = 0.0;  // to shut up compiler.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2079
7f561c08de6b Initial load
duke
parents:
diff changeset
  2080
        error(XPATHErrorResources.ER_COULDNOT_BE_FORMATTED_TO_NUMBER,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2081
              new Object[]{ m_token });  //m_token+" could not be formatted to a number!");
7f561c08de6b Initial load
duke
parents:
diff changeset
  2082
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2083
7f561c08de6b Initial load
duke
parents:
diff changeset
  2084
      m_ops.m_tokenQueue.setElementAt(new XNumber(num),m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2085
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), m_queueMark - 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2086
      m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2087
7f561c08de6b Initial load
duke
parents:
diff changeset
  2088
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2089
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2090
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2091
7f561c08de6b Initial load
duke
parents:
diff changeset
  2092
  // ============= PATTERN FUNCTIONS =================
7f561c08de6b Initial load
duke
parents:
diff changeset
  2093
7f561c08de6b Initial load
duke
parents:
diff changeset
  2094
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2095
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2096
   * Pattern  ::=  LocationPathPattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  2097
   * | Pattern '|' LocationPathPattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  2098
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2099
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2100
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2101
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2102
  protected void Pattern() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2103
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2104
7f561c08de6b Initial load
duke
parents:
diff changeset
  2105
    while (true)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2106
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2107
      LocationPathPattern();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2108
7f561c08de6b Initial load
duke
parents:
diff changeset
  2109
      if (tokenIs('|'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2110
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2111
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2112
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2113
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2114
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2115
        break;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2116
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2117
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2118
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2119
7f561c08de6b Initial load
duke
parents:
diff changeset
  2120
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2121
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2122
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2123
   * LocationPathPattern  ::=  '/' RelativePathPattern?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2124
   * | IdKeyPattern (('/' | '//') RelativePathPattern)?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2125
   * | '//'? RelativePathPattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  2126
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2127
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2128
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2129
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2130
  protected void LocationPathPattern() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2131
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2132
7f561c08de6b Initial load
duke
parents:
diff changeset
  2133
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2134
7f561c08de6b Initial load
duke
parents:
diff changeset
  2135
    final int RELATIVE_PATH_NOT_PERMITTED = 0;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2136
    final int RELATIVE_PATH_PERMITTED     = 1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2137
    final int RELATIVE_PATH_REQUIRED      = 2;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2138
7f561c08de6b Initial load
duke
parents:
diff changeset
  2139
    int relativePathStatus = RELATIVE_PATH_NOT_PERMITTED;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2140
7f561c08de6b Initial load
duke
parents:
diff changeset
  2141
    appendOp(2, OpCodes.OP_LOCATIONPATHPATTERN);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2142
7f561c08de6b Initial load
duke
parents:
diff changeset
  2143
    if (lookahead('(', 1)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2144
            && (tokenIs(Keywords.FUNC_ID_STRING)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2145
                || tokenIs(Keywords.FUNC_KEY_STRING)))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2146
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2147
      IdKeyPattern();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2148
7f561c08de6b Initial load
duke
parents:
diff changeset
  2149
      if (tokenIs('/'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2150
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2151
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2152
7f561c08de6b Initial load
duke
parents:
diff changeset
  2153
        if (tokenIs('/'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2154
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2155
          appendOp(4, OpCodes.MATCH_ANY_ANCESTOR);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2156
7f561c08de6b Initial load
duke
parents:
diff changeset
  2157
          nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2158
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2159
        else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2160
        {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2161
          appendOp(4, OpCodes.MATCH_IMMEDIATE_ANCESTOR);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2162
        }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2163
7f561c08de6b Initial load
duke
parents:
diff changeset
  2164
        // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  2165
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 2, 4);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2166
        m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 1, OpCodes.NODETYPE_FUNCTEST);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2167
7f561c08de6b Initial load
duke
parents:
diff changeset
  2168
        relativePathStatus = RELATIVE_PATH_REQUIRED;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2169
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2170
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2171
    else if (tokenIs('/'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2172
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2173
      if (lookahead('/', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2174
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2175
        appendOp(4, OpCodes.MATCH_ANY_ANCESTOR);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2176
7f561c08de6b Initial load
duke
parents:
diff changeset
  2177
        // Added this to fix bug reported by Myriam for match="//x/a"
7f561c08de6b Initial load
duke
parents:
diff changeset
  2178
        // patterns.  If you don't do this, the 'x' step will think it's part
7f561c08de6b Initial load
duke
parents:
diff changeset
  2179
        // of a '//' pattern, and so will cause 'a' to be matched when it has
7f561c08de6b Initial load
duke
parents:
diff changeset
  2180
        // any ancestor that is 'x'.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2181
        nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2182
7f561c08de6b Initial load
duke
parents:
diff changeset
  2183
        relativePathStatus = RELATIVE_PATH_REQUIRED;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2184
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2185
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2186
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2187
        appendOp(4, OpCodes.FROM_ROOT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2188
7f561c08de6b Initial load
duke
parents:
diff changeset
  2189
        relativePathStatus = RELATIVE_PATH_PERMITTED;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2190
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2191
7f561c08de6b Initial load
duke
parents:
diff changeset
  2192
7f561c08de6b Initial load
duke
parents:
diff changeset
  2193
      // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  2194
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 2, 4);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2195
      m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH) - 1, OpCodes.NODETYPE_ROOT);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2196
7f561c08de6b Initial load
duke
parents:
diff changeset
  2197
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2198
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2199
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2200
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2201
      relativePathStatus = RELATIVE_PATH_REQUIRED;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2202
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2203
7f561c08de6b Initial load
duke
parents:
diff changeset
  2204
    if (relativePathStatus != RELATIVE_PATH_NOT_PERMITTED)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2205
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2206
      if (!tokenIs('|') && (null != m_token))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2207
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2208
        RelativePathPattern();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2209
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2210
      else if (relativePathStatus == RELATIVE_PATH_REQUIRED)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2211
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2212
        // "A relative path pattern was expected."
7f561c08de6b Initial load
duke
parents:
diff changeset
  2213
        error(XPATHErrorResources.ER_EXPECTED_REL_PATH_PATTERN, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2214
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2215
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2216
7f561c08de6b Initial load
duke
parents:
diff changeset
  2217
    // Terminate for safety.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2218
    m_ops.setOp(m_ops.getOp(OpMap.MAPINDEX_LENGTH), OpCodes.ENDOP);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2219
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2220
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2221
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2222
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2223
7f561c08de6b Initial load
duke
parents:
diff changeset
  2224
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2225
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2226
   * IdKeyPattern  ::=  'id' '(' Literal ')'
7f561c08de6b Initial load
duke
parents:
diff changeset
  2227
   * | 'key' '(' Literal ',' Literal ')'
7f561c08de6b Initial load
duke
parents:
diff changeset
  2228
   * (Also handle doc())
7f561c08de6b Initial load
duke
parents:
diff changeset
  2229
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2230
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2231
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2232
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2233
  protected void IdKeyPattern() throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2234
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2235
    FunctionCall();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2236
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2237
7f561c08de6b Initial load
duke
parents:
diff changeset
  2238
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2239
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2240
   * RelativePathPattern  ::=  StepPattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  2241
   * | RelativePathPattern '/' StepPattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  2242
   * | RelativePathPattern '//' StepPattern
7f561c08de6b Initial load
duke
parents:
diff changeset
  2243
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2244
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2245
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2246
  protected void RelativePathPattern()
7f561c08de6b Initial load
duke
parents:
diff changeset
  2247
              throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2248
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2249
7f561c08de6b Initial load
duke
parents:
diff changeset
  2250
    // Caller will have consumed any '/' or '//' preceding the
7f561c08de6b Initial load
duke
parents:
diff changeset
  2251
    // RelativePathPattern, so let StepPattern know it can't begin with a '/'
7f561c08de6b Initial load
duke
parents:
diff changeset
  2252
    boolean trailingSlashConsumed = StepPattern(false);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2253
7f561c08de6b Initial load
duke
parents:
diff changeset
  2254
    while (tokenIs('/'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2255
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2256
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2257
7f561c08de6b Initial load
duke
parents:
diff changeset
  2258
      // StepPattern() may consume first slash of pair in "a//b" while
7f561c08de6b Initial load
duke
parents:
diff changeset
  2259
      // processing StepPattern "a".  On next iteration, let StepPattern know
7f561c08de6b Initial load
duke
parents:
diff changeset
  2260
      // that happened, so it doesn't match ill-formed patterns like "a///b".
7f561c08de6b Initial load
duke
parents:
diff changeset
  2261
      trailingSlashConsumed = StepPattern(!trailingSlashConsumed);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2262
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2263
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2264
7f561c08de6b Initial load
duke
parents:
diff changeset
  2265
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2266
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2267
   * StepPattern  ::=  AbbreviatedNodeTestStep
7f561c08de6b Initial load
duke
parents:
diff changeset
  2268
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2269
   * @param isLeadingSlashPermitted a boolean indicating whether a slash can
7f561c08de6b Initial load
duke
parents:
diff changeset
  2270
   *        appear at the start of this step
7f561c08de6b Initial load
duke
parents:
diff changeset
  2271
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2272
   * @return boolean indicating whether a slash following the step was consumed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2273
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2274
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2275
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2276
  protected boolean StepPattern(boolean isLeadingSlashPermitted)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2277
            throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2278
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2279
    return AbbreviatedNodeTestStep(isLeadingSlashPermitted);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2280
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2281
7f561c08de6b Initial load
duke
parents:
diff changeset
  2282
  /**
7f561c08de6b Initial load
duke
parents:
diff changeset
  2283
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2284
   * AbbreviatedNodeTestStep    ::=    '@'? NodeTest Predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  2285
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2286
   * @param isLeadingSlashPermitted a boolean indicating whether a slash can
7f561c08de6b Initial load
duke
parents:
diff changeset
  2287
   *        appear at the start of this step
7f561c08de6b Initial load
duke
parents:
diff changeset
  2288
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2289
   * @return boolean indicating whether a slash following the step was consumed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2290
   *
7f561c08de6b Initial load
duke
parents:
diff changeset
  2291
   * @throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2292
   */
7f561c08de6b Initial load
duke
parents:
diff changeset
  2293
  protected boolean AbbreviatedNodeTestStep(boolean isLeadingSlashPermitted)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2294
            throws javax.xml.transform.TransformerException
7f561c08de6b Initial load
duke
parents:
diff changeset
  2295
  {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2296
7f561c08de6b Initial load
duke
parents:
diff changeset
  2297
    int opPos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2298
    int axesType;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2299
7f561c08de6b Initial load
duke
parents:
diff changeset
  2300
    // The next blocks guarantee that a MATCH_XXX will be added.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2301
    int matchTypePos = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2302
7f561c08de6b Initial load
duke
parents:
diff changeset
  2303
    if (tokenIs('@'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2304
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2305
      axesType = OpCodes.MATCH_ATTRIBUTE;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2306
7f561c08de6b Initial load
duke
parents:
diff changeset
  2307
      appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2308
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2309
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2310
    else if (this.lookahead("::", 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2311
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2312
      if (tokenIs("attribute"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2313
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2314
        axesType = OpCodes.MATCH_ATTRIBUTE;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2315
7f561c08de6b Initial load
duke
parents:
diff changeset
  2316
        appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2317
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2318
      else if (tokenIs("child"))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2319
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2320
        matchTypePos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2321
        axesType = OpCodes.MATCH_IMMEDIATE_ANCESTOR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2322
7f561c08de6b Initial load
duke
parents:
diff changeset
  2323
        appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2324
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2325
      else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2326
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2327
        axesType = -1;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2328
7f561c08de6b Initial load
duke
parents:
diff changeset
  2329
        this.error(XPATHErrorResources.ER_AXES_NOT_ALLOWED,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2330
                   new Object[]{ this.m_token });
7f561c08de6b Initial load
duke
parents:
diff changeset
  2331
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2332
7f561c08de6b Initial load
duke
parents:
diff changeset
  2333
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2334
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2335
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2336
    else if (tokenIs('/'))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2337
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2338
      if (!isLeadingSlashPermitted)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2339
      {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2340
        // "A step was expected in the pattern, but '/' was encountered."
7f561c08de6b Initial load
duke
parents:
diff changeset
  2341
        error(XPATHErrorResources.ER_EXPECTED_STEP_PATTERN, null);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2342
      }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2343
      axesType = OpCodes.MATCH_ANY_ANCESTOR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2344
7f561c08de6b Initial load
duke
parents:
diff changeset
  2345
      appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2346
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2347
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2348
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2349
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2350
      matchTypePos = m_ops.getOp(OpMap.MAPINDEX_LENGTH);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2351
      axesType = OpCodes.MATCH_IMMEDIATE_ANCESTOR;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2352
7f561c08de6b Initial load
duke
parents:
diff changeset
  2353
      appendOp(2, axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2354
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2355
7f561c08de6b Initial load
duke
parents:
diff changeset
  2356
    // Make room for telling how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  2357
    m_ops.setOp(OpMap.MAPINDEX_LENGTH, m_ops.getOp(OpMap.MAPINDEX_LENGTH) + 1);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2358
7f561c08de6b Initial load
duke
parents:
diff changeset
  2359
    NodeTest(axesType);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2360
7f561c08de6b Initial load
duke
parents:
diff changeset
  2361
    // Tell how long the step is without the predicate
7f561c08de6b Initial load
duke
parents:
diff changeset
  2362
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH + 1,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2363
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2364
7f561c08de6b Initial load
duke
parents:
diff changeset
  2365
    while (tokenIs('['))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2366
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2367
      Predicate();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2368
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2369
7f561c08de6b Initial load
duke
parents:
diff changeset
  2370
    boolean trailingSlashConsumed;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2371
7f561c08de6b Initial load
duke
parents:
diff changeset
  2372
    // For "a//b", where "a" is current step, we need to mark operation of
7f561c08de6b Initial load
duke
parents:
diff changeset
  2373
    // current step as "MATCH_ANY_ANCESTOR".  Then we'll consume the first
7f561c08de6b Initial load
duke
parents:
diff changeset
  2374
    // slash and subsequent step will be treated as a MATCH_IMMEDIATE_ANCESTOR
7f561c08de6b Initial load
duke
parents:
diff changeset
  2375
    // (unless it too is followed by '//'.)
7f561c08de6b Initial load
duke
parents:
diff changeset
  2376
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
  2377
    // %REVIEW%  Following is what happens today, but I'm not sure that's
7f561c08de6b Initial load
duke
parents:
diff changeset
  2378
    // %REVIEW%  correct behaviour.  Perhaps no valid case could be constructed
7f561c08de6b Initial load
duke
parents:
diff changeset
  2379
    // %REVIEW%  where it would matter?
7f561c08de6b Initial load
duke
parents:
diff changeset
  2380
    //
7f561c08de6b Initial load
duke
parents:
diff changeset
  2381
    // If current step is on the attribute axis (e.g., "@x//b"), we won't
7f561c08de6b Initial load
duke
parents:
diff changeset
  2382
    // change the current step, and let following step be marked as
7f561c08de6b Initial load
duke
parents:
diff changeset
  2383
    // MATCH_ANY_ANCESTOR on next call instead.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2384
    if ((matchTypePos > -1) && tokenIs('/') && lookahead('/', 1))
7f561c08de6b Initial load
duke
parents:
diff changeset
  2385
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2386
      m_ops.setOp(matchTypePos, OpCodes.MATCH_ANY_ANCESTOR);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2387
7f561c08de6b Initial load
duke
parents:
diff changeset
  2388
      nextToken();
7f561c08de6b Initial load
duke
parents:
diff changeset
  2389
7f561c08de6b Initial load
duke
parents:
diff changeset
  2390
      trailingSlashConsumed = true;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2391
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2392
    else
7f561c08de6b Initial load
duke
parents:
diff changeset
  2393
    {
7f561c08de6b Initial load
duke
parents:
diff changeset
  2394
      trailingSlashConsumed = false;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2395
    }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2396
7f561c08de6b Initial load
duke
parents:
diff changeset
  2397
    // Tell how long the entire step is.
7f561c08de6b Initial load
duke
parents:
diff changeset
  2398
    m_ops.setOp(opPos + OpMap.MAPINDEX_LENGTH,
7f561c08de6b Initial load
duke
parents:
diff changeset
  2399
      m_ops.getOp(OpMap.MAPINDEX_LENGTH) - opPos);
7f561c08de6b Initial load
duke
parents:
diff changeset
  2400
7f561c08de6b Initial load
duke
parents:
diff changeset
  2401
    return trailingSlashConsumed;
7f561c08de6b Initial load
duke
parents:
diff changeset
  2402
  }
7f561c08de6b Initial load
duke
parents:
diff changeset
  2403
}