2 * Copyright (C) 2010, 2013 Apple Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #ifndef ParserTokens_h
27 #define ParserTokens_h
29 #include "ParserModes.h"
38 UnaryOpTokenFlag
= 64,
39 KeywordTokenFlag
= 128,
40 BinaryOpTokenPrecedenceShift
= 8,
41 BinaryOpTokenAllowsInPrecedenceAdditionalShift
= 4,
42 BinaryOpTokenPrecedenceMask
= 15 << BinaryOpTokenPrecedenceShift
,
43 ErrorTokenFlag
= 1 << (BinaryOpTokenAllowsInPrecedenceAdditionalShift
+ BinaryOpTokenPrecedenceShift
+ 7),
44 UnterminatedErrorTokenFlag
= ErrorTokenFlag
<< 1
47 #define BINARY_OP_PRECEDENCE(prec) (((prec) << BinaryOpTokenPrecedenceShift) | ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift)))
48 #define IN_OP_PRECEDENCE(prec) ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift))
51 NULLTOKEN
= KeywordTokenFlag
,
107 // Begin tagged tokens
108 PLUSPLUS
= 0 | UnaryOpTokenFlag
,
109 MINUSMINUS
= 1 | UnaryOpTokenFlag
,
110 EXCLAMATION
= 2 | UnaryOpTokenFlag
,
111 TILDE
= 3 | UnaryOpTokenFlag
,
112 AUTOPLUSPLUS
= 4 | UnaryOpTokenFlag
,
113 AUTOMINUSMINUS
= 5 | UnaryOpTokenFlag
,
114 TYPEOF
= 6 | UnaryOpTokenFlag
| KeywordTokenFlag
,
115 VOIDTOKEN
= 7 | UnaryOpTokenFlag
| KeywordTokenFlag
,
116 DELETETOKEN
= 8 | UnaryOpTokenFlag
| KeywordTokenFlag
,
117 OR
= 0 | BINARY_OP_PRECEDENCE(1),
118 AND
= 1 | BINARY_OP_PRECEDENCE(2),
119 BITOR
= 2 | BINARY_OP_PRECEDENCE(3),
120 BITXOR
= 3 | BINARY_OP_PRECEDENCE(4),
121 BITAND
= 4 | BINARY_OP_PRECEDENCE(5),
122 EQEQ
= 5 | BINARY_OP_PRECEDENCE(6),
123 NE
= 6 | BINARY_OP_PRECEDENCE(6),
124 STREQ
= 7 | BINARY_OP_PRECEDENCE(6),
125 STRNEQ
= 8 | BINARY_OP_PRECEDENCE(6),
126 LT
= 9 | BINARY_OP_PRECEDENCE(7),
127 GT
= 10 | BINARY_OP_PRECEDENCE(7),
128 LE
= 11 | BINARY_OP_PRECEDENCE(7),
129 GE
= 12 | BINARY_OP_PRECEDENCE(7),
130 INSTANCEOF
= 13 | BINARY_OP_PRECEDENCE(7) | KeywordTokenFlag
,
131 INTOKEN
= 14 | IN_OP_PRECEDENCE(7) | KeywordTokenFlag
,
132 LSHIFT
= 15 | BINARY_OP_PRECEDENCE(8),
133 RSHIFT
= 16 | BINARY_OP_PRECEDENCE(8),
134 URSHIFT
= 17 | BINARY_OP_PRECEDENCE(8),
135 PLUS
= 18 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag
,
136 MINUS
= 19 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag
,
137 TIMES
= 20 | BINARY_OP_PRECEDENCE(10),
138 DIVIDE
= 21 | BINARY_OP_PRECEDENCE(10),
139 MOD
= 22 | BINARY_OP_PRECEDENCE(10),
140 ERRORTOK
= 0 | ErrorTokenFlag
,
141 UNTERMINATED_IDENTIFIER_ESCAPE_ERRORTOK
= 0 | ErrorTokenFlag
| UnterminatedErrorTokenFlag
,
142 INVALID_IDENTIFIER_ESCAPE_ERRORTOK
= 1 | ErrorTokenFlag
,
143 UNTERMINATED_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK
= 2 | ErrorTokenFlag
| UnterminatedErrorTokenFlag
,
144 INVALID_IDENTIFIER_UNICODE_ESCAPE_ERRORTOK
= 3 | ErrorTokenFlag
,
145 UNTERMINATED_MULTILINE_COMMENT_ERRORTOK
= 4 | ErrorTokenFlag
| UnterminatedErrorTokenFlag
,
146 UNTERMINATED_NUMERIC_LITERAL_ERRORTOK
= 5 | ErrorTokenFlag
| UnterminatedErrorTokenFlag
,
147 INVALID_OCTAL_NUMBER_ERRORTOK
= 6 | ErrorTokenFlag
| UnterminatedErrorTokenFlag
,
148 INVALID_NUMERIC_LITERAL_ERRORTOK
= 7 | ErrorTokenFlag
,
149 UNTERMINATED_STRING_LITERAL_ERRORTOK
= 8 | ErrorTokenFlag
| UnterminatedErrorTokenFlag
,
150 INVALID_STRING_LITERAL_ERRORTOK
= 9 | ErrorTokenFlag
,
157 uint32_t lineStartOffset
;
160 const Identifier
* ident
;
163 struct JSTokenLocation
{
164 JSTokenLocation() : line(0), lineStartOffset(0), startOffset(0) { }
165 JSTokenLocation(const JSTokenLocation
& location
)
167 line
= location
.line
;
168 lineStartOffset
= location
.lineStartOffset
;
169 startOffset
= location
.startOffset
;
170 endOffset
= location
.endOffset
;
174 unsigned lineStartOffset
;
175 unsigned startOffset
;
182 JSTokenLocation m_location
;
187 #endif // ParserTokens_h