Add SpanScanner.location. Also explicitly expose FileSpans and FileLocations. R=rnystrom@google.com Review URL: https://codereview.chromium.org//683323002 git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/string_scanner@41383 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/pkgs/string_scanner/CHANGELOG.md b/pkgs/string_scanner/CHANGELOG.md index f1d8763..d7f09f3 100644 --- a/pkgs/string_scanner/CHANGELOG.md +++ b/pkgs/string_scanner/CHANGELOG.md
@@ -1,3 +1,12 @@ +## 0.1.1 + +* Declare `SpanScanner`'s exposed `SourceSpan`s and `SourceLocation`s to be + `FileSpan`s and `FileLocation`s. They always were underneath, but callers may + now rely on it. + +* Add `SpanScanner.location`, which returns the scanner's current + `SourceLocation`. + ## 0.1.0 * Switch from `source_maps`' `Span` class to `source_span`'s `SourceSpan` class.
diff --git a/pkgs/string_scanner/lib/src/span_scanner.dart b/pkgs/string_scanner/lib/src/span_scanner.dart index d8dc230..a70d5fd 100644 --- a/pkgs/string_scanner/lib/src/span_scanner.dart +++ b/pkgs/string_scanner/lib/src/span_scanner.dart
@@ -34,28 +34,31 @@ this.position = state.position; } - /// The [SourceSpan] for [lastMatch]. + /// The [FileSpan] for [lastMatch]. /// /// This is the span for the entire match. There's no way to get spans for /// subgroups since [Match] exposes no information about their positions. - SourceSpan get lastSpan => _lastSpan; - SourceSpan _lastSpan; + FileSpan get lastSpan => _lastSpan; + FileSpan _lastSpan; + + /// The current location of the scanner. + FileLocation get location => _sourceFile.location(position); /// Returns an empty span at the current location. - SourceSpan get emptySpan => _sourceFile.location(position).pointSpan(); + FileSpan get emptySpan => location.pointSpan(); /// Creates a new [SpanScanner] that starts scanning from [position]. /// /// [sourceUrl] is used as [SourceLocation.sourceUrl] for the returned - /// [SourceSpan]s as well as for error reporting. It can be a [String], a + /// [FileSpan]s as well as for error reporting. It can be a [String], a /// [Uri], or `null`. SpanScanner(String string, {sourceUrl, int position}) : _sourceFile = new SourceFile(string, url: sourceUrl), super(string, sourceUrl: sourceUrl, position: position); - /// Creates a [SourceSpan] representing the source range between [startState] + /// Creates a [FileSpan] representing the source range between [startState] /// and the current position. - SourceSpan spanFrom(LineScannerState startState) => + FileSpan spanFrom(LineScannerState startState) => _sourceFile.span(startState.position, position); bool matches(Pattern pattern) {
diff --git a/pkgs/string_scanner/pubspec.yaml b/pkgs/string_scanner/pubspec.yaml index 1451fc5..831dfac 100644 --- a/pkgs/string_scanner/pubspec.yaml +++ b/pkgs/string_scanner/pubspec.yaml
@@ -1,5 +1,5 @@ name: string_scanner -version: 0.1.0 +version: 0.1.1 author: "Dart Team <misc@dartlang.org>" homepage: http://www.dartlang.org description: >