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

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

Issue 2758113002: fasta.PrecedenceInfo implement analyzer.TokenType (Closed)
Patch Set: rebase Created 3 years, 9 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/scanner/string_utilities.dart'; 12 import 'package:front_end/src/scanner/string_utilities.dart';
13 import 'package:front_end/src/fasta/scanner/keyword.dart' as fasta; 13 import 'package:front_end/src/fasta/scanner/keyword.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.
22 */ 23 */
23 Token endToken; 24 Token endToken;
(...skipping 850 matching lines...) Expand 10 before | Expand all | Expand 10 after
874 875
875 @override 876 @override
876 String toString() => name; 877 String toString() => name;
877 } 878 }
878 879
879 /** 880 /**
880 * The types of tokens that can be returned by the scanner. 881 * The types of tokens that can be returned by the scanner.
881 * 882 *
882 * Clients may not extend, implement or mix-in this class. 883 * Clients may not extend, implement or mix-in this class.
883 */ 884 */
884 class TokenType { 885 abstract class TokenType {
885 /** 886 /**
886 * The type of the token that marks the start or end of the input. 887 * The type of the token that marks the start or end of the input.
887 */ 888 */
888 static const TokenType EOF = const _EndOfFileTokenType(); 889 static const TokenType EOF = fasta.EOF_INFO;
889 890
890 static const TokenType DOUBLE = const TokenType._('DOUBLE'); 891 static const TokenType DOUBLE = fasta.DOUBLE_INFO;
891 892
892 static const TokenType HEXADECIMAL = const TokenType._('HEXADECIMAL'); 893 static const TokenType HEXADECIMAL = fasta.HEXADECIMAL_INFO;
893 894
894 static const TokenType IDENTIFIER = const TokenType._('IDENTIFIER'); 895 static const TokenType IDENTIFIER = fasta.IDENTIFIER_INFO;
895 896
896 static const TokenType INT = const TokenType._('INT'); 897 static const TokenType INT = fasta.INT_INFO;
897 898
898 static const TokenType KEYWORD = const TokenType._('KEYWORD'); 899 static const TokenType KEYWORD = fasta.KEYWORD_INFO;
899 900
900 static const TokenType MULTI_LINE_COMMENT = 901 static const TokenType MULTI_LINE_COMMENT =
901 const TokenType._('MULTI_LINE_COMMENT'); 902 const fasta.PrecedenceInfo(null, 'MULTI_LINE_COMMENT', 0, -1);
902 903
903 static const TokenType SCRIPT_TAG = const TokenType._('SCRIPT_TAG'); 904 static const TokenType SCRIPT_TAG = fasta.SCRIPT_INFO;
904 905
905 static const TokenType SINGLE_LINE_COMMENT = 906 static const TokenType SINGLE_LINE_COMMENT =
906 const TokenType._('SINGLE_LINE_COMMENT'); 907 const fasta.PrecedenceInfo(null, 'SINGLE_LINE_COMMENT', 0, -1);
907 908
908 static const TokenType STRING = const TokenType._('STRING'); 909 static const TokenType STRING = fasta.STRING_INFO;
909 910
910 static const TokenType AMPERSAND = 911 static const TokenType AMPERSAND = fasta.AMPERSAND_INFO;
911 const TokenType._('AMPERSAND', TokenClass.BITWISE_AND_OPERATOR, '&');
912 912
913 static const TokenType AMPERSAND_AMPERSAND = const TokenType._( 913 static const TokenType AMPERSAND_AMPERSAND = fasta.AMPERSAND_AMPERSAND_INFO;
914 'AMPERSAND_AMPERSAND', TokenClass.LOGICAL_AND_OPERATOR, '&&');
915 914
916 static const TokenType AMPERSAND_AMPERSAND_EQ = const TokenType._( 915 static const TokenType AMPERSAND_AMPERSAND_EQ =
917 'AMPERSAND_AMPERSAND_EQ', TokenClass.ASSIGNMENT_OPERATOR, '&&='); 916 const fasta.PrecedenceInfo('&&=', 'AMPERSAND_AMPERSAND_EQ', 1, -1);
918 917
919 static const TokenType AMPERSAND_EQ = 918 static const TokenType AMPERSAND_EQ = fasta.AMPERSAND_EQ_INFO;
920 const TokenType._('AMPERSAND_EQ', TokenClass.ASSIGNMENT_OPERATOR, '&=');
921 919
922 static const TokenType AT = const TokenType._('AT', TokenClass.NO_CLASS, '@'); 920 static const TokenType AT = fasta.AT_INFO;
923 921
924 static const TokenType BANG = 922 static const TokenType BANG = fasta.BANG_INFO;
925 const TokenType._('BANG', TokenClass.UNARY_PREFIX_OPERATOR, '!');
926 923
927 static const TokenType BANG_EQ = 924 static const TokenType BANG_EQ = fasta.BANG_EQ_INFO;
928 const TokenType._('BANG_EQ', TokenClass.EQUALITY_OPERATOR, '!=');
929 925
930 static const TokenType BAR = 926 static const TokenType BAR = fasta.BAR_INFO;
931 const TokenType._('BAR', TokenClass.BITWISE_OR_OPERATOR, '|');
932 927
933 static const TokenType BAR_BAR = 928 static const TokenType BAR_BAR = fasta.BAR_BAR_INFO;
934 const TokenType._('BAR_BAR', TokenClass.LOGICAL_OR_OPERATOR, '||');
935 929
936 static const TokenType BAR_BAR_EQ = 930 static const TokenType BAR_BAR_EQ =
937 const TokenType._('BAR_BAR_EQ', TokenClass.ASSIGNMENT_OPERATOR, '||='); 931 const fasta.PrecedenceInfo('||=', 'BAR_BAR_EQ', 1, -1);
938 932
939 static const TokenType BAR_EQ = 933 static const TokenType BAR_EQ = fasta.BAR_EQ_INFO;
940 const TokenType._('BAR_EQ', TokenClass.ASSIGNMENT_OPERATOR, '|=');
941 934
942 static const TokenType COLON = 935 static const TokenType COLON = fasta.COLON_INFO;
943 const TokenType._('COLON', TokenClass.NO_CLASS, ':');
944 936
945 static const TokenType COMMA = 937 static const TokenType COMMA = fasta.COMMA_INFO;
946 const TokenType._('COMMA', TokenClass.NO_CLASS, ',');
947 938
948 static const TokenType CARET = 939 static const TokenType CARET = fasta.CARET_INFO;
949 const TokenType._('CARET', TokenClass.BITWISE_XOR_OPERATOR, '^');
950 940
951 static const TokenType CARET_EQ = 941 static const TokenType CARET_EQ = fasta.CARET_EQ_INFO;
952 const TokenType._('CARET_EQ', TokenClass.ASSIGNMENT_OPERATOR, '^=');
953 942
954 static const TokenType CLOSE_CURLY_BRACKET = 943 static const TokenType CLOSE_CURLY_BRACKET = fasta.CLOSE_CURLY_BRACKET_INFO;
955 const TokenType._('CLOSE_CURLY_BRACKET', TokenClass.NO_CLASS, '}');
956 944
957 static const TokenType CLOSE_PAREN = 945 static const TokenType CLOSE_PAREN = fasta.CLOSE_PAREN_INFO;
958 const TokenType._('CLOSE_PAREN', TokenClass.NO_CLASS, ')');
959 946
960 static const TokenType CLOSE_SQUARE_BRACKET = 947 static const TokenType CLOSE_SQUARE_BRACKET = fasta.CLOSE_SQUARE_BRACKET_INFO;
961 const TokenType._('CLOSE_SQUARE_BRACKET', TokenClass.NO_CLASS, ']');
962 948
963 static const TokenType EQ = 949 static const TokenType EQ = fasta.EQ_INFO;
964 const TokenType._('EQ', TokenClass.ASSIGNMENT_OPERATOR, '=');
965 950
966 static const TokenType EQ_EQ = 951 static const TokenType EQ_EQ = fasta.EQ_EQ_INFO;
967 const TokenType._('EQ_EQ', TokenClass.EQUALITY_OPERATOR, '==');
968 952
969 static const TokenType FUNCTION = 953 static const TokenType FUNCTION = fasta.FUNCTION_INFO;
970 const TokenType._('FUNCTION', TokenClass.NO_CLASS, '=>');
971 954
972 static const TokenType GT = 955 static const TokenType GT = fasta.GT_INFO;
973 const TokenType._('GT', TokenClass.RELATIONAL_OPERATOR, '>');
974 956
975 static const TokenType GT_EQ = 957 static const TokenType GT_EQ = fasta.GT_EQ_INFO;
976 const TokenType._('GT_EQ', TokenClass.RELATIONAL_OPERATOR, '>=');
977 958
978 static const TokenType GT_GT = 959 static const TokenType GT_GT = fasta.GT_GT_INFO;
979 const TokenType._('GT_GT', TokenClass.SHIFT_OPERATOR, '>>');
980 960
981 static const TokenType GT_GT_EQ = 961 static const TokenType GT_GT_EQ = fasta.GT_GT_EQ_INFO;
982 const TokenType._('GT_GT_EQ', TokenClass.ASSIGNMENT_OPERATOR, '>>=');
983 962
984 static const TokenType HASH = 963 static const TokenType HASH = fasta.HASH_INFO;
985 const TokenType._('HASH', TokenClass.NO_CLASS, '#');
986 964
987 static const TokenType INDEX = 965 static const TokenType INDEX = fasta.INDEX_INFO;
988 const TokenType._('INDEX', TokenClass.NO_CLASS, '[]');
989 966
990 static const TokenType INDEX_EQ = 967 static const TokenType INDEX_EQ = fasta.INDEX_EQ_INFO;
991 const TokenType._('INDEX_EQ', TokenClass.NO_CLASS, '[]=');
992 968
993 static const TokenType LT = 969 static const TokenType LT = fasta.LT_INFO;
994 const TokenType._('LT', TokenClass.RELATIONAL_OPERATOR, '<');
995 970
996 static const TokenType LT_EQ = 971 static const TokenType LT_EQ = fasta.LT_EQ_INFO;
997 const TokenType._('LT_EQ', TokenClass.RELATIONAL_OPERATOR, '<=');
998 972
999 static const TokenType LT_LT = 973 static const TokenType LT_LT = fasta.LT_LT_INFO;
1000 const TokenType._('LT_LT', TokenClass.SHIFT_OPERATOR, '<<');
1001 974
1002 static const TokenType LT_LT_EQ = 975 static const TokenType LT_LT_EQ = fasta.LT_LT_EQ_INFO;
1003 const TokenType._('LT_LT_EQ', TokenClass.ASSIGNMENT_OPERATOR, '<<=');
1004 976
1005 static const TokenType MINUS = 977 static const TokenType MINUS = fasta.MINUS_INFO;
1006 const TokenType._('MINUS', TokenClass.ADDITIVE_OPERATOR, '-');
1007 978
1008 static const TokenType MINUS_EQ = 979 static const TokenType MINUS_EQ = fasta.MINUS_EQ_INFO;
1009 const TokenType._('MINUS_EQ', TokenClass.ASSIGNMENT_OPERATOR, '-=');
1010 980
1011 static const TokenType MINUS_MINUS = 981 static const TokenType MINUS_MINUS = fasta.MINUS_MINUS_INFO;
1012 const TokenType._('MINUS_MINUS', TokenClass.UNARY_POSTFIX_OPERATOR, '--');
1013 982
1014 static const TokenType OPEN_CURLY_BRACKET = 983 static const TokenType OPEN_CURLY_BRACKET = fasta.OPEN_CURLY_BRACKET_INFO;
1015 const TokenType._('OPEN_CURLY_BRACKET', TokenClass.NO_CLASS, '{');
1016 984
1017 static const TokenType OPEN_PAREN = 985 static const TokenType OPEN_PAREN = fasta.OPEN_PAREN_INFO;
1018 const TokenType._('OPEN_PAREN', TokenClass.UNARY_POSTFIX_OPERATOR, '(');
1019 986
1020 static const TokenType OPEN_SQUARE_BRACKET = const TokenType._( 987 static const TokenType OPEN_SQUARE_BRACKET = fasta.OPEN_SQUARE_BRACKET_INFO;
1021 'OPEN_SQUARE_BRACKET', TokenClass.UNARY_POSTFIX_OPERATOR, '[');
1022 988
1023 static const TokenType PERCENT = 989 static const TokenType PERCENT = fasta.PERCENT_INFO;
1024 const TokenType._('PERCENT', TokenClass.MULTIPLICATIVE_OPERATOR, '%');
1025 990
1026 static const TokenType PERCENT_EQ = 991 static const TokenType PERCENT_EQ = fasta.PERCENT_EQ_INFO;
1027 const TokenType._('PERCENT_EQ', TokenClass.ASSIGNMENT_OPERATOR, '%=');
1028 992
1029 static const TokenType PERIOD = 993 static const TokenType PERIOD = fasta.PERIOD_INFO;
1030 const TokenType._('PERIOD', TokenClass.UNARY_POSTFIX_OPERATOR, '.');
1031 994
1032 static const TokenType PERIOD_PERIOD = 995 static const TokenType PERIOD_PERIOD = fasta.PERIOD_PERIOD_INFO;
1033 const TokenType._('PERIOD_PERIOD', TokenClass.CASCADE_OPERATOR, '..');
1034 996
1035 static const TokenType PLUS = 997 static const TokenType PLUS = fasta.PLUS_INFO;
1036 const TokenType._('PLUS', TokenClass.ADDITIVE_OPERATOR, '+');
1037 998
1038 static const TokenType PLUS_EQ = 999 static const TokenType PLUS_EQ = fasta.PLUS_EQ_INFO;
1039 const TokenType._('PLUS_EQ', TokenClass.ASSIGNMENT_OPERATOR, '+=');
1040 1000
1041 static const TokenType PLUS_PLUS = 1001 static const TokenType PLUS_PLUS = fasta.PLUS_PLUS_INFO;
1042 const TokenType._('PLUS_PLUS', TokenClass.UNARY_POSTFIX_OPERATOR, '++');
1043 1002
1044 static const TokenType QUESTION = 1003 static const TokenType QUESTION = fasta.QUESTION_INFO;
1045 const TokenType._('QUESTION', TokenClass.CONDITIONAL_OPERATOR, '?');
1046 1004
1047 static const TokenType QUESTION_PERIOD = const TokenType._( 1005 static const TokenType QUESTION_PERIOD = fasta.QUESTION_PERIOD_INFO;
1048 'QUESTION_PERIOD', TokenClass.UNARY_POSTFIX_OPERATOR, '?.');
1049 1006
1050 static const TokenType QUESTION_QUESTION = 1007 static const TokenType QUESTION_QUESTION = fasta.QUESTION_QUESTION_INFO;
1051 const TokenType._('QUESTION_QUESTION', TokenClass.IF_NULL_OPERATOR, '??');
1052 1008
1053 static const TokenType QUESTION_QUESTION_EQ = const TokenType._( 1009 static const TokenType QUESTION_QUESTION_EQ = fasta.QUESTION_QUESTION_EQ_INFO;
1054 'QUESTION_QUESTION_EQ', TokenClass.ASSIGNMENT_OPERATOR, '??=');
1055 1010
1056 static const TokenType SEMICOLON = 1011 static const TokenType SEMICOLON = fasta.SEMICOLON_INFO;
1057 const TokenType._('SEMICOLON', TokenClass.NO_CLASS, ';');
1058 1012
1059 static const TokenType SLASH = 1013 static const TokenType SLASH = fasta.SLASH_INFO;
1060 const TokenType._('SLASH', TokenClass.MULTIPLICATIVE_OPERATOR, '/');
1061 1014
1062 static const TokenType SLASH_EQ = 1015 static const TokenType SLASH_EQ = fasta.SLASH_EQ_INFO;
1063 const TokenType._('SLASH_EQ', TokenClass.ASSIGNMENT_OPERATOR, '/=');
1064 1016
1065 static const TokenType STAR = 1017 static const TokenType STAR = fasta.STAR_INFO;
1066 const TokenType._('STAR', TokenClass.MULTIPLICATIVE_OPERATOR, '*');
1067 1018
1068 static const TokenType STAR_EQ = 1019 static const TokenType STAR_EQ = fasta.STAR_EQ_INFO;
1069 const TokenType._('STAR_EQ', TokenClass.ASSIGNMENT_OPERATOR, "*=");
1070 1020
1071 static const TokenType STRING_INTERPOLATION_EXPRESSION = const TokenType._( 1021 static const TokenType STRING_INTERPOLATION_EXPRESSION =
1072 'STRING_INTERPOLATION_EXPRESSION', TokenClass.NO_CLASS, '\${'); 1022 fasta.STRING_INTERPOLATION_INFO;
1073 1023
1074 static const TokenType STRING_INTERPOLATION_IDENTIFIER = const TokenType._( 1024 static const TokenType STRING_INTERPOLATION_IDENTIFIER =
1075 'STRING_INTERPOLATION_IDENTIFIER', TokenClass.NO_CLASS, '\$'); 1025 fasta.STRING_INTERPOLATION_IDENTIFIER_INFO;
1076 1026
1077 static const TokenType TILDE = 1027 static const TokenType TILDE = fasta.TILDE_INFO;
1078 const TokenType._('TILDE', TokenClass.UNARY_PREFIX_OPERATOR, '~');
1079 1028
1080 static const TokenType TILDE_SLASH = const TokenType._( 1029 static const TokenType TILDE_SLASH = fasta.TILDE_SLASH_INFO;
1081 'TILDE_SLASH', TokenClass.MULTIPLICATIVE_OPERATOR, '~/');
1082 1030
1083 static const TokenType TILDE_SLASH_EQ = const TokenType._( 1031 static const TokenType TILDE_SLASH_EQ = fasta.TILDE_SLASH_EQ_INFO;
1084 'TILDE_SLASH_EQ', TokenClass.ASSIGNMENT_OPERATOR, '~/=');
1085 1032
1086 static const TokenType BACKPING = 1033 static const TokenType BACKPING = fasta.BACKPING_INFO;
1087 const TokenType._('BACKPING', TokenClass.NO_CLASS, '`');
1088 1034
1089 static const TokenType BACKSLASH = 1035 static const TokenType BACKSLASH = fasta.BACKSLASH_INFO;
1090 const TokenType._('BACKSLASH', TokenClass.NO_CLASS, '\\');
1091 1036
1092 static const TokenType PERIOD_PERIOD_PERIOD = 1037 static const TokenType PERIOD_PERIOD_PERIOD = fasta.PERIOD_PERIOD_PERIOD_INFO;
1093 const TokenType._('PERIOD_PERIOD_PERIOD', TokenClass.NO_CLASS, '...');
1094 1038
1095 static const TokenType GENERIC_METHOD_TYPE_LIST = 1039 static const TokenType GENERIC_METHOD_TYPE_LIST =
1096 const TokenType._('GENERIC_METHOD_TYPE_LIST'); 1040 const fasta.PrecedenceInfo(null, 'GENERIC_METHOD_TYPE_LIST', 0, -1);
1097 1041
1098 static const TokenType GENERIC_METHOD_TYPE_ASSIGN = 1042 static const TokenType GENERIC_METHOD_TYPE_ASSIGN =
1099 const TokenType._('GENERIC_METHOD_TYPE_ASSIGN'); 1043 const fasta.PrecedenceInfo(null, 'GENERIC_METHOD_TYPE_ASSIGN', 0, -1);
1100
1101 /**
1102 * The class of the token.
1103 */
1104 final TokenClass _tokenClass;
1105 1044
1106 /** 1045 /**
1107 * The name of the token type. 1046 * The name of the token type.
1108 */ 1047 */
1109 final String name; 1048 String get name;
1110 1049
1111 /** 1050 /**
1112 * The lexeme that defines this type of token, or `null` if there is more than 1051 * The lexeme that defines this type of token, or `null` if there is more than
1113 * one possible lexeme for this type of token. 1052 * one possible lexeme for this type of token.
1114 */ 1053 */
1115 final String lexeme; 1054 String get lexeme;
1116
1117 /**
1118 * Initialize a newly created token type to have the given [name],
1119 * [_tokenClass] and [lexeme].
1120 */
1121 const TokenType._(this.name,
1122 [this._tokenClass = TokenClass.NO_CLASS, this.lexeme = null]);
1123 1055
1124 /** 1056 /**
1125 * Return `true` if this type of token represents an additive operator. 1057 * Return `true` if this type of token represents an additive operator.
1126 */ 1058 */
1127 bool get isAdditiveOperator => _tokenClass == TokenClass.ADDITIVE_OPERATOR; 1059 bool get isAdditiveOperator;
1128 1060
1129 /** 1061 /**
1130 * Return `true` if this type of token represents an assignment operator. 1062 * Return `true` if this type of token represents an assignment operator.
1131 */ 1063 */
1132 bool get isAssignmentOperator => 1064 bool get isAssignmentOperator;
1133 _tokenClass == TokenClass.ASSIGNMENT_OPERATOR;
1134 1065
1135 /** 1066 /**
1136 * Return `true` if this type of token represents an associative operator. An 1067 * Return `true` if this type of token represents an associative operator. An
1137 * associative operator is an operator for which the following equality is 1068 * associative operator is an operator for which the following equality is
1138 * true: `(a * b) * c == a * (b * c)`. In other words, if the result of 1069 * true: `(a * b) * c == a * (b * c)`. In other words, if the result of
1139 * applying the operator to multiple operands does not depend on the order in 1070 * applying the operator to multiple operands does not depend on the order in
1140 * which those applications occur. 1071 * which those applications occur.
1141 * 1072 *
1142 * Note: This method considers the logical-and and logical-or operators to be 1073 * Note: This method considers the logical-and and logical-or operators to be
1143 * associative, even though the order in which the application of those 1074 * associative, even though the order in which the application of those
1144 * operators can have an effect because evaluation of the right-hand operand 1075 * operators can have an effect because evaluation of the right-hand operand
1145 * is conditional. 1076 * is conditional.
1146 */ 1077 */
1147 bool get isAssociativeOperator => 1078 bool get isAssociativeOperator;
1148 this == AMPERSAND ||
1149 this == AMPERSAND_AMPERSAND ||
1150 this == BAR ||
1151 this == BAR_BAR ||
1152 this == CARET ||
1153 this == PLUS ||
1154 this == STAR;
1155 1079
1156 /** 1080 /**
1157 * Return `true` if this type of token represents an equality operator. 1081 * Return `true` if this type of token represents an equality operator.
1158 */ 1082 */
1159 bool get isEqualityOperator => _tokenClass == TokenClass.EQUALITY_OPERATOR; 1083 bool get isEqualityOperator;
1160 1084
1161 /** 1085 /**
1162 * Return `true` if this type of token represents an increment operator. 1086 * Return `true` if this type of token represents an increment operator.
1163 */ 1087 */
1164 bool get isIncrementOperator => 1088 bool get isIncrementOperator;
1165 identical(lexeme, '++') || identical(lexeme, '--');
1166 1089
1167 /** 1090 /**
1168 * Return `true` if this type of token represents a multiplicative operator. 1091 * Return `true` if this type of token represents a multiplicative operator.
1169 */ 1092 */
1170 bool get isMultiplicativeOperator => 1093 bool get isMultiplicativeOperator;
1171 _tokenClass == TokenClass.MULTIPLICATIVE_OPERATOR;
1172 1094
1173 /** 1095 /**
1174 * Return `true` if this token type represents an operator. 1096 * Return `true` if this token type represents an operator.
1175 */ 1097 */
1176 bool get isOperator => 1098 bool get isOperator;
1177 this == INDEX ||
1178 this == INDEX_EQ ||
1179 (_tokenClass != TokenClass.NO_CLASS &&
1180 this != OPEN_PAREN &&
1181 this != OPEN_SQUARE_BRACKET &&
1182 this != PERIOD);
1183 1099
1184 /** 1100 /**
1185 * Return `true` if this type of token represents a relational operator. 1101 * Return `true` if this type of token represents a relational operator.
1186 */ 1102 */
1187 bool get isRelationalOperator => 1103 bool get isRelationalOperator;
1188 _tokenClass == TokenClass.RELATIONAL_OPERATOR;
1189 1104
1190 /** 1105 /**
1191 * Return `true` if this type of token represents a shift operator. 1106 * Return `true` if this type of token represents a shift operator.
1192 */ 1107 */
1193 bool get isShiftOperator => _tokenClass == TokenClass.SHIFT_OPERATOR; 1108 bool get isShiftOperator;
1194 1109
1195 /** 1110 /**
1196 * Return `true` if this type of token represents a unary postfix operator. 1111 * Return `true` if this type of token represents a unary postfix operator.
1197 */ 1112 */
1198 bool get isUnaryPostfixOperator => 1113 bool get isUnaryPostfixOperator;
1199 _tokenClass == TokenClass.UNARY_POSTFIX_OPERATOR;
1200 1114
1201 /** 1115 /**
1202 * Return `true` if this type of token represents a unary prefix operator. 1116 * Return `true` if this type of token represents a unary prefix operator.
1203 */ 1117 */
1204 bool get isUnaryPrefixOperator => 1118 bool get isUnaryPrefixOperator;
1205 _tokenClass == TokenClass.UNARY_PREFIX_OPERATOR;
1206 1119
1207 /** 1120 /**
1208 * Return `true` if this token type represents an operator that can be defined 1121 * Return `true` if this token type represents an operator that can be defined
1209 * by users. 1122 * by users.
1210 */ 1123 */
1211 bool get isUserDefinableOperator => 1124 bool get isUserDefinableOperator;
1212 identical(lexeme, '==') ||
1213 identical(lexeme, '~') ||
1214 identical(lexeme, '[]') ||
1215 identical(lexeme, '[]=') ||
1216 identical(lexeme, '*') ||
1217 identical(lexeme, '/') ||
1218 identical(lexeme, '%') ||
1219 identical(lexeme, '~/') ||
1220 identical(lexeme, '+') ||
1221 identical(lexeme, '-') ||
1222 identical(lexeme, '<<') ||
1223 identical(lexeme, '>>') ||
1224 identical(lexeme, '>=') ||
1225 identical(lexeme, '>') ||
1226 identical(lexeme, '<=') ||
1227 identical(lexeme, '<') ||
1228 identical(lexeme, '&') ||
1229 identical(lexeme, '^') ||
1230 identical(lexeme, '|');
1231 1125
1232 /** 1126 /**
1233 * Return the precedence of the token, or `0` if the token does not represent 1127 * Return the precedence of the token, or `0` if the token does not represent
1234 * an operator. 1128 * an operator.
1235 */ 1129 */
1236 int get precedence => _tokenClass.precedence; 1130 int get precedence;
1237 1131
1238 @override 1132 @override
1239 String toString() => name; 1133 String toString() => name;
1240 } 1134 }
1241 1135
1242 /** 1136 /**
1243 * A normal token that is preceded by comments. 1137 * A normal token that is preceded by comments.
1244 */ 1138 */
1245 class TokenWithComment extends SimpleToken { 1139 class TokenWithComment extends SimpleToken {
1246 /** 1140 /**
(...skipping 16 matching lines...) Expand all
1263 1157
1264 void set precedingComments(CommentToken comment) { 1158 void set precedingComments(CommentToken comment) {
1265 _precedingComment = comment; 1159 _precedingComment = comment;
1266 _setCommentParent(_precedingComment); 1160 _setCommentParent(_precedingComment);
1267 } 1161 }
1268 1162
1269 @override 1163 @override
1270 Token copy() => 1164 Token copy() =>
1271 new TokenWithComment(type, offset, copyComments(precedingComments)); 1165 new TokenWithComment(type, offset, copyComments(precedingComments));
1272 } 1166 }
1273
1274 /**
1275 * A token representing the end (either the head or the tail) of a stream of
1276 * tokens.
1277 */
1278 class _EndOfFileTokenType extends TokenType {
1279 /**
1280 * Initialize a newly created token.
1281 */
1282 const _EndOfFileTokenType() : super._('EOF', TokenClass.NO_CLASS, '');
1283
1284 @override
1285 String toString() => '-eof-';
1286 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698