1 /*
2 * $Header$
3 * $Revision$
4 * $Date$
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$
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 // split star into two token types
100 static final int STAR_OPERATOR = 31;
101
102 static String getTokenText( int tokenType )
103 {
104 switch( tokenType )
105 {
106 case ERROR:
107 return "(error)";
108 case SKIP:
109 return "(skip)";
110 case EOF:
111 return "(eof)";
112 case 0:
113 return "Unrecognized token type: 0";
114 case EQUALS:
115 return "=";
116 case NOT_EQUALS:
117 return "!=";
118 case LESS_THAN_SIGN:
119 return "<";
120 case LESS_THAN_OR_EQUALS_SIGN:
121 return "<=";
122 case GREATER_THAN_SIGN:
123 return ">";
124 case GREATER_THAN_OR_EQUALS_SIGN:
125 return ">=";
126 case PLUS:
127 return "+";
128 case MINUS:
129 return "-";
130 case STAR:
131 return "*";
132 case STAR_OPERATOR:
133 return "*";
134 case DIV:
135 return "div";
136 case MOD:
137 return "mod";
138 case SLASH:
139 return "/";
140 case DOUBLE_SLASH:
141 return "//";
142 case DOT:
143 return ".";
144 case DOT_DOT:
145 return "..";
146 case IDENTIFIER:
147 return "(identifier)";
148 case AT:
149 return "@";
150 case PIPE:
151 return "|";
152 case COLON:
153 return ":";
154 case DOUBLE_COLON:
155 return "::";
156 case LEFT_BRACKET:
157 return "[";
158 case RIGHT_BRACKET:
159 return "]";
160 case LEFT_PAREN:
161 return "(";
162 case RIGHT_PAREN:
163 return ")";
164 case DOLLAR:
165 return "$";
166 case LITERAL:
167 return "(literal)";
168 case AND:
169 return "and";
170 case OR:
171 return "or";
172 case DOUBLE:
173 return "(double)";
174 case COMMA:
175 return ",";
176 default:
177 // This method is only called from an error handler, and only
178 // to provide an exception message. In other words, the string
179 // returned by this method is only used in an exception message.
180 // Something has already gone wrong, and is being reported.
181 // Thus there's no real reason to throw another exception here.
182 // Just return a string and this message will be reported in an
183 // exception anyway.
184 return("Unrecognized token type: " + tokenType);
185 }
186 }
187 }