Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(242)

Side by Side Diff: pkg/front_end/lib/src/scanner/token.dart

Issue 2832403002: merge PrecedenceInfo into TokenType and update all refs (Closed)
Patch Set: rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 /** 5 /**
6 * Defines the tokens that are produced by the scanner, used by the parser, and 6 * Defines the tokens that are produced by the scanner, used by the parser, and
7 * referenced from the [AST structure](ast.dart). 7 * referenced from the [AST structure](ast.dart).
8 */ 8 */
9 import 'dart:collection'; 9 import 'dart:collection';
10 10
11 import 'package:front_end/src/base/syntactic_entity.dart'; 11 import 'package:front_end/src/base/syntactic_entity.dart';
12 import 'package:front_end/src/fasta/scanner/precedence.dart'; 12 import 'package:front_end/src/fasta/scanner/token_constants.dart';
13 import 'package:front_end/src/scanner/string_utilities.dart'; 13 import 'package:front_end/src/scanner/string_utilities.dart';
14 import 'package:front_end/src/fasta/scanner/precedence.dart' as fasta;
15 14
16 const int NO_PRECEDENCE = 0; 15 const int NO_PRECEDENCE = 0;
17 const int ASSIGNMENT_PRECEDENCE = 1; 16 const int ASSIGNMENT_PRECEDENCE = 1;
18 const int CASCADE_PRECEDENCE = 2; 17 const int CASCADE_PRECEDENCE = 2;
19 const int CONDITIONAL_PRECEDENCE = 3; 18 const int CONDITIONAL_PRECEDENCE = 3;
20 const int IF_NULL_PRECEDENCE = 4; 19 const int IF_NULL_PRECEDENCE = 4;
21 const int LOGICAL_OR_PRECEDENCE = 5; 20 const int LOGICAL_OR_PRECEDENCE = 5;
22 const int LOGICAL_AND_PRECEDENCE = 6; 21 const int LOGICAL_AND_PRECEDENCE = 6;
23 const int EQUALITY_PRECEDENCE = 7; 22 const int EQUALITY_PRECEDENCE = 7;
24 const int RELATIONAL_PRECEDENCE = 8; 23 const int RELATIONAL_PRECEDENCE = 8;
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
164 163
165 /** 164 /**
166 * The keywords in the Dart programming language. 165 * The keywords in the Dart programming language.
167 * 166 *
168 * Clients may not extend, implement or mix-in this class. 167 * Clients may not extend, implement or mix-in this class.
169 */ 168 */
170 class Keyword { 169 class Keyword {
171 static const Keyword ABSTRACT = const Keyword("abstract", isBuiltIn: true); 170 static const Keyword ABSTRACT = const Keyword("abstract", isBuiltIn: true);
172 171
173 static const Keyword AS = 172 static const Keyword AS =
174 const Keyword("as", info: fasta.AS_INFO, isBuiltIn: true); 173 const Keyword("as", info: TokenType.AS, isBuiltIn: true);
175 174
176 static const Keyword ASSERT = const Keyword("assert"); 175 static const Keyword ASSERT = const Keyword("assert");
177 176
178 static const Keyword ASYNC = const Keyword("async", isPseudo: true); 177 static const Keyword ASYNC = const Keyword("async", isPseudo: true);
179 178
180 static const Keyword AWAIT = const Keyword("await", isPseudo: true); 179 static const Keyword AWAIT = const Keyword("await", isPseudo: true);
181 180
182 static const Keyword BREAK = const Keyword("break"); 181 static const Keyword BREAK = const Keyword("break");
183 182
184 static const Keyword CASE = const Keyword("case"); 183 static const Keyword CASE = const Keyword("case");
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 228
230 static const Keyword IF = const Keyword("if"); 229 static const Keyword IF = const Keyword("if");
231 230
232 static const Keyword IMPLEMENTS = 231 static const Keyword IMPLEMENTS =
233 const Keyword("implements", isBuiltIn: true); 232 const Keyword("implements", isBuiltIn: true);
234 233
235 static const Keyword IMPORT = const Keyword("import", isBuiltIn: true); 234 static const Keyword IMPORT = const Keyword("import", isBuiltIn: true);
236 235
237 static const Keyword IN = const Keyword("in"); 236 static const Keyword IN = const Keyword("in");
238 237
239 static const Keyword IS = const Keyword("is", info: fasta.IS_INFO); 238 static const Keyword IS = const Keyword("is", info: TokenType.IS);
240 239
241 static const Keyword LIBRARY = const Keyword("library", isBuiltIn: true); 240 static const Keyword LIBRARY = const Keyword("library", isBuiltIn: true);
242 241
243 static const Keyword NATIVE = const Keyword("native", isPseudo: true); 242 static const Keyword NATIVE = const Keyword("native", isPseudo: true);
244 243
245 static const Keyword NEW = const Keyword("new"); 244 static const Keyword NEW = const Keyword("new");
246 245
247 static const Keyword NULL = const Keyword("null"); 246 static const Keyword NULL = const Keyword("null");
248 247
249 static const Keyword OF = const Keyword("of", isPseudo: true); 248 static const Keyword OF = const Keyword("of", isPseudo: true);
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 * The lexeme for the keyword. 380 * The lexeme for the keyword.
382 */ 381 */
383 final String syntax; 382 final String syntax;
384 383
385 /** 384 /**
386 * Initialize a newly created keyword. 385 * Initialize a newly created keyword.
387 */ 386 */
388 const Keyword(this.syntax, 387 const Keyword(this.syntax,
389 {this.isBuiltIn: false, 388 {this.isBuiltIn: false,
390 this.isPseudo: false, 389 this.isPseudo: false,
391 this.info: fasta.KEYWORD_INFO}); 390 this.info: TokenType.KEYWORD});
392 391
393 bool get isBuiltInOrPseudo => isBuiltIn || isPseudo; 392 bool get isBuiltInOrPseudo => isBuiltIn || isPseudo;
394 393
395 /** 394 /**
396 * A flag indicating whether the keyword is "built-in" identifier. 395 * A flag indicating whether the keyword is "built-in" identifier.
397 * This method exists for backward compatibility and will be removed. 396 * This method exists for backward compatibility and will be removed.
398 * Use [isBuiltIn] instead. 397 * Use [isBuiltIn] instead.
399 */ 398 */
400 @deprecated 399 @deprecated
401 bool get isPseudoKeyword => isBuiltIn; // TODO (danrubel): remove this 400 bool get isPseudoKeyword => isBuiltIn; // TODO (danrubel): remove this
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 997
999 /** 998 /**
1000 * The types of tokens that can be returned by the scanner. 999 * The types of tokens that can be returned by the scanner.
1001 * 1000 *
1002 * Clients may not extend, implement or mix-in this class. 1001 * Clients may not extend, implement or mix-in this class.
1003 */ 1002 */
1004 class TokenType { 1003 class TokenType {
1005 /** 1004 /**
1006 * The type of the token that marks the start or end of the input. 1005 * The type of the token that marks the start or end of the input.
1007 */ 1006 */
1008 static const TokenType EOF = fasta.EOF_INFO; 1007 static const TokenType EOF =
1009 1008 const TokenType('', 'EOF', NO_PRECEDENCE, EOF_TOKEN);
1010 static const TokenType DOUBLE = fasta.DOUBLE_INFO; 1009
1011 1010 static const TokenType DOUBLE =
1012 static const TokenType HEXADECIMAL = fasta.HEXADECIMAL_INFO; 1011 const TokenType('double', 'DOUBLE', NO_PRECEDENCE, DOUBLE_TOKEN);
1013 1012
1014 static const TokenType IDENTIFIER = fasta.IDENTIFIER_INFO; 1013 static const TokenType HEXADECIMAL = const TokenType(
1015 1014 'hexadecimal', 'HEXADECIMAL', NO_PRECEDENCE, HEXADECIMAL_TOKEN);
1016 static const TokenType INT = fasta.INT_INFO; 1015
1017 1016 static const TokenType IDENTIFIER = const TokenType(
1018 static const TokenType KEYWORD = fasta.KEYWORD_INFO; 1017 'identifier', 'STRING_INT', NO_PRECEDENCE, IDENTIFIER_TOKEN);
1019 1018
1020 static const TokenType MULTI_LINE_COMMENT = fasta.MULTI_LINE_COMMENT_INFO; 1019 static const TokenType INT =
1021 1020 const TokenType('int', 'INT', NO_PRECEDENCE, INT_TOKEN);
1022 static const TokenType SCRIPT_TAG = fasta.SCRIPT_INFO; 1021
1023 1022 static const TokenType KEYWORD =
1024 static const TokenType SINGLE_LINE_COMMENT = fasta.SINGLE_LINE_COMMENT_INFO; 1023 const TokenType('keyword', 'KEYWORD', NO_PRECEDENCE, KEYWORD_TOKEN);
1025 1024
1026 static const TokenType STRING = fasta.STRING_INFO; 1025 static const TokenType MULTI_LINE_COMMENT = const TokenType(
1027 1026 'comment', 'MULTI_LINE_COMMENT', NO_PRECEDENCE, COMMENT_TOKEN);
1028 static const TokenType AMPERSAND = fasta.AMPERSAND_INFO; 1027
1029 1028 static const TokenType SCRIPT_TAG =
1030 static const TokenType AMPERSAND_AMPERSAND = fasta.AMPERSAND_AMPERSAND_INFO; 1029 const TokenType('script', 'SCRIPT_TAG', NO_PRECEDENCE, SCRIPT_TOKEN);
1031 1030
1031 static const TokenType SINGLE_LINE_COMMENT = const TokenType(
1032 'comment', 'SINGLE_LINE_COMMENT', NO_PRECEDENCE, COMMENT_TOKEN);
1033
1034 static const TokenType STRING =
1035 const TokenType('string', 'STRING', NO_PRECEDENCE, STRING_TOKEN);
1036
1037 static const TokenType AMPERSAND = const TokenType(
1038 '&', 'AMPERSAND', BITWISE_AND_PRECEDENCE, AMPERSAND_TOKEN,
1039 isOperator: true, isUserDefinableOperator: true);
1040
1041 static const TokenType AMPERSAND_AMPERSAND = const TokenType('&&',
1042 'AMPERSAND_AMPERSAND', LOGICAL_AND_PRECEDENCE, AMPERSAND_AMPERSAND_TOKEN,
1043 isOperator: true);
1044
1045 // This is not yet part of the language and not supported by fasta
1032 static const TokenType AMPERSAND_AMPERSAND_EQ = 1046 static const TokenType AMPERSAND_AMPERSAND_EQ =
1033 const TokenType('&&=', 'AMPERSAND_AMPERSAND_EQ', 1, -1); 1047 const TokenType('&&=', 'AMPERSAND_AMPERSAND_EQ', 1, -1);
1034 1048
1035 static const TokenType AMPERSAND_EQ = fasta.AMPERSAND_EQ_INFO; 1049 static const TokenType AMPERSAND_EQ = const TokenType(
1036 1050 '&=', 'AMPERSAND_EQ', ASSIGNMENT_PRECEDENCE, AMPERSAND_EQ_TOKEN,
1037 static const TokenType AT = fasta.AT_INFO; 1051 isOperator: true);
1038 1052
1039 static const TokenType BANG = fasta.BANG_INFO; 1053 static const TokenType AT =
1040 1054 const TokenType('@', 'AT', NO_PRECEDENCE, AT_TOKEN);
1041 static const TokenType BANG_EQ = fasta.BANG_EQ_INFO; 1055
1042 1056 static const TokenType BANG = const TokenType(
1043 static const TokenType BAR = fasta.BAR_INFO; 1057 '!', 'BANG', PREFIX_PRECEDENCE, BANG_TOKEN,
1044 1058 isOperator: true);
1045 static const TokenType BAR_BAR = fasta.BAR_BAR_INFO; 1059
1046 1060 static const TokenType BANG_EQ = const TokenType(
1061 '!=', 'BANG_EQ', EQUALITY_PRECEDENCE, BANG_EQ_TOKEN,
1062 isOperator: true);
1063
1064 static const TokenType BANG_EQ_EQ = const TokenType(
1065 '!==', 'BANG_EQ_EQ', EQUALITY_PRECEDENCE, BANG_EQ_EQ_TOKEN);
1066
1067 static const TokenType BAR = const TokenType(
1068 '|', 'BAR', BITWISE_OR_PRECEDENCE, BAR_TOKEN,
1069 isOperator: true, isUserDefinableOperator: true);
1070
1071 static const TokenType BAR_BAR = const TokenType(
1072 '||', 'BAR_BAR', LOGICAL_OR_PRECEDENCE, BAR_BAR_TOKEN,
1073 isOperator: true);
1074
1075 // This is not yet part of the language and not supported by fasta
1047 static const TokenType BAR_BAR_EQ = 1076 static const TokenType BAR_BAR_EQ =
1048 const TokenType('||=', 'BAR_BAR_EQ', 1, -1); 1077 const TokenType('||=', 'BAR_BAR_EQ', 1, -1);
1049 1078
1050 static const TokenType BAR_EQ = fasta.BAR_EQ_INFO; 1079 static const TokenType BAR_EQ = const TokenType(
1051 1080 '|=', 'BAR_EQ', ASSIGNMENT_PRECEDENCE, BAR_EQ_TOKEN,
1052 static const TokenType COLON = fasta.COLON_INFO; 1081 isOperator: true);
1053 1082
1054 static const TokenType COMMA = fasta.COMMA_INFO; 1083 static const TokenType COLON =
1055 1084 const TokenType(':', 'COLON', NO_PRECEDENCE, COLON_TOKEN);
1056 static const TokenType CARET = fasta.CARET_INFO; 1085
1057 1086 static const TokenType COMMA =
1058 static const TokenType CARET_EQ = fasta.CARET_EQ_INFO; 1087 const TokenType(',', 'COMMA', NO_PRECEDENCE, COMMA_TOKEN);
1059 1088
1060 static const TokenType CLOSE_CURLY_BRACKET = fasta.CLOSE_CURLY_BRACKET_INFO; 1089 static const TokenType CARET = const TokenType(
1061 1090 '^', 'CARET', BITWISE_XOR_PRECEDENCE, CARET_TOKEN,
1062 static const TokenType CLOSE_PAREN = fasta.CLOSE_PAREN_INFO; 1091 isOperator: true, isUserDefinableOperator: true);
1063 1092
1064 static const TokenType CLOSE_SQUARE_BRACKET = fasta.CLOSE_SQUARE_BRACKET_INFO; 1093 static const TokenType CARET_EQ = const TokenType(
1065 1094 '^=', 'CARET_EQ', ASSIGNMENT_PRECEDENCE, CARET_EQ_TOKEN,
1066 static const TokenType EQ = fasta.EQ_INFO; 1095 isOperator: true);
1067 1096
1068 static const TokenType EQ_EQ = fasta.EQ_EQ_INFO; 1097 static const TokenType CLOSE_CURLY_BRACKET = const TokenType(
1069 1098 '}', 'CLOSE_CURLY_BRACKET', NO_PRECEDENCE, CLOSE_CURLY_BRACKET_TOKEN);
1070 static const TokenType FUNCTION = fasta.FUNCTION_INFO; 1099
1071 1100 static const TokenType CLOSE_PAREN =
1072 static const TokenType GT = fasta.GT_INFO; 1101 const TokenType(')', 'CLOSE_PAREN', NO_PRECEDENCE, CLOSE_PAREN_TOKEN);
1073 1102
1074 static const TokenType GT_EQ = fasta.GT_EQ_INFO; 1103 static const TokenType CLOSE_SQUARE_BRACKET = const TokenType(
1075 1104 ']', 'CLOSE_SQUARE_BRACKET', NO_PRECEDENCE, CLOSE_SQUARE_BRACKET_TOKEN);
1076 static const TokenType GT_GT = fasta.GT_GT_INFO; 1105
1077 1106 static const TokenType EQ = const TokenType(
1078 static const TokenType GT_GT_EQ = fasta.GT_GT_EQ_INFO; 1107 '=', 'EQ', ASSIGNMENT_PRECEDENCE, EQ_TOKEN,
1079 1108 isOperator: true);
1080 static const TokenType HASH = fasta.HASH_INFO; 1109
1081 1110 static const TokenType EQ_EQ = const TokenType(
1082 static const TokenType INDEX = fasta.INDEX_INFO; 1111 '==', 'EQ_EQ', EQUALITY_PRECEDENCE, EQ_EQ_TOKEN,
1083 1112 isOperator: true, isUserDefinableOperator: true);
1084 static const TokenType INDEX_EQ = fasta.INDEX_EQ_INFO; 1113
1085 1114 static const TokenType EQ_EQ_EQ =
1086 static const TokenType LT = fasta.LT_INFO; 1115 const TokenType('===', 'EQ_EQ_EQ', EQUALITY_PRECEDENCE, EQ_EQ_EQ_TOKEN);
1087 1116
1088 static const TokenType LT_EQ = fasta.LT_EQ_INFO; 1117 static const TokenType FUNCTION =
1089 1118 const TokenType('=>', 'FUNCTION', NO_PRECEDENCE, FUNCTION_TOKEN);
1090 static const TokenType LT_LT = fasta.LT_LT_INFO; 1119
1091 1120 static const TokenType GT = const TokenType(
1092 static const TokenType LT_LT_EQ = fasta.LT_LT_EQ_INFO; 1121 '>', 'GT', RELATIONAL_PRECEDENCE, GT_TOKEN,
1093 1122 isOperator: true, isUserDefinableOperator: true);
1094 static const TokenType MINUS = fasta.MINUS_INFO; 1123
1095 1124 static const TokenType GT_EQ = const TokenType(
1096 static const TokenType MINUS_EQ = fasta.MINUS_EQ_INFO; 1125 '>=', 'GT_EQ', RELATIONAL_PRECEDENCE, GT_EQ_TOKEN,
1097 1126 isOperator: true, isUserDefinableOperator: true);
1098 static const TokenType MINUS_MINUS = fasta.MINUS_MINUS_INFO; 1127
1099 1128 static const TokenType GT_GT = const TokenType(
1100 static const TokenType OPEN_CURLY_BRACKET = fasta.OPEN_CURLY_BRACKET_INFO; 1129 '>>', 'GT_GT', SHIFT_PRECEDENCE, GT_GT_TOKEN,
1101 1130 isOperator: true, isUserDefinableOperator: true);
1102 static const TokenType OPEN_PAREN = fasta.OPEN_PAREN_INFO; 1131
1103 1132 static const TokenType GT_GT_EQ = const TokenType(
1104 static const TokenType OPEN_SQUARE_BRACKET = fasta.OPEN_SQUARE_BRACKET_INFO; 1133 '>>=', 'GT_GT_EQ', ASSIGNMENT_PRECEDENCE, GT_GT_EQ_TOKEN,
1105 1134 isOperator: true);
1106 static const TokenType PERCENT = fasta.PERCENT_INFO; 1135
1107 1136 static const TokenType HASH =
1108 static const TokenType PERCENT_EQ = fasta.PERCENT_EQ_INFO; 1137 const TokenType('#', 'HASH', NO_PRECEDENCE, HASH_TOKEN);
1109 1138
1110 static const TokenType PERIOD = fasta.PERIOD_INFO; 1139 static const TokenType INDEX = const TokenType(
1111 1140 '[]', 'INDEX', NO_PRECEDENCE, INDEX_TOKEN,
1112 static const TokenType PERIOD_PERIOD = fasta.PERIOD_PERIOD_INFO; 1141 isOperator: true, isUserDefinableOperator: true);
1113 1142
1114 static const TokenType PLUS = fasta.PLUS_INFO; 1143 static const TokenType INDEX_EQ = const TokenType(
1115 1144 '[]=', 'INDEX_EQ', NO_PRECEDENCE, INDEX_EQ_TOKEN,
1116 static const TokenType PLUS_EQ = fasta.PLUS_EQ_INFO; 1145 isOperator: true, isUserDefinableOperator: true);
1117 1146
1118 static const TokenType PLUS_PLUS = fasta.PLUS_PLUS_INFO; 1147 static const TokenType LT = const TokenType(
1119 1148 '<', 'LT', RELATIONAL_PRECEDENCE, LT_TOKEN,
1120 static const TokenType QUESTION = fasta.QUESTION_INFO; 1149 isOperator: true, isUserDefinableOperator: true);
1121 1150
1122 static const TokenType QUESTION_PERIOD = fasta.QUESTION_PERIOD_INFO; 1151 static const TokenType LT_EQ = const TokenType(
1123 1152 '<=', 'LT_EQ', RELATIONAL_PRECEDENCE, LT_EQ_TOKEN,
1124 static const TokenType QUESTION_QUESTION = fasta.QUESTION_QUESTION_INFO; 1153 isOperator: true, isUserDefinableOperator: true);
1125 1154
1126 static const TokenType QUESTION_QUESTION_EQ = fasta.QUESTION_QUESTION_EQ_INFO; 1155 static const TokenType LT_LT = const TokenType(
1127 1156 '<<', 'LT_LT', SHIFT_PRECEDENCE, LT_LT_TOKEN,
1128 static const TokenType SEMICOLON = fasta.SEMICOLON_INFO; 1157 isOperator: true, isUserDefinableOperator: true);
1129 1158
1130 static const TokenType SLASH = fasta.SLASH_INFO; 1159 static const TokenType LT_LT_EQ = const TokenType(
1131 1160 '<<=', 'LT_LT_EQ', ASSIGNMENT_PRECEDENCE, LT_LT_EQ_TOKEN,
1132 static const TokenType SLASH_EQ = fasta.SLASH_EQ_INFO; 1161 isOperator: true);
1133 1162
1134 static const TokenType STAR = fasta.STAR_INFO; 1163 static const TokenType MINUS = const TokenType(
1135 1164 '-', 'MINUS', ADDITIVE_PRECEDENCE, MINUS_TOKEN,
1136 static const TokenType STAR_EQ = fasta.STAR_EQ_INFO; 1165 isOperator: true, isUserDefinableOperator: true);
1137 1166
1138 static const TokenType STRING_INTERPOLATION_EXPRESSION = 1167 static const TokenType MINUS_EQ = const TokenType(
1139 fasta.STRING_INTERPOLATION_INFO; 1168 '-=', 'MINUS_EQ', ASSIGNMENT_PRECEDENCE, MINUS_EQ_TOKEN,
1140 1169 isOperator: true);
1141 static const TokenType STRING_INTERPOLATION_IDENTIFIER = 1170
1142 fasta.STRING_INTERPOLATION_IDENTIFIER_INFO; 1171 static const TokenType MINUS_MINUS = const TokenType(
1143 1172 '--', 'MINUS_MINUS', POSTFIX_PRECEDENCE, MINUS_MINUS_TOKEN,
1144 static const TokenType TILDE = fasta.TILDE_INFO; 1173 isOperator: true);
1145 1174
1146 static const TokenType TILDE_SLASH = fasta.TILDE_SLASH_INFO; 1175 static const TokenType OPEN_CURLY_BRACKET = const TokenType(
1147 1176 '{', 'OPEN_CURLY_BRACKET', NO_PRECEDENCE, OPEN_CURLY_BRACKET_TOKEN);
1148 static const TokenType TILDE_SLASH_EQ = fasta.TILDE_SLASH_EQ_INFO; 1177
1149 1178 static const TokenType OPEN_PAREN =
1150 static const TokenType BACKPING = fasta.BACKPING_INFO; 1179 const TokenType('(', 'OPEN_PAREN', POSTFIX_PRECEDENCE, OPEN_PAREN_TOKEN);
1151 1180
1152 static const TokenType BACKSLASH = fasta.BACKSLASH_INFO; 1181 static const TokenType OPEN_SQUARE_BRACKET = const TokenType('[',
1153 1182 'OPEN_SQUARE_BRACKET', POSTFIX_PRECEDENCE, OPEN_SQUARE_BRACKET_TOKEN);
1154 static const TokenType PERIOD_PERIOD_PERIOD = fasta.PERIOD_PERIOD_PERIOD_INFO; 1183
1155 1184 static const TokenType PERCENT = const TokenType(
1156 static const TokenType GENERIC_METHOD_TYPE_LIST = 1185 '%', 'PERCENT', MULTIPLICATIVE_PRECEDENCE, PERCENT_TOKEN,
1157 fasta.GENERIC_METHOD_TYPE_LIST; 1186 isOperator: true, isUserDefinableOperator: true);
1158 1187
1159 static const TokenType GENERIC_METHOD_TYPE_ASSIGN = 1188 static const TokenType PERCENT_EQ = const TokenType(
1160 fasta.GENERIC_METHOD_TYPE_ASSIGN; 1189 '%=', 'PERCENT_EQ', ASSIGNMENT_PRECEDENCE, PERCENT_EQ_TOKEN,
1161 1190 isOperator: true);
1191
1192 static const TokenType PERIOD =
1193 const TokenType('.', 'PERIOD', POSTFIX_PRECEDENCE, PERIOD_TOKEN);
1194
1195 static const TokenType PERIOD_PERIOD = const TokenType(
1196 '..', 'PERIOD_PERIOD', CASCADE_PRECEDENCE, PERIOD_PERIOD_TOKEN,
1197 isOperator: true);
1198
1199 static const TokenType PLUS = const TokenType(
1200 '+', 'PLUS', ADDITIVE_PRECEDENCE, PLUS_TOKEN,
1201 isOperator: true, isUserDefinableOperator: true);
1202
1203 static const TokenType PLUS_EQ = const TokenType(
1204 '+=', 'PLUS_EQ', ASSIGNMENT_PRECEDENCE, PLUS_EQ_TOKEN,
1205 isOperator: true);
1206
1207 static const TokenType PLUS_PLUS = const TokenType(
1208 '++', 'PLUS_PLUS', POSTFIX_PRECEDENCE, PLUS_PLUS_TOKEN,
1209 isOperator: true);
1210
1211 static const TokenType QUESTION = const TokenType(
1212 '?', 'QUESTION', CONDITIONAL_PRECEDENCE, QUESTION_TOKEN,
1213 isOperator: true);
1214
1215 static const TokenType QUESTION_PERIOD = const TokenType(
1216 '?.', 'QUESTION_PERIOD', POSTFIX_PRECEDENCE, QUESTION_PERIOD_TOKEN,
1217 isOperator: true);
1218
1219 static const TokenType QUESTION_QUESTION = const TokenType(
1220 '??', 'QUESTION_QUESTION', IF_NULL_PRECEDENCE, QUESTION_QUESTION_TOKEN,
1221 isOperator: true);
1222
1223 static const TokenType QUESTION_QUESTION_EQ = const TokenType('??=',
1224 'QUESTION_QUESTION_EQ', ASSIGNMENT_PRECEDENCE, QUESTION_QUESTION_EQ_TOKEN,
1225 isOperator: true);
1226
1227 static const TokenType SEMICOLON =
1228 const TokenType(';', 'SEMICOLON', NO_PRECEDENCE, SEMICOLON_TOKEN);
1229
1230 static const TokenType SLASH = const TokenType(
1231 '/', 'SLASH', MULTIPLICATIVE_PRECEDENCE, SLASH_TOKEN,
1232 isOperator: true, isUserDefinableOperator: true);
1233
1234 static const TokenType SLASH_EQ = const TokenType(
1235 '/=', 'SLASH_EQ', ASSIGNMENT_PRECEDENCE, SLASH_EQ_TOKEN,
1236 isOperator: true);
1237
1238 static const TokenType STAR = const TokenType(
1239 '*', 'STAR', MULTIPLICATIVE_PRECEDENCE, STAR_TOKEN,
1240 isOperator: true, isUserDefinableOperator: true);
1241
1242 static const TokenType STAR_EQ = const TokenType(
1243 '*=', 'STAR_EQ', ASSIGNMENT_PRECEDENCE, STAR_EQ_TOKEN,
1244 isOperator: true);
1245
1246 static const TokenType STRING_INTERPOLATION_EXPRESSION = const TokenType(
1247 '\${',
1248 'STRING_INTERPOLATION_EXPRESSION',
1249 NO_PRECEDENCE,
1250 STRING_INTERPOLATION_TOKEN);
1251
1252 static const TokenType STRING_INTERPOLATION_IDENTIFIER = const TokenType(
1253 '\$',
1254 'STRING_INTERPOLATION_IDENTIFIER',
1255 NO_PRECEDENCE,
1256 STRING_INTERPOLATION_IDENTIFIER_TOKEN);
1257
1258 static const TokenType TILDE = const TokenType(
1259 '~', 'TILDE', PREFIX_PRECEDENCE, TILDE_TOKEN,
1260 isOperator: true, isUserDefinableOperator: true);
1261
1262 static const TokenType TILDE_SLASH = const TokenType(
1263 '~/', 'TILDE_SLASH', MULTIPLICATIVE_PRECEDENCE, TILDE_SLASH_TOKEN,
1264 isOperator: true, isUserDefinableOperator: true);
1265
1266 static const TokenType TILDE_SLASH_EQ = const TokenType(
1267 '~/=', 'TILDE_SLASH_EQ', ASSIGNMENT_PRECEDENCE, TILDE_SLASH_EQ_TOKEN,
1268 isOperator: true);
1269
1270 static const TokenType BACKPING =
1271 const TokenType('`', 'BACKPING', NO_PRECEDENCE, BACKPING_TOKEN);
1272
1273 static const TokenType BACKSLASH =
1274 const TokenType('\\', 'BACKSLASH', NO_PRECEDENCE, BACKSLASH_TOKEN);
1275
1276 static const TokenType PERIOD_PERIOD_PERIOD = const TokenType(
1277 '...', 'PERIOD_PERIOD_PERIOD', NO_PRECEDENCE, PERIOD_PERIOD_PERIOD_TOKEN);
1278
1279 static const TokenType GENERIC_METHOD_TYPE_LIST = const TokenType(
1280 'generic_comment_list',
1281 'GENERIC_METHOD_TYPE_LIST',
1282 NO_PRECEDENCE,
1283 GENERIC_METHOD_TYPE_LIST_TOKEN);
1284
1285 static const TokenType GENERIC_METHOD_TYPE_ASSIGN = const TokenType(
1286 'generic_comment_assign',
1287 'GENERIC_METHOD_TYPE_ASSIGN',
1288 NO_PRECEDENCE,
1289 GENERIC_METHOD_TYPE_ASSIGN_TOKEN);
1290
1291 static const TokenType AS =
1292 const TokenType('as', 'AS', RELATIONAL_PRECEDENCE, KEYWORD_TOKEN);
1293
1294 static const TokenType IS =
1295 const TokenType('is', 'IS', RELATIONAL_PRECEDENCE, KEYWORD_TOKEN);
1296
1297 /**
1298 * Token type used by error tokens.
1299 */
1300 static const TokenType BAD_INPUT = const TokenType(
1301 'malformed input', 'BAD_INPUT', NO_PRECEDENCE, BAD_INPUT_TOKEN);
1302
1303 /**
1304 * Token type used by synthetic tokens that are created during parser
1305 * recovery (non-analyzer use case).
1306 */
1307 static const TokenType RECOVERY =
1308 const TokenType('recovery', 'RECOVERY', NO_PRECEDENCE, RECOVERY_TOKEN);
1309
1310 // TODO(danrubel): "all" is misleading
1311 // because this list does not include all TokenType instances.
1162 static const List<TokenType> all = const <TokenType>[ 1312 static const List<TokenType> all = const <TokenType>[
1163 TokenType.EOF, 1313 TokenType.EOF,
1164 TokenType.DOUBLE, 1314 TokenType.DOUBLE,
1165 TokenType.HEXADECIMAL, 1315 TokenType.HEXADECIMAL,
1166 TokenType.IDENTIFIER, 1316 TokenType.IDENTIFIER,
1167 TokenType.INT, 1317 TokenType.INT,
1168 TokenType.KEYWORD, 1318 TokenType.KEYWORD,
1169 TokenType.MULTI_LINE_COMMENT, 1319 TokenType.MULTI_LINE_COMMENT,
1170 TokenType.SCRIPT_TAG, 1320 TokenType.SCRIPT_TAG,
1171 TokenType.SINGLE_LINE_COMMENT, 1321 TokenType.SINGLE_LINE_COMMENT,
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1226 TokenType.STRING_INTERPOLATION_IDENTIFIER, 1376 TokenType.STRING_INTERPOLATION_IDENTIFIER,
1227 TokenType.TILDE, 1377 TokenType.TILDE,
1228 TokenType.TILDE_SLASH, 1378 TokenType.TILDE_SLASH,
1229 TokenType.TILDE_SLASH_EQ, 1379 TokenType.TILDE_SLASH_EQ,
1230 TokenType.BACKPING, 1380 TokenType.BACKPING,
1231 TokenType.BACKSLASH, 1381 TokenType.BACKSLASH,
1232 TokenType.PERIOD_PERIOD_PERIOD, 1382 TokenType.PERIOD_PERIOD_PERIOD,
1233 TokenType.GENERIC_METHOD_TYPE_LIST, 1383 TokenType.GENERIC_METHOD_TYPE_LIST,
1234 TokenType.GENERIC_METHOD_TYPE_ASSIGN, 1384 TokenType.GENERIC_METHOD_TYPE_ASSIGN,
1235 1385
1386 // TODO(danrubel): Should these be added to the "all" list?
1387 //TokenType.IS,
1388 //TokenType.AS,
1389
1236 // These are not yet part of the language and not supported by fasta 1390 // These are not yet part of the language and not supported by fasta
1237 //TokenType.AMPERSAND_AMPERSAND_EQ, 1391 //TokenType.AMPERSAND_AMPERSAND_EQ,
1238 //TokenType.BAR_BAR_EQ, 1392 //TokenType.BAR_BAR_EQ,
1393
1394 // Supported by fasta but not part of the language
1395 //TokenType.BANG_EQ_EQ,
1396 //TokenType.EQ_EQ_EQ,
1397
1398 // Used by synthetic tokens generated during recovery
1399 //TokenType.BAD_INPUT,
1400 //TokenType.RECOVERY,
1239 ]; 1401 ];
1240 1402
1241 final int kind; 1403 final int kind;
1242 1404
1243 /** 1405 /**
1244 * `true` if this token type represents an operator. 1406 * `true` if this token type represents an operator.
1245 */ 1407 */
1246 final bool isOperator; 1408 final bool isOperator;
1247 1409
1248 /** 1410 /**
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 * true: `(a * b) * c == a * (b * c)`. In other words, if the result of 1449 * true: `(a * b) * c == a * (b * c)`. In other words, if the result of
1288 * applying the operator to multiple operands does not depend on the order in 1450 * applying the operator to multiple operands does not depend on the order in
1289 * which those applications occur. 1451 * which those applications occur.
1290 * 1452 *
1291 * Note: This method considers the logical-and and logical-or operators to be 1453 * Note: This method considers the logical-and and logical-or operators to be
1292 * associative, even though the order in which the application of those 1454 * associative, even though the order in which the application of those
1293 * operators can have an effect because evaluation of the right-hand operand 1455 * operators can have an effect because evaluation of the right-hand operand
1294 * is conditional. 1456 * is conditional.
1295 */ 1457 */
1296 bool get isAssociativeOperator => 1458 bool get isAssociativeOperator =>
1297 this == AMPERSAND_INFO || 1459 this == TokenType.AMPERSAND ||
1298 this == AMPERSAND_AMPERSAND_INFO || 1460 this == TokenType.AMPERSAND_AMPERSAND ||
1299 this == BAR_INFO || 1461 this == TokenType.BAR ||
1300 this == BAR_BAR_INFO || 1462 this == TokenType.BAR_BAR ||
1301 this == CARET_INFO || 1463 this == TokenType.CARET ||
1302 this == PLUS_INFO || 1464 this == TokenType.PLUS ||
1303 this == STAR_INFO; 1465 this == TokenType.STAR;
1304 1466
1305 /** 1467 /**
1306 * Return `true` if this type of token represents an equality operator. 1468 * Return `true` if this type of token represents an equality operator.
1307 */ 1469 */
1308 bool get isEqualityOperator => this == BANG_EQ_INFO || this == EQ_EQ_INFO; 1470 bool get isEqualityOperator =>
1471 this == TokenType.BANG_EQ || this == TokenType.EQ_EQ;
1309 1472
1310 /** 1473 /**
1311 * Return `true` if this type of token represents an increment operator. 1474 * Return `true` if this type of token represents an increment operator.
1312 */ 1475 */
1313 bool get isIncrementOperator => 1476 bool get isIncrementOperator =>
1314 this == PLUS_PLUS_INFO || this == MINUS_MINUS_INFO; 1477 this == TokenType.PLUS_PLUS || this == TokenType.MINUS_MINUS;
1315 1478
1316 /** 1479 /**
1317 * Return `true` if this type of token represents a multiplicative operator. 1480 * Return `true` if this type of token represents a multiplicative operator.
1318 */ 1481 */
1319 bool get isMultiplicativeOperator => precedence == MULTIPLICATIVE_PRECEDENCE; 1482 bool get isMultiplicativeOperator => precedence == MULTIPLICATIVE_PRECEDENCE;
1320 1483
1321 /** 1484 /**
1322 * Return `true` if this type of token represents a relational operator. 1485 * Return `true` if this type of token represents a relational operator.
1323 */ 1486 */
1324 bool get isRelationalOperator => 1487 bool get isRelationalOperator =>
1325 this == LT_INFO || 1488 this == TokenType.LT ||
1326 this == LT_EQ_INFO || 1489 this == TokenType.LT_EQ ||
1327 this == GT_INFO || 1490 this == TokenType.GT ||
1328 this == GT_EQ_INFO; 1491 this == TokenType.GT_EQ;
1329 1492
1330 /** 1493 /**
1331 * Return `true` if this type of token represents a shift operator. 1494 * Return `true` if this type of token represents a shift operator.
1332 */ 1495 */
1333 bool get isShiftOperator => precedence == SHIFT_PRECEDENCE; 1496 bool get isShiftOperator => precedence == SHIFT_PRECEDENCE;
1334 1497
1335 /** 1498 /**
1336 * Return `true` if this type of token represents a unary postfix operator. 1499 * Return `true` if this type of token represents a unary postfix operator.
1337 */ 1500 */
1338 bool get isUnaryPostfixOperator => precedence == POSTFIX_PRECEDENCE; 1501 bool get isUnaryPostfixOperator => precedence == POSTFIX_PRECEDENCE;
1339 1502
1340 /** 1503 /**
1341 * Return `true` if this type of token represents a unary prefix operator. 1504 * Return `true` if this type of token represents a unary prefix operator.
1342 */ 1505 */
1343 bool get isUnaryPrefixOperator => 1506 bool get isUnaryPrefixOperator =>
1344 precedence == PREFIX_PRECEDENCE || 1507 precedence == PREFIX_PRECEDENCE ||
1345 this == PLUS_PLUS_INFO || 1508 this == TokenType.PLUS_PLUS ||
1346 this == MINUS_MINUS_INFO; 1509 this == TokenType.MINUS_MINUS;
1347 1510
1348 @override 1511 @override
1349 String toString() => name; 1512 String toString() => name;
1350 1513
1351 /** 1514 /**
1352 * Use [lexeme] instead of this method 1515 * Use [lexeme] instead of this method
1353 */ 1516 */
1354 @deprecated 1517 @deprecated
1355 String get value => lexeme; 1518 String get value => lexeme;
1356 } 1519 }
(...skipping 22 matching lines...) Expand all
1379 1542
1380 void set precedingComments(CommentToken comment) { 1543 void set precedingComments(CommentToken comment) {
1381 _precedingComment = comment; 1544 _precedingComment = comment;
1382 _setCommentParent(_precedingComment); 1545 _setCommentParent(_precedingComment);
1383 } 1546 }
1384 1547
1385 @override 1548 @override
1386 Token copy() => 1549 Token copy() =>
1387 new TokenWithComment(type, offset, copyComments(precedingComments)); 1550 new TokenWithComment(type, offset, copyComments(precedingComments));
1388 } 1551 }
OLDNEW
« no previous file with comments | « pkg/front_end/lib/src/fasta/scanner/token.dart ('k') | pkg/front_end/test/fasta/parser/token_stream_rewriter_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698