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

Unified Diff: pkg/source_span/lib/src/span_exception.dart

Issue 381363002: Extract out a source_span package from source_maps. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: code review Created 6 years, 5 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/source_span/lib/src/span.dart ('k') | pkg/source_span/lib/src/span_mixin.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/source_span/lib/src/span_exception.dart
diff --git a/pkg/source_span/lib/src/span_exception.dart b/pkg/source_span/lib/src/span_exception.dart
new file mode 100644
index 0000000000000000000000000000000000000000..af642413bdda0c2a1a6c20c459b40bd4e4334a5f
--- /dev/null
+++ b/pkg/source_span/lib/src/span_exception.dart
@@ -0,0 +1,43 @@
+// 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 source_span.span_exception;
+
+import 'span.dart';
+
+/// A class for exceptions that have source span information attached.
+class SourceSpanException implements Exception {
+ /// A message describing the exception.
+ final String message;
+
+ /// The span associated with this exception.
+ ///
+ /// This may be `null` if the source location can't be determined.
+ final SourceSpan span;
+
+ SourceSpanException(this.message, this.span);
+
+ /// Returns a string representation of [this].
+ ///
+ /// [color] may either be a [String], a [bool], or `null`. If it's a string,
+ /// it indicates an ANSII terminal color escape that should be used to
+ /// highlight the span's text. If it's `true`, it indicates that the text
+ /// should be highlighted using the default color. If it's `false` or `null`,
+ /// it indicates that the text shouldn't be highlighted.
+ String toString({color}) {
+ if (span == null) return message;
+ return "Error on " + span.message(message, color: color);
+ }
+}
+
+/// A [SourceSpanException] that's also a [FormatException].
+class SourceSpanFormatException extends SourceSpanException
+ implements FormatException {
+ final source;
+
+ int get position => span == null ? null : span.start.offset;
+
+ SourceSpanFormatException(String message, SourceSpan span, [this.source])
+ : super(message, span);
+}
« no previous file with comments | « pkg/source_span/lib/src/span.dart ('k') | pkg/source_span/lib/src/span_mixin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698