Index: lib/span.dart |
diff --git a/lib/span.dart b/lib/span.dart |
index 4c1c3b707b8f4b982fc4aa2106e021865ed07d4e..19829941f3b07c962f1a159979df29c6dd80181e 100644 |
--- a/lib/span.dart |
+++ b/lib/span.dart |
@@ -18,7 +18,7 @@ abstract class Span implements Comparable { |
/// The end location of this span, exclusive. |
final Location end; |
- /// Url of the file containing this span. |
+ /// Url of the source (typically a file) containing this span. |
String get sourceUrl => start.sourceUrl; |
/// The length of this span, in characters. |
@@ -35,10 +35,9 @@ abstract class Span implements Comparable { |
_checkRange(); |
} |
- /// Creates a new source span that is the union of two existing spans [start] |
- /// and [end]. Note that the resulting span might contain some positions that |
- /// were not in either of the original spans if [start] and [end] are |
- /// disjoint. |
+ /// Creates a new span that is the union of two existing spans [start] and |
+ /// [end]. Note that the resulting span might contain some positions that were |
+ /// not in either of the original spans if [start] and [end] are disjoint. |
Span.union(Span start, Span end) |
: start = start.start, end = end.end, isIdentifier = false { |
_checkRange(); |
@@ -51,8 +50,8 @@ abstract class Span implements Comparable { |
} |
} |
- /// Compares two source spans. If the spans are not in the same file, this |
- /// method generates an error. |
+ /// Compares two spans. If the spans are not in the same source, this method |
+ /// generates an error. |
int compareTo(Span other) { |
int d = start.compareTo(other.start); |
return d == 0 ? end.compareTo(other.end) : d; |
@@ -75,25 +74,25 @@ abstract class Span implements Comparable { |
/// A location in the source text |
abstract class Location implements Comparable { |
- /// Url of the file containing this span. |
+ /// Url of the source containing this span. |
String get sourceUrl; |
/// The offset of this location, 0-based. |
final int offset; |
- /// The 0-based line in the file where of this location. |
+ /// The 0-based line in the source of this location. |
int get line; |
- /// The 0-based column in the file of this location. |
+ /// The 0-based column in the source of this location. |
int get column; |
Location(this.offset); |
- /// Compares two source locations. If the locations are not in the same file, |
- /// this method generates an error. |
+ /// Compares two locations. If the locations are not in the same source, this |
+ /// method generates an error. |
int compareTo(Location other) { |
if (sourceUrl != other.sourceUrl) { |
- throw new ArgumentError('can only compare locations of the same file'); |
+ throw new ArgumentError('can only compare locations of the same source'); |
} |
return offset - other.offset; |
} |
@@ -120,17 +119,16 @@ class FixedSpan extends Span { |
/// Creates a span which starts and end in the same line. |
FixedSpan(String sourceUrl, int start, int line, int column, |
{String text: '', bool isIdentifier: false}) |
- : this.text = text, |
- super(new FixedLocation(start, sourceUrl, line, column), |
+ : text = text, super(new FixedLocation(start, sourceUrl, line, column), |
new FixedLocation(start + text.length, sourceUrl, line, |
column + text.length), |
isIdentifier); |
} |
-/// Implementation of [Location] with values computed from an underling [File]. |
+/// [Location] with values computed from an underling [SourceFile]. |
class FileLocation extends Location { |
- /// The file containing this location. |
- final File file; |
+ /// The source file containing this location. |
+ final SourceFile file; |
String get sourceUrl => file.url; |
int get line => file.getLine(offset); |
@@ -139,28 +137,28 @@ class FileLocation extends Location { |
FileLocation(this.file, int offset): super(offset); |
} |
-/// Implementation of [Span] where values are computed from an underling [File]. |
+/// [Span] where values are computed from an underling [SourceFile]. |
class FileSpan extends Span { |
- /// The file containing this span. |
- final File file; |
+ /// The source file containing this span. |
+ final SourceFile file; |
/// The source text for this span, if available. |
String get text => file.getText(start.offset, end.offset); |
- factory FileSpan(File file, int start, |
+ factory FileSpan(SourceFile file, int start, |
[int end, bool isIdentifier = false]) { |
var startLoc = new FileLocation(file, start); |
var endLoc = end == null ? startLoc : new FileLocation(file, end); |
return new FileSpan.locations(startLoc, endLoc, isIdentifier); |
} |
- FileSpan.locations(FileLocation start, FileLocation end, bool isIdentifier) |
- : this.file = start.file, super(start, end, isIdentifier); |
+ FileSpan.locations(FileLocation start, FileLocation end, |
+ bool isIdentifier) |
+ : file = start.file, super(start, end, isIdentifier); |
- /// Creates a new source span that is the union of two existing spans [start] |
- /// and [end]. Note that the resulting span might contain some positions that |
- /// were not in either of the original spans if [start] and [end] are |
- /// disjoint. |
+ /// Creates a new span that is the union of two existing spans [start] and |
+ /// [end]. Note that the resulting span might contain some positions that were |
+ /// not in either of the original spans if [start] and [end] are disjoint. |
FileSpan.union(FileSpan start, FileSpan end) |
: file = start.file, super.union(start, end) { |
if (start.file != end.file) { |
@@ -186,15 +184,15 @@ const String _NO_COLOR = '\u001b[0m'; |
/// Stores information about a source file, to permit computation of the line |
/// and column. Also contains a nice default error message highlighting the code |
/// location. |
-class File { |
- /// Url where the file is located. |
+class SourceFile { |
+ /// Url where the source file is located. |
final String url; |
final List<int> _lineStarts; |
final List<int> _decodedChars; |
- File(this.url, this._lineStarts, this._decodedChars); |
+ SourceFile(this.url, this._lineStarts, this._decodedChars); |
- File.text(this.url, String text) |
+ SourceFile.text(this.url, String text) |
: _lineStarts = <int>[0], |
_decodedChars = stringToCodepoints(text) { |
for (int i = 0; i < _decodedChars.length; i++) { |
@@ -210,19 +208,19 @@ class File { |
} |
} |
- /// Returns a span in this file with the given offsets. |
+ /// Returns a span in this [SourceFile] with the given offsets. |
Span span(int start, [int end, bool isIdentifier = false]) => |
new FileSpan(this, start, end, isIdentifier); |
- /// Returns a location in this file with the given offset. |
+ /// Returns a location in this [SourceFile] with the given offset. |
Location location(int offset) => new FileLocation(this, offset); |
- /// Gets the 0-based line in the file for this offset. |
+ /// Gets the 0-based line corresponding to an offset. |
int getLine(int offset) { |
return binarySearch(_lineStarts, (o) => o > offset) - 1; |
} |
- /// Gets the 0-based column in the file for this offset. |
+ /// Gets the 0-based column corresponding to an offset. |
int getColumn(int line, int offset) { |
return offset - _lineStarts[line]; |
} |
@@ -237,7 +235,7 @@ class File { |
return codepointsToString(_decodedChars.sublist(start, end)); |
} |
- /// Create a pretty string representation from a span in the file. |
+ /// Create a pretty string representation from a span. |
String getLocationMessage(String message, int start, int end, |
{bool useColors: false, String color}) { |
// TODO(jmesserly): it would be more useful to pass in an object that |
@@ -245,8 +243,8 @@ class File { |
var line = getLine(start); |
var column = getColumn(line, start); |
- var source = url == null ? '' : url; |
- var msg = '$source:${line + 1}:${column + 1}: $message'; |
+ var src = url == null ? '' : url; |
+ var msg = '$src:${line + 1}:${column + 1}: $message'; |
if (_decodedChars == null) { |
// We don't have any text to include, so exit. |
@@ -257,7 +255,7 @@ class File { |
buf.write('\n'); |
var textLine; |
- // +1 for 0-indexing, +1 again to avoid the last line of the file |
+ // +1 for 0-indexing, +1 again to avoid the last line |
if ((line + 2) < _lineStarts.length) { |
textLine = getText(_lineStarts[line], _lineStarts[line + 1]); |
} else { |
@@ -293,20 +291,21 @@ class File { |
} |
} |
-/// A convenience type to treat a code segment as if it were a separate file. An |
-/// [FileSegment] shifts all locations by an offset, which allows you to set |
-/// source-map locations based on the locations relative to the start of the |
-/// segment, but that get translated to absolute locations in the original file. |
-class FileSegment extends File { |
+/// A convenience type to treat a code segment as if it were a separate |
+/// [SourceFile]. A [SourceFileSegment] shifts all locations by an offset, which |
+/// allows you to set source-map locations based on the locations relative to |
+/// the start of the segment, but that get translated to absolute locations in |
+/// the original source file. |
+class SourceFileSegment extends SourceFile { |
final int _baseOffset; |
final int _baseLine; |
final int _baseColumn; |
- FileSegment(String url, String segment, Location startOffset) |
+ SourceFileSegment(String url, String textSegment, Location startOffset) |
: _baseOffset = startOffset.offset, |
_baseLine = startOffset.line, |
_baseColumn = startOffset.column, |
- super.text(url, segment); |
+ super.text(url, textSegment); |
Span span(int start, [int end, bool isIdentifier = false]) => |
super.span(start + _baseOffset, |