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