OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 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. |
| 4 |
| 5 library source_span.span_exception; |
| 6 |
| 7 import 'span.dart'; |
| 8 |
| 9 /// A class for exceptions that have source span information attached. |
| 10 class SourceSpanException implements Exception { |
| 11 /// A message describing the exception. |
| 12 final String message; |
| 13 |
| 14 /// The span associated with this exception. |
| 15 /// |
| 16 /// This may be `null` if the source location can't be determined. |
| 17 final SourceSpan span; |
| 18 |
| 19 SourceSpanException(this.message, this.span); |
| 20 |
| 21 /// Returns a string representation of [this]. |
| 22 /// |
| 23 /// [color] may either be a [String], a [bool], or `null`. If it's a string, |
| 24 /// it indicates an ANSII terminal color escape that should be used to |
| 25 /// highlight the span's text. If it's `true`, it indicates that the text |
| 26 /// should be highlighted using the default color. If it's `false` or `null`, |
| 27 /// it indicates that the text shouldn't be highlighted. |
| 28 String toString({color}) { |
| 29 if (span == null) return message; |
| 30 return "Error on " + span.message(message, color: color); |
| 31 } |
| 32 } |
| 33 |
| 34 /// A [SourceSpanException] that's also a [FormatException]. |
| 35 class SourceSpanFormatException extends SourceSpanException |
| 36 implements FormatException { |
| 37 final source; |
| 38 |
| 39 int get offset => span == null ? null : span.start.offset; |
| 40 |
| 41 SourceSpanFormatException(String message, SourceSpan span, [this.source]) |
| 42 : super(message, span); |
| 43 } |
OLD | NEW |