Move a number of packages and some of pub over to using source_span.

R=efortuna@google.com, rnystrom@google.com, sigmund@google.com
BUG=19930

Review URL: https://codereview.chromium.org//401753002

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart/pkg/yaml@38526 260f80e4-7a28-3924-810f-c04153c831b5
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e4f532c..94c8807 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,11 @@
+## 2.0.0
+
+* Switch from `source_maps`' `Span` class to `source_span`'s `SourceSpan` class.
+
+* For consistency with `source_span` and `string_scanner`, all `sourceName`
+  parameters have been renamed to `sourceUrl`. They now accept Urls as well as
+  Strings.
+
 ## 1.1.1
 
 * Fix broken type arguments that caused breakage on dart2js.
diff --git a/lib/src/model.dart b/lib/src/model.dart
index 0973769..93cb49c 100644
--- a/lib/src/model.dart
+++ b/lib/src/model.dart
@@ -7,7 +7,7 @@
 /// representation graph.
 library yaml.model;
 
-import 'package:source_maps/source_maps.dart';
+import 'package:source_span/source_span.dart';
 
 import 'equality.dart';
 import 'parser.dart';
@@ -83,7 +83,7 @@
   String anchor;
 
   /// The source span for this node.
-  Span span;
+  SourceSpan span;
 
   Node(this.tag, this.span, [this.anchor]);
 
@@ -102,7 +102,7 @@
   /// The nodes in the sequence.
   List<Node> content;
 
-  SequenceNode(String tagName, this.content, Span span)
+  SequenceNode(String tagName, this.content, SourceSpan span)
     : super(new Tag.sequence(tagName), span);
 
   /// Two sequences are equal if their tags and contents are equal.
@@ -125,7 +125,7 @@
 
 /// An alias node is a reference to an anchor.
 class AliasNode extends Node {
-  AliasNode(String anchor, Span span)
+  AliasNode(String anchor, SourceSpan span)
       : super(new Tag.scalar(Tag.yaml("str")), span, anchor);
 
   visit(Visitor v) => v.visitAlias(this);
@@ -145,7 +145,7 @@
   /// be specified for a newly-parsed scalar that hasn't yet been composed.
   /// Value should be specified for a composed scalar, although `null` is a
   /// valid value.
-  ScalarNode(String tagName, Span span, {String content, this.value})
+  ScalarNode(String tagName, SourceSpan span, {String content, this.value})
    : _content = content,
      super(new Tag.scalar(tagName), span);
 
@@ -231,7 +231,7 @@
   /// The node map.
   Map<Node, Node> content;
 
-  MappingNode(String tagName, this.content, Span span)
+  MappingNode(String tagName, this.content, SourceSpan span)
     : super(new Tag.mapping(tagName), span);
 
   /// Two mappings are equal if their tags and contents are equal.
diff --git a/lib/src/null_span.dart b/lib/src/null_span.dart
index b3e3254..1054df1 100644
--- a/lib/src/null_span.dart
+++ b/lib/src/null_span.dart
@@ -4,44 +4,18 @@
 
 library yaml.null_span;
 
-import 'package:path/path.dart' as p;
-import 'package:source_maps/source_maps.dart';
+import 'package:source_span/source_span.dart';
 
 /// A [Span] with no location information.
 ///
 /// This is used with [YamlMap.wrap] and [YamlList.wrap] to provide means of
 /// accessing a non-YAML map that behaves transparently like a map parsed from
 /// YAML.
-class NullSpan extends Span {
-  Location get end => start;
+class NullSpan extends SourceSpanMixin {
+  final SourceLocation start;
+  SourceLocation get end => start;
   final text = "";
 
-  NullSpan(String sourceUrl)
-      : this._(new NullLocation(sourceUrl));
-
-  NullSpan._(Location location)
-      : super(location, location, false);
-
-  String formatLocationMessage(String message, {bool useColors: false,
-      String color}) {
-    var locationMessage = sourceUrl == null ? "in an unknown location" :
-        "in ${p.prettyUri(sourceUrl)}";
-    return "$locationMessage: $message";
-  }
-}
-
-/// A [Location] with no location information.
-///
-/// This is used with [YamlMap.wrap] and [YamlList.wrap] to provide means of
-/// accessing a non-YAML map that behaves transparently like a map parsed from
-/// YAML.
-class NullLocation extends Location {
-  final String sourceUrl;
-  final line = 0;
-  final column = 0;
-
-  String get formatString => sourceUrl == null ? "unknown location" : sourceUrl;
-
-  NullLocation(this.sourceUrl)
-      : super(0);
+  NullSpan(sourceUrl)
+      : start = new SourceLocation(0, sourceUrl: sourceUrl);
 }
diff --git a/lib/src/parser.dart b/lib/src/parser.dart
index b42638f..94f551f 100644
--- a/lib/src/parser.dart
+++ b/lib/src/parser.dart
@@ -6,7 +6,7 @@
 
 import 'dart:collection';
 
-import 'package:source_maps/source_maps.dart';
+import 'package:source_span/source_span.dart';
 import 'package:string_scanner/string_scanner.dart';
 
 import 'equality.dart';
@@ -151,8 +151,8 @@
   /// Whether the current string capture is being overridden.
   bool _capturingAs = false;
 
-  Parser(String yaml, String sourceName)
-      : _scanner = new SpanScanner(yaml, sourceName) {
+  Parser(String yaml, sourceUrl)
+      : _scanner = new SpanScanner(yaml, sourceUrl: sourceUrl) {
     _farthestState = _scanner.state;
   }
 
@@ -326,7 +326,7 @@
   }
 
   /// Creates a MappingNode from [pairs].
-  MappingNode map(List<Pair<Node, Node>> pairs, Span span) {
+  MappingNode map(List<Pair<Node, Node>> pairs, SourceSpan span) {
     var content = new Map<Node, Node>();
     pairs.forEach((pair) => content[pair.first] = pair.last);
     return new MappingNode("?", content, span);
@@ -1822,7 +1822,7 @@
     or([l_directiveDocument, l_explicitDocument, l_bareDocument]);
 
   // 211
-  Pair<List<Node>, Span> l_yamlStream() {
+  Pair<List<Node>, SourceSpan> l_yamlStream() {
     var start = _scanner.state;
     var docs = [];
     zeroOrMore(l_documentPrefix);
diff --git a/lib/src/yaml_exception.dart b/lib/src/yaml_exception.dart
index 9d43717..8689953 100644
--- a/lib/src/yaml_exception.dart
+++ b/lib/src/yaml_exception.dart
@@ -4,11 +4,11 @@
 
 library yaml.exception;
 
-import 'package:source_maps/source_maps.dart';
+import 'package:source_span/source_span.dart';
 
 /// An error thrown by the YAML processor.
-class YamlException extends SpanFormatException {
-  YamlException(String message, Span span)
+class YamlException extends SourceSpanFormatException {
+  YamlException(String message, SourceSpan span)
       : super(message, span);
 }
 
diff --git a/lib/src/yaml_node.dart b/lib/src/yaml_node.dart
index 1aded2b..4f77060 100644
--- a/lib/src/yaml_node.dart
+++ b/lib/src/yaml_node.dart
@@ -7,7 +7,7 @@
 import 'dart:collection' as collection;
 
 import 'package:collection/collection.dart';
-import 'package:source_maps/source_maps.dart';
+import 'package:source_span/source_span.dart';
 
 import 'null_span.dart';
 import 'yaml_node_wrapper.dart';
@@ -24,9 +24,9 @@
 abstract class YamlNode {
   /// The source span for this node.
   ///
-  /// [Span.getLocationMessage] can be used to produce a human-friendly message
-  /// about this node.
-  Span get span;
+  /// [SourceSpan.message] can be used to produce a human-friendly message about
+  /// this node.
+  SourceSpan get span;
 
   /// The inner value of this node.
   ///
@@ -38,7 +38,7 @@
 
 /// A read-only [Map] parsed from YAML.
 class YamlMap extends YamlNode with collection.MapMixin, UnmodifiableMapMixin  {
-  final Span span;
+  final SourceSpan span;
 
   /// A view of [this] where the keys and values are guaranteed to be
   /// [YamlNode]s.
@@ -57,20 +57,24 @@
   /// Creates an empty YamlMap.
   ///
   /// This map's [span] won't have useful location information. However, it will
-  /// have a reasonable implementation of [Span.getLocationMessage]. If
-  /// [sourceName] is passed, it's used as the [Span.sourceUrl].
-  factory YamlMap({String sourceName}) =>
-      new YamlMapWrapper(const {}, sourceName);
+  /// have a reasonable implementation of [SourceSpan.message]. If [sourceUrl]
+  /// is passed, it's used as the [SourceSpan.sourceUrl].
+  ///
+  /// [sourceUrl] may be either a [String], a [Uri], or `null`.
+  factory YamlMap({sourceUrl}) =>
+      new YamlMapWrapper(const {}, sourceUrl);
 
   /// Wraps a Dart map so that it can be accessed (recursively) like a
   /// [YamlMap].
   ///
-  /// Any [Span]s returned by this map or its children will be dummies without
-  /// useful location information. However, they will have a reasonable
-  /// implementation of [Span.getLocationMessage]. If [sourceName] is passed,
-  /// it's used as the [Span.sourceUrl].
-  factory YamlMap.wrap(Map dartMap, {String sourceName}) =>
-      new YamlMapWrapper(dartMap, sourceName);
+  /// Any [SourceSpan]s returned by this map or its children will be dummies
+  /// without useful location information. However, they will have a reasonable
+  /// implementation of [SourceSpan.getLocationMessage]. If [sourceUrl] is
+  /// passed, it's used as the [SourceSpan.sourceUrl].
+  ///
+  /// [sourceUrl] may be either a [String], a [Uri], or `null`.
+  factory YamlMap.wrap(Map dartMap, {sourceUrl}) =>
+      new YamlMapWrapper(dartMap, sourceUrl);
 
   /// Users of the library should not use this constructor.
   YamlMap.internal(Map<dynamic, YamlNode> nodes, this.span)
@@ -85,7 +89,7 @@
 // TODO(nweiz): Use UnmodifiableListMixin when issue 18970 is fixed.
 /// A read-only [List] parsed from YAML.
 class YamlList extends YamlNode with collection.ListMixin {
-  final Span span;
+  final SourceSpan span;
 
   final List<YamlNode> nodes;
 
@@ -100,20 +104,24 @@
   /// Creates an empty YamlList.
   ///
   /// This list's [span] won't have useful location information. However, it
-  /// will have a reasonable implementation of [Span.getLocationMessage]. If
-  /// [sourceName] is passed, it's used as the [Span.sourceUrl].
-  factory YamlList({String sourceName}) =>
-      new YamlListWrapper(const [], sourceName);
+  /// will have a reasonable implementation of [SourceSpan.message]. If
+  /// [sourceUrl] is passed, it's used as the [SourceSpan.sourceUrl].
+  ///
+  /// [sourceUrl] may be either a [String], a [Uri], or `null`.
+  factory YamlList({sourceUrl}) =>
+      new YamlListWrapper(const [], sourceUrl);
 
   /// Wraps a Dart list so that it can be accessed (recursively) like a
   /// [YamlList].
   ///
-  /// Any [Span]s returned by this list or its children will be dummies without
-  /// useful location information. However, they will have a reasonable
-  /// implementation of [Span.getLocationMessage]. If [sourceName] is passed,
-  /// it's used as the [Span.sourceUrl].
-  factory YamlList.wrap(List dartList, {String sourceName}) =>
-      new YamlListWrapper(dartList, sourceName);
+  /// Any [SourceSpan]s returned by this list or its children will be dummies
+  /// without useful location information. However, they will have a reasonable
+  /// implementation of [SourceSpan.getLocationMessage]. If [sourceUrl] is
+  /// passed, it's used as the [Span.sourceUrl].
+  ///
+  /// [sourceUrl] may be either a [String], a [Uri], or `null`.
+  factory YamlList.wrap(List dartList, {sourceUrl}) =>
+      new YamlListWrapper(dartList, sourceUrl);
 
   /// Users of the library should not use this constructor.
   YamlList.internal(List<YamlNode> nodes, this.span)
@@ -128,17 +136,19 @@
 
 /// A wrapped scalar value parsed from YAML.
 class YamlScalar extends YamlNode {
-  final Span span;
+  final SourceSpan span;
 
   final value;
 
   /// Wraps a Dart value in a [YamlScalar].
   ///
   /// This scalar's [span] won't have useful location information. However, it
-  /// will have a reasonable implementation of [Span.getLocationMessage]. If
-  /// [sourceName] is passed, it's used as the [Span.sourceUrl].
-  YamlScalar.wrap(this.value, {String sourceName})
-      : span = new NullSpan(sourceName);
+  /// will have a reasonable implementation of [SourceSpan.message]. If
+  /// [sourceUrl] is passed, it's used as the [Span.sourceUrl].
+  ///
+  /// [sourceUrl] may be either a [String], a [Uri], or `null`.
+  YamlScalar.wrap(this.value, {sourceUrl})
+      : span = new NullSpan(sourceUrl);
 
   /// Users of the library should not use this constructor.
   YamlScalar.internal(this.value, this.span);
diff --git a/lib/src/yaml_node_wrapper.dart b/lib/src/yaml_node_wrapper.dart
index 2dcaa23..d000dcb 100644
--- a/lib/src/yaml_node_wrapper.dart
+++ b/lib/src/yaml_node_wrapper.dart
@@ -7,7 +7,7 @@
 import 'dart:collection';
 
 import 'package:collection/collection.dart' as pkg_collection;
-import 'package:source_maps/source_maps.dart';
+import 'package:source_span/source_span.dart';
 
 import 'null_span.dart';
 import 'yaml_node.dart';
@@ -18,7 +18,7 @@
     implements YamlMap {
   final Map _dartMap;
 
-  final Span span;
+  final SourceSpan span;
 
   final Map<dynamic, YamlNode> nodes;
 
@@ -26,10 +26,10 @@
 
   Iterable get keys => _dartMap.keys;
 
-  YamlMapWrapper(Map dartMap, String sourceName)
-      : this._(dartMap, new NullSpan(sourceName));
+  YamlMapWrapper(Map dartMap, sourceUrl)
+      : this._(dartMap, new NullSpan(sourceUrl));
 
-  YamlMapWrapper._(Map dartMap, Span span)
+  YamlMapWrapper._(Map dartMap, SourceSpan span)
       : _dartMap = dartMap,
         span = span,
         nodes = new _YamlMapNodes(dartMap, span);
@@ -53,7 +53,7 @@
     with pkg_collection.UnmodifiableMapMixin<dynamic, YamlNode> {
   final Map _dartMap;
 
-  final Span _span;
+  final SourceSpan _span;
 
   Iterable get keys =>
       _dartMap.keys.map((key) => new YamlScalar.internal(key, _span));
@@ -78,7 +78,7 @@
 class YamlListWrapper extends ListBase implements YamlList {
   final List _dartList;
 
-  final Span span;
+  final SourceSpan span;
 
   final List<YamlNode> nodes;
 
@@ -90,10 +90,10 @@
     throw new UnsupportedError("Cannot modify an unmodifiable List.");
   }
 
-  YamlListWrapper(List dartList, String sourceName)
-      : this._(dartList, new NullSpan(sourceName));
+  YamlListWrapper(List dartList, sourceUrl)
+      : this._(dartList, new NullSpan(sourceUrl));
 
-  YamlListWrapper._(List dartList, Span span)
+  YamlListWrapper._(List dartList, SourceSpan span)
       : _dartList = dartList,
         span = span,
         nodes = new _YamlListNodes(dartList, span);
@@ -121,7 +121,7 @@
 class _YamlListNodes extends ListBase<YamlNode> {
   final List _dartList;
 
-  final Span _span;
+  final SourceSpan _span;
 
   int get length => _dartList.length;
 
@@ -143,7 +143,7 @@
       other is _YamlListNodes && other._dartList == _dartList;
 }
 
-YamlNode _nodeForValue(value, Span span) {
+YamlNode _nodeForValue(value, SourceSpan span) {
   if (value is Map) return new YamlMapWrapper._(value, span);
   if (value is List) return new YamlListWrapper._(value, span);
   return new YamlScalar.internal(value, span);
diff --git a/lib/yaml.dart b/lib/yaml.dart
index 0afc2cc..e45dd6e 100644
--- a/lib/yaml.dart
+++ b/lib/yaml.dart
@@ -29,18 +29,18 @@
 /// In future versions, maps will instead be [HashMap]s with a custom equality
 /// operation.
 ///
-/// If [sourceName] is passed, it's used as the name of the file or URL from
-/// which the YAML originated for error reporting.
-loadYaml(String yaml, {String sourceName}) =>
-    loadYamlNode(yaml, sourceName: sourceName).value;
+/// If [sourceUrl] is passed, it's used as the URL from which the YAML
+/// originated for error reporting. It can be a [String], a [Uri], or `null`.
+loadYaml(String yaml, {sourceUrl}) =>
+    loadYamlNode(yaml, sourceUrl: sourceUrl).value;
 
 /// Loads a single document from a YAML string as a [YamlNode].
 ///
 /// This is just like [loadYaml], except that where [loadYaml] would return a
 /// normal Dart value this returns a [YamlNode] instead. This allows the caller
 /// to be confident that the return value will always be a [YamlNode].
-YamlNode loadYamlNode(String yaml, {String sourceName}) {
-  var stream = loadYamlStream(yaml, sourceName: sourceName);
+YamlNode loadYamlNode(String yaml, {sourceUrl}) {
+  var stream = loadYamlStream(yaml, sourceUrl: sourceUrl);
   if (stream.length != 1) {
     throw new YamlException("Expected 1 document, were ${stream.length}.",
         stream.span);
@@ -59,12 +59,12 @@
 /// In future versions, maps will instead be [HashMap]s with a custom equality
 /// operation.
 ///
-/// If [sourceName] is passed, it's used as the name of the file or URL from
-/// which the YAML originated for error reporting.
-YamlList loadYamlStream(String yaml, {String sourceName}) {
+/// If [sourceUrl] is passed, it's used as the URL from which the YAML
+/// originated for error reporting. It can be a [String], a [Uri], or `null`.
+YamlList loadYamlStream(String yaml, {sourceUrl}) {
   var pair;
   try {
-    pair = new Parser(yaml, sourceName).l_yamlStream();
+    pair = new Parser(yaml, sourceUrl).l_yamlStream();
   } on StringScannerException catch (error) {
     throw new YamlException(error.message, error.span);
   }
diff --git a/pubspec.yaml b/pubspec.yaml
index c160482..470bc2f 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,13 +1,13 @@
 name: yaml
-version: 1.1.1
+version: 2.0.0
 author: "Dart Team <misc@dartlang.org>"
 homepage: http://www.dartlang.org
 description: A parser for YAML.
 dependencies:
   collection: ">=0.9.2 <0.10.0"
   path: ">=1.2.0 <2.0.0"
-  string_scanner: ">=0.0.2 <0.1.0"
-  source_maps: ">=0.9.2 <0.10.0"
+  string_scanner: ">=0.1.0 <0.2.0"
+  source_span: ">=1.0.0 <2.0.0"
 dev_dependencies:
   unittest: ">=0.9.0 <0.12.0"
 environment:
diff --git a/test/yaml_node_wrapper_test.dart b/test/yaml_node_wrapper_test.dart
index 8bf4761..7d4faa6 100644
--- a/test/yaml_node_wrapper_test.dart
+++ b/test/yaml_node_wrapper_test.dart
@@ -9,31 +9,31 @@
 import 'package:yaml/yaml.dart';
 
 main() {
-  test("YamlMap() with no sourceName", () {
+  test("YamlMap() with no sourceUrl", () {
     var map = new YamlMap();
     expect(map, isEmpty);
     expect(map.nodes, isEmpty);
     expect(map.span, isNullSpan(isNull));
   });
 
-  test("YamlMap() with a sourceName", () {
-    var map = new YamlMap(sourceName: "source");
+  test("YamlMap() with a sourceUrl", () {
+    var map = new YamlMap(sourceUrl: "source");
     expect(map.span, isNullSpan("source"));
   });
 
-  test("YamlList() with no sourceName", () {
+  test("YamlList() with no sourceUrl", () {
     var list = new YamlList();
     expect(list, isEmpty);
     expect(list.nodes, isEmpty);
     expect(list.span, isNullSpan(isNull));
   });
 
-  test("YamlList() with a sourceName", () {
-    var list = new YamlList(sourceName: "source");
+  test("YamlList() with a sourceUrl", () {
+    var list = new YamlList(sourceUrl: "source");
     expect(list.span, isNullSpan("source"));
   });
 
-  test("YamlMap.wrap() with no sourceName", () {
+  test("YamlMap.wrap() with no sourceUrl", () {
     var map = new YamlMap.wrap({
       "list": [1, 2, 3],
       "map": {
@@ -69,7 +69,7 @@
     expect(map.nodes[new YamlScalar.wrap("list")], equals([1, 2, 3]));
   });
 
-  test("YamlMap.wrap() with a sourceName", () {
+  test("YamlMap.wrap() with a sourceUrl", () {
     var map = new YamlMap.wrap({
       "list": [1, 2, 3],
       "map": {
@@ -77,7 +77,7 @@
         "nested": [4, 5, 6]
       },
       "scalar": "value"
-    }, sourceName: "source");
+    }, sourceUrl: "source");
 
     expect(map.span, isNullSpan("source"));
     expect(map["list"].span, isNullSpan("source"));
@@ -85,7 +85,7 @@
     expect(map.nodes["scalar"].span, isNullSpan("source"));
   });
 
-  test("YamlList.wrap() with no sourceName", () {
+  test("YamlList.wrap() with no sourceUrl", () {
     var list = new YamlList.wrap([
       [1, 2, 3],
       {
@@ -118,7 +118,7 @@
     expect(list[2], "value");
   });
 
-  test("YamlList.wrap() with a sourceName", () {
+  test("YamlList.wrap() with a sourceUrl", () {
     var list = new YamlList.wrap([
       [1, 2, 3],
       {