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

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
« no previous file with comments | « lib/src/location.dart ('k') | lib/src/span_mixin.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/span.dart
diff --git a/lib/src/span.dart b/lib/src/span.dart
index 9f150482c6da354adbbad9753a12a306b4bf432c..6f9013e55dc3b582ae01205ace1976110e557db9 100644
--- a/lib/src/span.dart
+++ b/lib/src/span.dart
@@ -57,6 +57,25 @@ abstract class SourceSpan implements Comparable<SourceSpan> {
String message(String message, {color});
}
+/// A class that describes a segment of source text with additional context.
+abstract class SourceSpanWithContext extends SourceSpan {
nweiz 2015/03/25 01:15:20 Now that I think about it, it would be nice to hav
Siggi Cherem (dart-lang) 2015/03/26 21:07:29 Done.
+ /// The text of the line containing this span.
+ ///
+ /// If the span covers multiple lines, this should only contain the first.
+ final String context;
+
+ /// Creates a new span from [start] to [end] (exclusive) containing [text], in
+ /// the [context] line.
+ ///
+ /// [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]. [context] must contain [text], and
+ /// [text] should start at `start.column` within [context].
+ factory SourceSpanWithContext(
+ SourceLocation start, SourceLocation end, String text, String context) =
+ SourceSpanWithContextBase;
+}
+
/// A base class for source spans with [start], [end], and [text] known at
/// construction time.
class SourceSpanBase extends SourceSpanMixin {
@@ -76,3 +95,33 @@ class SourceSpanBase extends SourceSpanMixin {
}
}
}
+
+/// A base class for source spans with [start], [end], [text], and [context]
+/// known at construction time.
+class SourceSpanWithContextBase extends SourceSpanBase
+ implements SourceSpanWithContext {
+ /// The text of the line containing this span.
+ ///
+ /// If the span covers multiple lines, this should only contain the first.
nweiz 2015/03/25 01:10:39 I just realized that this property is incorrect; t
Siggi Cherem (dart-lang) 2015/03/26 21:07:29 I went with somewhere in between. I validate that
+ final String context;
+
+ /// Creates a new span from [start] to [end] (exclusive) containing [text], in
+ /// the [context] line.
+ ///
+ /// [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]. [context] must contain [text], and
+ /// [text] should start at `start.column` within [context].
+ SourceSpanWithContextBase(
+ SourceLocation start, SourceLocation end, String text, this.context)
+ : super(start, end, text) {
+ var index = context.indexOf(text);
+ if (index == -1) {
+ throw new ArgumentError(
+ 'The context line "$context" must contain "$text".');
+ } else if (index != start.column) {
+ throw new ArgumentError('The span text "$text" must start at '
+ 'column ${start.column + 1} in the context line "$context".');
+ }
+ }
+}
« no previous file with comments | « lib/src/location.dart ('k') | lib/src/span_mixin.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698