Skip to content

Commit

Permalink
Merge pull request flutter#94 from dart-lang/null_safety
Browse files Browse the repository at this point in the history
migrate to nnbd
  • Loading branch information
pq authored Nov 10, 2020
2 parents 093fcb9 + 7bf1948 commit 925c406
Show file tree
Hide file tree
Showing 16 changed files with 130 additions and 125 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
language: dart

dart:
- 2.4.0
- dev

dart_task:
Expand Down
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
## 2.3.0-dev

## 3.0.0-nullsafety
* Updated to support 2.12.0 and null safety.
* Allow `YamlNode`s to be wrapped with an optional `style` parameter.

## 2.2.1
Expand Down
20 changes: 10 additions & 10 deletions lib/src/event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DocumentStartEvent implements Event {
final FileSpan span;

/// The document's `%YAML` directive, or `null` if there was none.
final VersionDirective versionDirective;
final VersionDirective? versionDirective;

/// The document's `%TAG` directives, if any.
final List<TagDirective> tagDirectives;
Expand All @@ -37,7 +37,7 @@ class DocumentStartEvent implements Event {

DocumentStartEvent(this.span,
{this.versionDirective,
List<TagDirective> tagDirectives,
List<TagDirective>? tagDirectives,
this.isImplicit = true})
: tagDirectives = tagDirectives ?? [];

Expand Down Expand Up @@ -81,10 +81,10 @@ class AliasEvent implements Event {
/// An event that can have associated anchor and tag properties.
abstract class _ValueEvent implements Event {
/// The name of the value's anchor, or `null` if it wasn't anchored.
String get anchor;
String? get anchor;

/// The text of the value's tag, or `null` if it wasn't tagged.
String get tag;
String? get tag;

@override
String toString() {
Expand All @@ -102,9 +102,9 @@ class ScalarEvent extends _ValueEvent {
@override
final FileSpan span;
@override
final String anchor;
final String? anchor;
@override
final String tag;
final String? tag;

/// The contents of the scalar.
final String value;
Expand All @@ -125,9 +125,9 @@ class SequenceStartEvent extends _ValueEvent {
@override
final FileSpan span;
@override
final String anchor;
final String? anchor;
@override
final String tag;
final String? tag;

/// The style of the collection in the original source.
final CollectionStyle style;
Expand All @@ -142,9 +142,9 @@ class MappingStartEvent extends _ValueEvent {
@override
final FileSpan span;
@override
final String anchor;
final String? anchor;
@override
final String tag;
final String? tag;

/// The style of the collection in the original source.
final CollectionStyle style;
Expand Down
26 changes: 14 additions & 12 deletions lib/src/loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ class Loader {
/// Creates a loader that loads [source].
///
/// [sourceUrl] can be a String or a [Uri].
Loader(String source, {sourceUrl})
: _parser = Parser(source, sourceUrl: sourceUrl) {
var event = _parser.parse();
_span = event.span;
factory Loader(String source, {sourceUrl}) {
var parser = Parser(source, sourceUrl: sourceUrl);
var event = parser.parse();
assert(event.type == EventType.streamStart);
return Loader._(parser, event.span);
}

Loader._(this._parser, this._span);

/// Loads the next document from the stream.
///
/// If there are no more documents, returns `null`.
YamlDocument load() {
YamlDocument? load() {
if (_parser.isDone) return null;

var event = _parser.parse();
Expand Down Expand Up @@ -90,7 +92,7 @@ class Loader {
}

/// Registers an anchor.
void _registerAnchor(String anchor, YamlNode node) {
void _registerAnchor(String? anchor, YamlNode node) {
if (anchor == null) return;

// libyaml throws an error for duplicate anchors, but example 7.1 makes it
Expand Down Expand Up @@ -207,7 +209,7 @@ class Loader {
///
/// If parsing fails, this returns `null`, indicating that the scalar should
/// be parsed as a string.
YamlScalar _tryParseScalar(ScalarEvent scalar) {
YamlScalar? _tryParseScalar(ScalarEvent scalar) {
// Quickly check for the empty string, which means null.
var length = scalar.value.length;
if (length == 0) return YamlScalar.internal(null, scalar);
Expand Down Expand Up @@ -239,7 +241,7 @@ class Loader {
/// Parse a null scalar.
///
/// Returns a Dart `null` if parsing fails.
YamlScalar _parseNull(ScalarEvent scalar) {
YamlScalar? _parseNull(ScalarEvent scalar) {
switch (scalar.value) {
case '':
case 'null':
Expand All @@ -255,7 +257,7 @@ class Loader {
/// Parse a boolean scalar.
///
/// Returns `null` if parsing fails.
YamlScalar _parseBool(ScalarEvent scalar) {
YamlScalar? _parseBool(ScalarEvent scalar) {
switch (scalar.value) {
case 'true':
case 'True':
Expand All @@ -273,7 +275,7 @@ class Loader {
/// Parses a numeric scalar.
///
/// Returns `null` if parsing fails.
YamlScalar _parseNumber(ScalarEvent scalar,
YamlScalar? _parseNumber(ScalarEvent scalar,
{bool allowInt = true, bool allowFloat = true}) {
var value = _parseNumberValue(scalar.value,
allowInt: allowInt, allowFloat: allowFloat);
Expand All @@ -283,7 +285,7 @@ class Loader {
/// Parses the value of a number.
///
/// Returns the number if it's parsed successfully, or `null` if it's not.
num _parseNumberValue(String contents,
num? _parseNumberValue(String contents,
{bool allowInt = true, bool allowFloat = true}) {
assert(allowInt || allowFloat);

Expand Down Expand Up @@ -315,7 +317,7 @@ class Loader {
secondChar >= $0 &&
secondChar <= $9)) {
// Try to parse an int or, failing that, a double.
num result;
num? result;
if (allowInt) {
// Pass "radix: 10" explicitly to ensure that "-0x10", which is valid
// Dart but invalid YAML, doesn't get parsed.
Expand Down
Loading

0 comments on commit 925c406

Please sign in to comment.