]> git.saurik.com Git - apple/javascriptcore.git/blame - parser/ParserTokens.h
JavaScriptCore-1097.3.tar.gz
[apple/javascriptcore.git] / parser / ParserTokens.h
CommitLineData
14957cd0
A
1/*
2 * Copyright (C) 2010 Apple Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
6fe7ccc8
A
26#ifndef ParserTokens_h
27#define ParserTokens_h
14957cd0
A
28
29namespace JSC {
30
14957cd0 31class Identifier;
14957cd0
A
32
33enum {
34 UnaryOpTokenFlag = 64,
35 KeywordTokenFlag = 128,
36 BinaryOpTokenPrecedenceShift = 8,
37 BinaryOpTokenAllowsInPrecedenceAdditionalShift = 4,
38 BinaryOpTokenPrecedenceMask = 15 << BinaryOpTokenPrecedenceShift,
39};
40
41#define BINARY_OP_PRECEDENCE(prec) (((prec) << BinaryOpTokenPrecedenceShift) | ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift)))
42#define IN_OP_PRECEDENCE(prec) ((prec) << (BinaryOpTokenPrecedenceShift + BinaryOpTokenAllowsInPrecedenceAdditionalShift))
43
44enum JSTokenType {
45 NULLTOKEN = KeywordTokenFlag,
46 TRUETOKEN,
47 FALSETOKEN,
48 BREAK,
49 CASE,
50 DEFAULT,
51 FOR,
52 NEW,
53 VAR,
54 CONSTTOKEN,
55 CONTINUE,
56 FUNCTION,
57 RETURN,
58 IF,
59 THISTOKEN,
60 DO,
61 WHILE,
62 SWITCH,
63 WITH,
64 RESERVED,
6fe7ccc8 65 RESERVED_IF_STRICT,
14957cd0
A
66 THROW,
67 TRY,
68 CATCH,
69 FINALLY,
70 DEBUGGER,
71 ELSE,
72 OPENBRACE = 0,
73 CLOSEBRACE,
74 OPENPAREN,
75 CLOSEPAREN,
76 OPENBRACKET,
77 CLOSEBRACKET,
78 COMMA,
79 QUESTION,
80 NUMBER,
81 IDENT,
82 STRING,
83 SEMICOLON,
84 COLON,
85 DOT,
86 ERRORTOK,
87 EOFTOK,
88 EQUAL,
89 PLUSEQUAL,
90 MINUSEQUAL,
91 MULTEQUAL,
92 DIVEQUAL,
93 LSHIFTEQUAL,
94 RSHIFTEQUAL,
95 URSHIFTEQUAL,
96 ANDEQUAL,
97 MODEQUAL,
98 XOREQUAL,
99 OREQUAL,
100 LastUntaggedToken,
101
102 // Begin tagged tokens
103 PLUSPLUS = 0 | UnaryOpTokenFlag,
104 MINUSMINUS = 1 | UnaryOpTokenFlag,
105 EXCLAMATION = 2 | UnaryOpTokenFlag,
106 TILDE = 3 | UnaryOpTokenFlag,
107 AUTOPLUSPLUS = 4 | UnaryOpTokenFlag,
108 AUTOMINUSMINUS = 5 | UnaryOpTokenFlag,
109 TYPEOF = 6 | UnaryOpTokenFlag | KeywordTokenFlag,
110 VOIDTOKEN = 7 | UnaryOpTokenFlag | KeywordTokenFlag,
111 DELETETOKEN = 8 | UnaryOpTokenFlag | KeywordTokenFlag,
112 OR = 0 | BINARY_OP_PRECEDENCE(1),
113 AND = 1 | BINARY_OP_PRECEDENCE(2),
114 BITOR = 2 | BINARY_OP_PRECEDENCE(3),
115 BITXOR = 3 | BINARY_OP_PRECEDENCE(4),
116 BITAND = 4 | BINARY_OP_PRECEDENCE(5),
117 EQEQ = 5 | BINARY_OP_PRECEDENCE(6),
118 NE = 6 | BINARY_OP_PRECEDENCE(6),
119 STREQ = 7 | BINARY_OP_PRECEDENCE(6),
120 STRNEQ = 8 | BINARY_OP_PRECEDENCE(6),
121 LT = 9 | BINARY_OP_PRECEDENCE(7),
122 GT = 10 | BINARY_OP_PRECEDENCE(7),
123 LE = 11 | BINARY_OP_PRECEDENCE(7),
124 GE = 12 | BINARY_OP_PRECEDENCE(7),
125 INSTANCEOF = 13 | BINARY_OP_PRECEDENCE(7) | KeywordTokenFlag,
126 INTOKEN = 14 | IN_OP_PRECEDENCE(7) | KeywordTokenFlag,
127 LSHIFT = 15 | BINARY_OP_PRECEDENCE(8),
128 RSHIFT = 16 | BINARY_OP_PRECEDENCE(8),
129 URSHIFT = 17 | BINARY_OP_PRECEDENCE(8),
130 PLUS = 18 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag,
131 MINUS = 19 | BINARY_OP_PRECEDENCE(9) | UnaryOpTokenFlag,
132 TIMES = 20 | BINARY_OP_PRECEDENCE(10),
133 DIVIDE = 21 | BINARY_OP_PRECEDENCE(10),
134 MOD = 22 | BINARY_OP_PRECEDENCE(10)
135};
136
137union JSTokenData {
138 int intValue;
139 double doubleValue;
140 const Identifier* ident;
141};
142
143struct JSTokenInfo {
6fe7ccc8 144 JSTokenInfo() : line(0) { }
14957cd0
A
145 int line;
146 int startOffset;
147 int endOffset;
148};
149
150struct JSToken {
151 JSTokenType m_type;
152 JSTokenData m_data;
153 JSTokenInfo m_info;
154};
155
156enum JSParserStrictness { JSParseNormal, JSParseStrict };
157enum JSParserMode { JSParseProgramCode, JSParseFunctionCode };
6fe7ccc8 158
14957cd0 159}
6fe7ccc8
A
160
161
162#endif // ParserTokens_h