|
5 | 5 | import '../base/errors.dart'; |
6 | 6 | import '../messages/codes.dart'; |
7 | 7 | import 'error_token.dart'; |
8 | | -import 'token_constants.dart'; |
9 | 8 | import 'token.dart' show Token, TokenType; |
10 | | - |
11 | | -/** |
12 | | - * The error codes used for errors detected by the scanner. |
13 | | - */ |
14 | | -class ScannerErrorCode extends ErrorCode { |
15 | | - /** |
16 | | - * Parameters: |
17 | | - * 0: the token that was expected but not found |
18 | | - */ |
19 | | - static const ScannerErrorCode EXPECTED_TOKEN = |
20 | | - const ScannerErrorCode('EXPECTED_TOKEN', "Expected to find '{0}'."); |
21 | | - |
22 | | - /** |
23 | | - * Parameters: |
24 | | - * 0: the illegal character |
25 | | - */ |
26 | | - static const ScannerErrorCode ILLEGAL_CHARACTER = |
27 | | - const ScannerErrorCode('ILLEGAL_CHARACTER', "Illegal character '{0}'."); |
28 | | - |
29 | | - static const ScannerErrorCode MISSING_DIGIT = |
30 | | - const ScannerErrorCode('MISSING_DIGIT', "Decimal digit expected."); |
31 | | - |
32 | | - static const ScannerErrorCode MISSING_HEX_DIGIT = const ScannerErrorCode( |
33 | | - 'MISSING_HEX_DIGIT', "Hexadecimal digit expected."); |
34 | | - |
35 | | - static const ScannerErrorCode MISSING_IDENTIFIER = |
36 | | - const ScannerErrorCode('MISSING_IDENTIFIER', "Expected an identifier."); |
37 | | - |
38 | | - static const ScannerErrorCode MISSING_QUOTE = |
39 | | - const ScannerErrorCode('MISSING_QUOTE', "Expected quote (' or \")."); |
40 | | - |
41 | | - /** |
42 | | - * Parameters: |
43 | | - * 0: the path of the file that cannot be read |
44 | | - */ |
45 | | - static const ScannerErrorCode UNABLE_GET_CONTENT = const ScannerErrorCode( |
46 | | - 'UNABLE_GET_CONTENT', "Unable to get content of '{0}'."); |
47 | | - |
48 | | - static const ScannerErrorCode UNEXPECTED_DOLLAR_IN_STRING = |
49 | | - const ScannerErrorCode( |
50 | | - 'UNEXPECTED_DOLLAR_IN_STRING', |
51 | | - "A '\$' has special meaning inside a string, and must be followed by " |
52 | | - "an identifier or an expression in curly braces ({}).", |
53 | | - correction: "Try adding a backslash (\\) to escape the '\$'."); |
54 | | - |
55 | | - /** |
56 | | - * Parameters: |
57 | | - * 0: the unsupported operator |
58 | | - */ |
59 | | - static const ScannerErrorCode UNSUPPORTED_OPERATOR = const ScannerErrorCode( |
60 | | - 'UNSUPPORTED_OPERATOR', "The '{0}' operator is not supported."); |
61 | | - |
62 | | - static const ScannerErrorCode UNTERMINATED_MULTI_LINE_COMMENT = |
63 | | - const ScannerErrorCode( |
64 | | - 'UNTERMINATED_MULTI_LINE_COMMENT', "Unterminated multi-line comment.", |
65 | | - correction: "Try terminating the comment with '*/', or " |
66 | | - "removing any unbalanced occurrences of '/*'" |
67 | | - " (because comments nest in Dart)."); |
68 | | - |
69 | | - static const ScannerErrorCode UNTERMINATED_STRING_LITERAL = |
70 | | - const ScannerErrorCode( |
71 | | - 'UNTERMINATED_STRING_LITERAL', "Unterminated string literal."); |
72 | | - |
73 | | - /** |
74 | | - * Initialize a newly created error code to have the given [name]. The message |
75 | | - * associated with the error will be created from the given [message] |
76 | | - * template. The correction associated with the error will be created from the |
77 | | - * given [correction] template. |
78 | | - */ |
79 | | - const ScannerErrorCode(String name, String message, {String correction}) |
80 | | - : super.temporary(name, message, correction: correction); |
81 | | - |
82 | | - @override |
83 | | - ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
84 | | - |
85 | | - @override |
86 | | - ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
87 | | -} |
88 | | - |
89 | | -/** |
90 | | - * Used to report a scan error at the given offset. |
91 | | - * The [errorCode] is the error code indicating the nature of the error. |
92 | | - * The [arguments] are any arguments needed to complete the error message. |
93 | | - */ |
94 | | -typedef ReportError( |
95 | | - ScannerErrorCode errorCode, int offset, List<Object> arguments); |
| 9 | +import 'token_constants.dart'; |
96 | 10 |
|
97 | 11 | /** |
98 | 12 | * Translates the given error [token] into an analyzer error and reports it |
@@ -190,3 +104,94 @@ bool _isAtEnd(Token token, int charOffset) { |
190 | 104 | // Otherwise keep looking. |
191 | 105 | } |
192 | 106 | } |
| 107 | + |
| 108 | +/** |
| 109 | + * Used to report a scan error at the given offset. |
| 110 | + * The [errorCode] is the error code indicating the nature of the error. |
| 111 | + * The [arguments] are any arguments needed to complete the error message. |
| 112 | + */ |
| 113 | +typedef ReportError( |
| 114 | + ScannerErrorCode errorCode, int offset, List<Object> arguments); |
| 115 | + |
| 116 | +/** |
| 117 | + * The error codes used for errors detected by the scanner. |
| 118 | + */ |
| 119 | +class ScannerErrorCode extends ErrorCode { |
| 120 | + /** |
| 121 | + * Parameters: |
| 122 | + * 0: the token that was expected but not found |
| 123 | + */ |
| 124 | + static const ScannerErrorCode EXPECTED_TOKEN = |
| 125 | + const ScannerErrorCode('EXPECTED_TOKEN', "Expected to find '{0}'."); |
| 126 | + |
| 127 | + /** |
| 128 | + * Parameters: |
| 129 | + * 0: the illegal character |
| 130 | + */ |
| 131 | + static const ScannerErrorCode ILLEGAL_CHARACTER = |
| 132 | + const ScannerErrorCode('ILLEGAL_CHARACTER', "Illegal character '{0}'."); |
| 133 | + |
| 134 | + static const ScannerErrorCode MISSING_DIGIT = |
| 135 | + const ScannerErrorCode('MISSING_DIGIT', "Decimal digit expected."); |
| 136 | + |
| 137 | + static const ScannerErrorCode MISSING_HEX_DIGIT = const ScannerErrorCode( |
| 138 | + 'MISSING_HEX_DIGIT', "Hexadecimal digit expected."); |
| 139 | + |
| 140 | + static const ScannerErrorCode MISSING_IDENTIFIER = |
| 141 | + const ScannerErrorCode('MISSING_IDENTIFIER', "Expected an identifier."); |
| 142 | + |
| 143 | + static const ScannerErrorCode MISSING_QUOTE = |
| 144 | + const ScannerErrorCode('MISSING_QUOTE', "Expected quote (' or \")."); |
| 145 | + |
| 146 | + /** |
| 147 | + * Parameters: |
| 148 | + * 0: the path of the file that cannot be read |
| 149 | + */ |
| 150 | + static const ScannerErrorCode UNABLE_GET_CONTENT = const ScannerErrorCode( |
| 151 | + 'UNABLE_GET_CONTENT', "Unable to get content of '{0}'."); |
| 152 | + |
| 153 | + static const ScannerErrorCode UNEXPECTED_DOLLAR_IN_STRING = |
| 154 | + const ScannerErrorCode( |
| 155 | + 'UNEXPECTED_DOLLAR_IN_STRING', |
| 156 | + "A '\$' has special meaning inside a string, and must be followed by " |
| 157 | + "an identifier or an expression in curly braces ({}).", |
| 158 | + correction: "Try adding a backslash (\\) to escape the '\$'."); |
| 159 | + |
| 160 | + /** |
| 161 | + * Parameters: |
| 162 | + * 0: the unsupported operator |
| 163 | + */ |
| 164 | + static const ScannerErrorCode UNSUPPORTED_OPERATOR = const ScannerErrorCode( |
| 165 | + 'UNSUPPORTED_OPERATOR', "The '{0}' operator is not supported."); |
| 166 | + |
| 167 | + static const ScannerErrorCode UNTERMINATED_MULTI_LINE_COMMENT = |
| 168 | + const ScannerErrorCode( |
| 169 | + 'UNTERMINATED_MULTI_LINE_COMMENT', "Unterminated multi-line comment.", |
| 170 | + correction: "Try terminating the comment with '*/', or " |
| 171 | + "removing any unbalanced occurrences of '/*'" |
| 172 | + " (because comments nest in Dart)."); |
| 173 | + |
| 174 | + static const ScannerErrorCode UNTERMINATED_STRING_LITERAL = |
| 175 | + const ScannerErrorCode( |
| 176 | + 'UNTERMINATED_STRING_LITERAL', "Unterminated string literal."); |
| 177 | + |
| 178 | + /** |
| 179 | + * Initialize a newly created error code to have the given [name]. The message |
| 180 | + * associated with the error will be created from the given [message] |
| 181 | + * template. The correction associated with the error will be created from the |
| 182 | + * given [correction] template. |
| 183 | + */ |
| 184 | + const ScannerErrorCode(String name, String message, {String correction}) |
| 185 | + : super( |
| 186 | + correction: correction, |
| 187 | + message: message, |
| 188 | + name: name, |
| 189 | + uniqueName: 'ScannerErrorCode.$name', |
| 190 | + ); |
| 191 | + |
| 192 | + @override |
| 193 | + ErrorSeverity get errorSeverity => ErrorSeverity.ERROR; |
| 194 | + |
| 195 | + @override |
| 196 | + ErrorType get type => ErrorType.SYNTACTIC_ERROR; |
| 197 | +} |
0 commit comments