| OLD | NEW |
| 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/scanner/string_utilities.dart'; | 13 import 'package:front_end/src/scanner/string_utilities.dart'; |
| 13 import 'package:front_end/src/fasta/scanner/precedence.dart' as fasta; | 14 import 'package:front_end/src/fasta/scanner/precedence.dart' as fasta; |
| 14 | 15 |
| 15 /** | 16 /** |
| 16 * The opening half of a grouping pair of tokens. This is used for curly | 17 * The opening half of a grouping pair of tokens. This is used for curly |
| 17 * brackets ('{'), parentheses ('('), and square brackets ('['). | 18 * brackets ('{'), parentheses ('('), and square brackets ('['). |
| 18 */ | 19 */ |
| 19 class BeginToken extends SimpleToken { | 20 class BeginToken extends SimpleToken { |
| 20 /** | 21 /** |
| 21 * The token that corresponds to this token. | 22 * The token that corresponds to this token. |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 975 | 976 |
| 976 @override | 977 @override |
| 977 String toString() => name; | 978 String toString() => name; |
| 978 } | 979 } |
| 979 | 980 |
| 980 /** | 981 /** |
| 981 * The types of tokens that can be returned by the scanner. | 982 * The types of tokens that can be returned by the scanner. |
| 982 * | 983 * |
| 983 * Clients may not extend, implement or mix-in this class. | 984 * Clients may not extend, implement or mix-in this class. |
| 984 */ | 985 */ |
| 985 abstract class TokenType { | 986 class TokenType { |
| 986 /** | 987 /** |
| 987 * The type of the token that marks the start or end of the input. | 988 * The type of the token that marks the start or end of the input. |
| 988 */ | 989 */ |
| 989 static const TokenType EOF = fasta.EOF_INFO; | 990 static const TokenType EOF = fasta.EOF_INFO; |
| 990 | 991 |
| 991 static const TokenType DOUBLE = fasta.DOUBLE_INFO; | 992 static const TokenType DOUBLE = fasta.DOUBLE_INFO; |
| 992 | 993 |
| 993 static const TokenType HEXADECIMAL = fasta.HEXADECIMAL_INFO; | 994 static const TokenType HEXADECIMAL = fasta.HEXADECIMAL_INFO; |
| 994 | 995 |
| 995 static const TokenType IDENTIFIER = fasta.IDENTIFIER_INFO; | 996 static const TokenType IDENTIFIER = fasta.IDENTIFIER_INFO; |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1133 static const TokenType BACKSLASH = fasta.BACKSLASH_INFO; | 1134 static const TokenType BACKSLASH = fasta.BACKSLASH_INFO; |
| 1134 | 1135 |
| 1135 static const TokenType PERIOD_PERIOD_PERIOD = fasta.PERIOD_PERIOD_PERIOD_INFO; | 1136 static const TokenType PERIOD_PERIOD_PERIOD = fasta.PERIOD_PERIOD_PERIOD_INFO; |
| 1136 | 1137 |
| 1137 static const TokenType GENERIC_METHOD_TYPE_LIST = | 1138 static const TokenType GENERIC_METHOD_TYPE_LIST = |
| 1138 fasta.GENERIC_METHOD_TYPE_LIST; | 1139 fasta.GENERIC_METHOD_TYPE_LIST; |
| 1139 | 1140 |
| 1140 static const TokenType GENERIC_METHOD_TYPE_ASSIGN = | 1141 static const TokenType GENERIC_METHOD_TYPE_ASSIGN = |
| 1141 fasta.GENERIC_METHOD_TYPE_ASSIGN; | 1142 fasta.GENERIC_METHOD_TYPE_ASSIGN; |
| 1142 | 1143 |
| 1144 final int kind; |
| 1145 |
| 1146 /** |
| 1147 * `true` if this token type represents an operator. |
| 1148 */ |
| 1149 final bool isOperator; |
| 1150 |
| 1151 /** |
| 1152 * `true` if this token type represents an operator |
| 1153 * that can be defined by users. |
| 1154 */ |
| 1155 final bool isUserDefinableOperator; |
| 1156 |
| 1157 /** |
| 1158 * The lexeme that defines this type of token, |
| 1159 * or `null` if there is more than one possible lexeme for this type of token. |
| 1160 */ |
| 1161 final String lexeme; |
| 1162 |
| 1143 /** | 1163 /** |
| 1144 * The name of the token type. | 1164 * The name of the token type. |
| 1145 */ | 1165 */ |
| 1146 String get name; | 1166 final String name; |
| 1147 | 1167 |
| 1148 /** | 1168 /** |
| 1149 * The lexeme that defines this type of token, or `null` if there is more than | 1169 * The precedence of this type of token, |
| 1150 * one possible lexeme for this type of token. | 1170 * or `0` if the token does not represent an operator. |
| 1151 */ | 1171 */ |
| 1152 String get lexeme; | 1172 final int precedence; |
| 1173 |
| 1174 const TokenType(this.lexeme, this.name, this.precedence, this.kind, |
| 1175 {this.isOperator: false, this.isUserDefinableOperator: false}); |
| 1153 | 1176 |
| 1154 /** | 1177 /** |
| 1155 * Return `true` if this type of token represents an additive operator. | 1178 * Return `true` if this type of token represents an additive operator. |
| 1156 */ | 1179 */ |
| 1157 bool get isAdditiveOperator; | 1180 bool get isAdditiveOperator => precedence == ADDITIVE_PRECEDENCE; |
| 1158 | 1181 |
| 1159 /** | 1182 /** |
| 1160 * Return `true` if this type of token represents an assignment operator. | 1183 * Return `true` if this type of token represents an assignment operator. |
| 1161 */ | 1184 */ |
| 1162 bool get isAssignmentOperator; | 1185 bool get isAssignmentOperator => precedence == ASSIGNMENT_PRECEDENCE; |
| 1163 | 1186 |
| 1164 /** | 1187 /** |
| 1165 * Return `true` if this type of token represents an associative operator. An | 1188 * Return `true` if this type of token represents an associative operator. An |
| 1166 * associative operator is an operator for which the following equality is | 1189 * associative operator is an operator for which the following equality is |
| 1167 * true: `(a * b) * c == a * (b * c)`. In other words, if the result of | 1190 * true: `(a * b) * c == a * (b * c)`. In other words, if the result of |
| 1168 * applying the operator to multiple operands does not depend on the order in | 1191 * applying the operator to multiple operands does not depend on the order in |
| 1169 * which those applications occur. | 1192 * which those applications occur. |
| 1170 * | 1193 * |
| 1171 * Note: This method considers the logical-and and logical-or operators to be | 1194 * Note: This method considers the logical-and and logical-or operators to be |
| 1172 * associative, even though the order in which the application of those | 1195 * associative, even though the order in which the application of those |
| 1173 * operators can have an effect because evaluation of the right-hand operand | 1196 * operators can have an effect because evaluation of the right-hand operand |
| 1174 * is conditional. | 1197 * is conditional. |
| 1175 */ | 1198 */ |
| 1176 bool get isAssociativeOperator; | 1199 bool get isAssociativeOperator => |
| 1200 this == AMPERSAND_INFO || |
| 1201 this == AMPERSAND_AMPERSAND_INFO || |
| 1202 this == BAR_INFO || |
| 1203 this == BAR_BAR_INFO || |
| 1204 this == CARET_INFO || |
| 1205 this == PLUS_INFO || |
| 1206 this == STAR_INFO; |
| 1177 | 1207 |
| 1178 /** | 1208 /** |
| 1179 * Return `true` if this type of token represents an equality operator. | 1209 * Return `true` if this type of token represents an equality operator. |
| 1180 */ | 1210 */ |
| 1181 bool get isEqualityOperator; | 1211 bool get isEqualityOperator => this == BANG_EQ_INFO || this == EQ_EQ_INFO; |
| 1182 | 1212 |
| 1183 /** | 1213 /** |
| 1184 * Return `true` if this type of token represents an increment operator. | 1214 * Return `true` if this type of token represents an increment operator. |
| 1185 */ | 1215 */ |
| 1186 bool get isIncrementOperator; | 1216 bool get isIncrementOperator => |
| 1217 this == PLUS_PLUS_INFO || this == MINUS_MINUS_INFO; |
| 1187 | 1218 |
| 1188 /** | 1219 /** |
| 1189 * Return `true` if this type of token represents a multiplicative operator. | 1220 * Return `true` if this type of token represents a multiplicative operator. |
| 1190 */ | 1221 */ |
| 1191 bool get isMultiplicativeOperator; | 1222 bool get isMultiplicativeOperator => precedence == MULTIPLICATIVE_PRECEDENCE; |
| 1192 | |
| 1193 /** | |
| 1194 * Return `true` if this token type represents an operator. | |
| 1195 */ | |
| 1196 bool get isOperator; | |
| 1197 | 1223 |
| 1198 /** | 1224 /** |
| 1199 * Return `true` if this type of token represents a relational operator. | 1225 * Return `true` if this type of token represents a relational operator. |
| 1200 */ | 1226 */ |
| 1201 bool get isRelationalOperator; | 1227 bool get isRelationalOperator => |
| 1228 this == LT_INFO || |
| 1229 this == LT_EQ_INFO || |
| 1230 this == GT_INFO || |
| 1231 this == GT_EQ_INFO; |
| 1202 | 1232 |
| 1203 /** | 1233 /** |
| 1204 * Return `true` if this type of token represents a shift operator. | 1234 * Return `true` if this type of token represents a shift operator. |
| 1205 */ | 1235 */ |
| 1206 bool get isShiftOperator; | 1236 bool get isShiftOperator => precedence == SHIFT_PRECEDENCE; |
| 1207 | 1237 |
| 1208 /** | 1238 /** |
| 1209 * Return `true` if this type of token represents a unary postfix operator. | 1239 * Return `true` if this type of token represents a unary postfix operator. |
| 1210 */ | 1240 */ |
| 1211 bool get isUnaryPostfixOperator; | 1241 bool get isUnaryPostfixOperator => precedence == POSTFIX_PRECEDENCE; |
| 1212 | 1242 |
| 1213 /** | 1243 /** |
| 1214 * Return `true` if this type of token represents a unary prefix operator. | 1244 * Return `true` if this type of token represents a unary prefix operator. |
| 1215 */ | 1245 */ |
| 1216 bool get isUnaryPrefixOperator; | 1246 bool get isUnaryPrefixOperator => |
| 1217 | 1247 precedence == PREFIX_PRECEDENCE || |
| 1218 /** | 1248 this == PLUS_PLUS_INFO || |
| 1219 * Return `true` if this token type represents an operator that can be defined | 1249 this == MINUS_MINUS_INFO; |
| 1220 * by users. | |
| 1221 */ | |
| 1222 bool get isUserDefinableOperator; | |
| 1223 | |
| 1224 /** | |
| 1225 * Return the precedence of the token, or `0` if the token does not represent | |
| 1226 * an operator. | |
| 1227 */ | |
| 1228 int get precedence; | |
| 1229 | 1250 |
| 1230 @override | 1251 @override |
| 1231 String toString() => name; | 1252 String toString() => name; |
| 1253 |
| 1254 /** |
| 1255 * Use [lexeme] instead of this method |
| 1256 */ |
| 1257 @deprecated |
| 1258 String get value => lexeme; |
| 1232 } | 1259 } |
| 1233 | 1260 |
| 1234 /** | 1261 /** |
| 1235 * A normal token that is preceded by comments. | 1262 * A normal token that is preceded by comments. |
| 1236 */ | 1263 */ |
| 1237 class TokenWithComment extends SimpleToken { | 1264 class TokenWithComment extends SimpleToken { |
| 1238 /** | 1265 /** |
| 1239 * The first comment in the list of comments that precede this token. | 1266 * The first comment in the list of comments that precede this token. |
| 1240 */ | 1267 */ |
| 1241 CommentToken _precedingComment; | 1268 CommentToken _precedingComment; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1255 | 1282 |
| 1256 void set precedingComments(CommentToken comment) { | 1283 void set precedingComments(CommentToken comment) { |
| 1257 _precedingComment = comment; | 1284 _precedingComment = comment; |
| 1258 _setCommentParent(_precedingComment); | 1285 _setCommentParent(_precedingComment); |
| 1259 } | 1286 } |
| 1260 | 1287 |
| 1261 @override | 1288 @override |
| 1262 Token copy() => | 1289 Token copy() => |
| 1263 new TokenWithComment(type, offset, copyComments(precedingComments)); | 1290 new TokenWithComment(type, offset, copyComments(precedingComments)); |
| 1264 } | 1291 } |
| OLD | NEW |