View Javadoc

1   /*
2    * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/saxpath/base/TokenTypes.java,v 1.12 2006/02/05 21:47:42 elharo Exp $
3    * $Revision: 1.12 $
4    * $Date: 2006/02/05 21:47:42 $
5    *
6    * ====================================================================
7    *
8    * Copyright 2000-2004 bob mcwhirter & James Strachan.
9    * All rights reserved.
10   *
11   *
12   * Redistribution and use in source and binary forms, with or without
13   * modification, are permitted provided that the following conditions are
14   * met:
15   * 
16   *   * Redistributions of source code must retain the above copyright
17   *     notice, this list of conditions and the following disclaimer.
18   * 
19   *   * Redistributions in binary form must reproduce the above copyright
20   *     notice, this list of conditions and the following disclaimer in the
21   *     documentation and/or other materials provided with the distribution.
22   * 
23   *   * Neither the name of the Jaxen Project nor the names of its
24   *     contributors may be used to endorse or promote products derived 
25   *     from this software without specific prior written permission.
26   * 
27   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
28   * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
29   * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
30   * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
31   * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
32   * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
33   * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
34   * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
35   * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
36   * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
37   * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38   *
39   * ====================================================================
40   * This software consists of voluntary contributions made by many
41   * individuals on behalf of the Jaxen Project and was originally
42   * created by bob mcwhirter <bob@werken.com> and
43   * James Strachan <jstrachan@apache.org>.  For more information on the
44   * Jaxen Project, please see <http://www.jaxen.org/>.
45   *
46   * $Id: TokenTypes.java,v 1.12 2006/02/05 21:47:42 elharo Exp $
47   */
48  
49  package org.jaxen.saxpath.base;
50  
51  
52  class TokenTypes
53  {
54      static final int EOF   = -1;
55      static final int SKIP  = -2;
56      static final int ERROR = -3;
57  
58      static final int EQUALS = 1;
59      static final int NOT_EQUALS = 2;
60      
61      static final int LESS_THAN_SIGN = 3;
62      static final int LESS_THAN_OR_EQUALS_SIGN = 4;
63      static final int GREATER_THAN_SIGN = 5;
64      static final int GREATER_THAN_OR_EQUALS_SIGN = 6;  
65      
66      static final int PLUS  = 7;
67      static final int MINUS = 8;
68      static final int STAR  = 9;
69      static final int MOD   = 10;
70      static final int DIV   = 11;
71      
72      static final int SLASH = 12;
73      static final int DOUBLE_SLASH = 13;
74      static final int DOT = 14;
75      static final int DOT_DOT = 15;
76  
77      static final int IDENTIFIER = 16;
78  
79      static final int AT = 17;
80      static final int PIPE = 18;
81      static final int COLON = 19;
82      static final int DOUBLE_COLON = 20;
83      
84      static final int LEFT_BRACKET = 21;
85      static final int RIGHT_BRACKET = 22;    
86      static final int LEFT_PAREN = 23;
87      static final int RIGHT_PAREN = 24;
88  
89      // 25 was NOT but there is no such token in XPath
90      static final int DOLLAR = 25;
91      static final int LITERAL = 26;
92      static final int AND = 27;
93      static final int OR = 28;
94  
95      // No need for an integer token type. All numbers
96      // in XPath are doubles.
97      static final int DOUBLE = 29;
98      static final int COMMA = 30;
99  
100     static String getTokenText( int tokenType )
101     {
102         switch( tokenType )
103         {
104             case ERROR:
105                 return "(error)";
106             case SKIP:
107                 return "(skip)";
108             case EOF:
109                 return "(eof)";
110             case 0:
111                 return "Unrecognized token type: 0";
112             case EQUALS:
113                 return "=";
114             case NOT_EQUALS:
115                 return "!=";
116             case LESS_THAN_SIGN:
117                 return "<";
118             case LESS_THAN_OR_EQUALS_SIGN:
119                 return "<=";
120             case GREATER_THAN_SIGN:
121                 return ">";
122             case GREATER_THAN_OR_EQUALS_SIGN:
123                 return ">=";
124             case PLUS:
125                 return "+";
126             case MINUS:
127                 return "-";
128             case STAR:
129                 return "*";
130             case DIV:
131                 return "div";
132             case MOD:
133                 return "mod";
134             case SLASH:
135                 return "/";
136             case DOUBLE_SLASH:
137                 return "//";
138             case DOT:
139                 return ".";
140             case DOT_DOT:
141                 return "..";
142             case IDENTIFIER:
143                 return "(identifier)";
144             case AT:
145                 return "@";
146             case PIPE:
147                 return "|";
148             case COLON:
149                 return ":";
150             case DOUBLE_COLON:
151                 return "::";
152             case LEFT_BRACKET:
153                 return "[";
154             case RIGHT_BRACKET:
155                 return "]";
156             case LEFT_PAREN:
157                 return "(";
158             case RIGHT_PAREN:
159                 return ")";
160             case DOLLAR:
161                 return "$";
162             case LITERAL:
163                 return "(literal)";
164             case AND:
165                 return "and";
166             case OR:
167                 return "or";
168             case DOUBLE:
169                 return "(double)";
170             case COMMA:
171                 return ",";
172             default:
173                 // This method is only called from an error handler, and only
174                 // to provide an exception message. In other words, the string
175                 // returned by this method is only used in an exception message.
176                 // Something has already gone wrong, and is being reported.
177                 // Thus there's no real reason to throw another exception here.
178                 // Just return a string and this message will be reported in an
179                 // exception anyway.
180                 return("Unrecognized token type: " + tokenType);
181         }
182     }
183 }