Chromium Code Reviews| Index: pkg/string_scanner/lib/src/exception.dart |
| diff --git a/pkg/string_scanner/lib/src/exception.dart b/pkg/string_scanner/lib/src/exception.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..c3986871a8cff41e0f5219616c6700faa7ac8964 |
| --- /dev/null |
| +++ b/pkg/string_scanner/lib/src/exception.dart |
| @@ -0,0 +1,37 @@ |
| +// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +library string_scanner.exception; |
| + |
| +import 'package:source_maps/source_maps.dart'; |
| + |
| +/// An exception thrown by a [StringScanner] that failed to parse a string. |
| +class StringScannerException implements FormatException { |
| + /// The error message. |
| + final String message; |
| + |
| + /// The source string being parsed. |
| + final String string; |
|
Bob Nystrom
2014/05/28 21:28:57
Given that you use "sourceUrl" below, how about "s
nweiz
2014/05/28 23:56:34
I think it's better that it match [StringScanner.s
|
| + |
| + /// The URL of the source file being parsed. |
| + /// |
| + /// This may be `null`, indicating that the source URL is unknown. |
| + final Uri sourceUrl; |
| + |
| + /// The span within [string] that caused the exception. |
| + final Span span; |
| + |
| + StringScannerException(this.message, this.string, this.sourceUrl, this.span); |
| + |
| + /// Returns a detailed description of this exception. |
| + /// |
| + /// If [useColors] is true, the section of the source that caused the |
| + /// exception will be colored using ANSI color codes. By default, it's colored |
| + /// red, but a different ANSI code may passed via [color]. |
| + String toString({bool useColors: false, String color}) { |
|
Bob Nystrom
2014/05/28 21:28:57
I'd personally prefer not using a default value he
nweiz
2014/05/28 23:56:34
I generally agree for non-boolean values, but for
Bob Nystrom
2014/05/29 15:51:00
I definitely agree that users need to understand w
nweiz
2014/05/29 20:06:26
I don't think allowing users to pass null to any o
|
| + return "Error on " + span.getLocationMessage( |
| + message, useColors: useColors, color: color); |
| + } |
| +} |
| + |