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

Unified Diff: lib/src/span.dart

Issue 1028813002: Introduce span with line context (Closed) Base URL: git@github.com:dart-lang/source_span.git@master
Patch Set: Created 5 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 side-by-side diff with in-line comments
Download patch
Index: lib/src/span.dart
diff --git a/lib/src/span.dart b/lib/src/span.dart
index 9f150482c6da354adbbad9753a12a306b4bf432c..bb66d169f8eb95d56c98c0fe6de0b43137a992b8 100644
--- a/lib/src/span.dart
+++ b/lib/src/span.dart
@@ -5,6 +5,7 @@
library source_span.span;
import 'location.dart';
+import 'span_context.dart';
import 'span_mixin.dart';
/// A class that describes a segment of source text.
@@ -76,3 +77,26 @@ class SourceSpanBase extends SourceSpanMixin {
}
}
}
+
+/// A class that describes a segment of source text.
nweiz 2015/03/24 23:01:17 Update this doc comment.
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Done.
+class SourceSpanWithContext extends SourceSpanBase
+ implements SourceSpanContext {
+ /// Line containing the source-span
nweiz 2015/03/24 23:01:17 "The text of the line containing this span. If th
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Sounds good. Done
+ final String contextLine;
+
+ /// Creates a new span from [start] to [end] (exclusive) containing [text], in
+ /// the context of [contextLine].
+ ///
+ /// [start] and [end] must have the same source URL and [start] must come
+ /// before [end]. [text] must have a number of characters equal to the
+ /// distance between [start] and [end]. [contextLine] must contain [text], and
+ /// [text] should start at `start.column`.
+ SourceSpanWithContext(SourceLocation start, SourceLocation end, String text,
+ this.contextLine) : super(start, end, text) {
nweiz 2015/03/24 23:01:17 Nit: put the super call on its own line.
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Done. This made me realized I was not running the
nweiz 2015/03/25 01:10:39 I actually prefer to have format-everything CLs se
Siggi Cherem (dart-lang) 2015/03/26 21:07:29 OK reverted all other formatter changes. In dev_c
+ var index = contextLine.indexOf(text);
+ if (index != start.column) {
+ throw new ArgumentError('The context line "$contextLine" must '
+ 'contain "$text" starting at column ${start.column + 1}.');
nweiz 2015/03/24 23:01:17 I'd throw separate errors for [contextLine] not co
Siggi Cherem (dart-lang) 2015/03/25 00:33:25 Done.
+ }
+ }
+}

Powered by Google App Engine
This is Rietveld 408576698