View Javadoc

1   /*
2    * $Header: /home/projects/jaxen/scm/jaxen/src/java/main/org/jaxen/saxpath/base/TokenTypes.java,v 1.5 2005/04/09 14:06:04 elharo Exp $
3    * $Revision: 1.5 $
4    * $Date: 2005/04/09 14:06:04 $
5    *
6    * ====================================================================
7    *
8    * Copyright (C) 2000-2004 bob mcwhirter & James Strachan.
9    * All rights reserved.
10   *
11   * Redistribution and use in source and binary forms, with or without
12   * modification, are permitted provided that the following conditions
13   * are met:
14   *
15   * 1. Redistributions of source code must retain the above copyright
16   *    notice, this list of conditions, and the following disclaimer.
17   *
18   * 2. Redistributions in binary form must reproduce the above copyright
19   *    notice, this list of conditions, and the disclaimer that follows
20   *    these conditions in the documentation and/or other materials
21   *    provided with the distribution.
22   *
23   * 3. The name "Jaxen" must not be used to endorse or promote products
24   *    derived from this software without prior written permission.  For
25   *    written permission, please contact license@jaxen.org.
26   *
27   * 4. Products derived from this software may not be called "Jaxen", nor
28   *    may "Jaxen" appear in their name, without prior written permission
29   *    from the Jaxen Project Management (pm@jaxen.org).
30   *
31   * In addition, we request (but do not require) that you include in the
32   * end-user documentation provided with the redistribution and/or in the
33   * software itself an acknowledgement equivalent to the following:
34   *     "This product includes software developed by the
35   *      Jaxen Project (http://www.jaxen.org/)."
36   * Alternatively, the acknowledgment may be graphical using the logos
37   * available at http://www.jaxen.org/
38   *
39   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
40   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
42   * DISCLAIMED.  IN NO EVENT SHALL THE Jaxen AUTHORS OR THE PROJECT
43   * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
44   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
45   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
46   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
47   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
48   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
49   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50   * SUCH DAMAGE.
51   *
52   * ====================================================================
53   * This software consists of voluntary contributions made by many
54   * individuals on behalf of the Jaxen Project and was originally
55   * created by bob mcwhirter <bob@werken.com> and
56   * James Strachan <jstrachan@apache.org>.  For more information on the
57   * Jaxen Project, please see <http://www.jaxen.org/>.
58   *
59   * $Id: TokenTypes.java,v 1.5 2005/04/09 14:06:04 elharo Exp $
60   */
61  
62  package org.jaxen.saxpath.base;
63  
64  import org.jaxen.JaxenRuntimeException;
65  
66  
67  
68  class TokenTypes
69  {
70      static final int LEFT_PAREN = 1;
71      static final int RIGHT_PAREN = 2;
72  
73      static final int LEFT_BRACKET = 3;
74      static final int RIGHT_BRACKET = 4;
75  
76      static final int PLUS = 5;
77      static final int MINUS = 6;
78      static final int LESS_THAN = 7;
79      static final int LESS_THAN_EQUALS = 8;
80      static final int GREATER_THAN = 9;
81      static final int GREATER_THAN_EQUALS = 10;
82  
83      static final int SLASH = 11;
84      static final int DOUBLE_SLASH = 12;
85      static final int DOT = 13;
86      static final int DOT_DOT = 14;
87  
88      static final int IDENTIFIER = 15;
89  
90      static final int AT = 16;
91      static final int PIPE = 17;
92      static final int COLON = 18;
93      static final int DOUBLE_COLON = 19;
94      static final int STAR = 20;
95  
96      static final int EQUALS = 21;
97      static final int NOT_EQUALS = 22;
98      static final int NOT = 23;
99  
100     static final int DIV = 24;
101     static final int MOD = 25;
102 
103     static final int DOLLAR = 26;
104 
105     static final int LITERAL = 27;
106 
107     static final int AND = 28;
108     static final int OR = 29;
109 
110     static final int INTEGER = 30;
111     static final int DOUBLE = 31;
112 
113     static final int COMMA = 32;
114 
115     //static final int SKIP = 99;
116     //static final int EOF = 100;
117     static final int SKIP = -2;
118     static final int EOF = -1;
119     static final int ERROR = -3;
120 
121     String getTokenText( int tokenType )
122     {
123         switch( tokenType )
124         {
125             case LEFT_PAREN:
126                 return "(";
127             case RIGHT_PAREN:
128                 return ")";
129             case LEFT_BRACKET:
130                 return "[";
131             case RIGHT_BRACKET:
132                 return "]";
133             case PLUS:
134                 return "+";
135             case MINUS:
136                 return "-";
137             case LESS_THAN:
138                 return "<";
139             case LESS_THAN_EQUALS:
140                 return "<=";
141             case GREATER_THAN:
142                 return ">";
143             case GREATER_THAN_EQUALS:
144                 return ">=";
145             case SLASH:
146                 return "/";
147             case DOUBLE_SLASH:
148                 return "//";
149             case DOT:
150                 return ".";
151             case DOT_DOT:
152                 return "..";
153             case IDENTIFIER:
154                 return "(identifier)";
155             case AT:
156                 return "@";
157             case PIPE:
158                 return "|";
159             case COLON:
160                 return ":";
161             case DOUBLE_COLON:
162                 return "::";
163             case STAR:
164                 return "*";
165 
166             case EQUALS:
167                 return "=";
168             case NOT_EQUALS:
169                 return "!=";
170             case NOT:
171                 return "!";
172             case DIV:
173                 return "div";
174             case MOD:
175                 return "mod";
176 
177             case DOLLAR:
178                 return "$";
179 
180             case LITERAL:
181                 return "(literal)";
182             case AND:
183                 return "and";
184             case OR:
185                 return "or";
186             case INTEGER:
187                 return "(integer)";
188             case DOUBLE:
189                 return "(double)";
190             case COMMA:
191                 return ",";
192             case ERROR:
193                 return "(error)";
194             default:
195                 throw new JaxenRuntimeException("Unrecognized token type: " + tokenType);
196         }
197     }
198 }