Giter Club home page Giter Club logo

yaml's Introduction

Build Status Pub Package package publisher

A parser for YAML.

Usage

Use loadYaml to load a single document, or loadYamlStream to load a stream of documents. For example:

import 'package:yaml/yaml.dart';

main() {
  var doc = loadYaml("YAML: YAML Ain't Markup Language");
  print(doc['YAML']);
}

This library currently doesn't support dumping to YAML. You should use json.encode from dart:convert instead:

import 'dart:convert';
import 'package:yaml/yaml.dart';

main() {
  var doc = loadYaml("YAML: YAML Ain't Markup Language");
  print(json.encode(doc));
}

yaml's People

Contributors

adarshm-26 avatar athomas avatar ayan-b avatar bcko avatar bwilkerson avatar chalin avatar dantup avatar denesalmasi avatar dependabot[bot] avatar devoncarew avatar dgrove avatar floitschg avatar franklinyow avatar godcrampy avatar jakemac53 avatar jonasfj avatar kevmoo avatar lrhn avatar munificent avatar natebosch avatar nex3 avatar onejmi avatar pq avatar scheglov avatar sethladd avatar srawlins avatar walnutdust avatar yjbanov avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

yaml's Issues

Add recovery support to the parser

We are using the YAML parser for development-time support, including code completion, and this requires the parser to be able to recover well in the face of errors in order to provide the best UX.

I believe that naively adding recovery would be a breaking change because the parser would begin to return guesses for what it thinks the user intended to type in situations where it previously would have returned null. I believe, however, that we can make it a non-breaking change by putting recovery behind a flag that is optionally passed to the loadYaml* functions (something like bool recover = false).

Extending the API in this way would also allow us to incrementally implement recovery based on which failure cases occur most often.

Does that seem like a reasonable approach?

jsonEncode not working

import 'dart:convert';

final yamlDoc = loadYaml(doc);
jsonEncode(yamlDoc);

throws

Converting object to an encodable object failed: Instance of 'YamlMap'

[proposal] update example app

Hi,
please consider this PR
it contains an update sample app

code
import 'package:yaml/yaml.dart';

const String _yaml = '''
message: this is a message
 
map: 
  message: this is the map message
  another: this is another

list:
  - 1
  - 2  
  - 3 

complex:
  message: this is more complex
  list:
    - 1
    - 2
    - 3

morecomplex:
  - complex:
      message: this is even more complex
      list:
        - 1
        - 2
        - 3
  - complex:
      message: this also
      list:
        - 1
        - 2
        - 3
''';

/// this boilerplate-y code illustrate how to access a [YamlDocument]
/// and the [YamlMap] through the [YamlNode]

YamlMap get yamlMap {
  final _yamlDocument = loadYamlDocument(_yaml);
  final _yamlNode = _yamlDocument.contents;
  return _yamlNode.value as YamlMap;
}

void main() {
  final _yamlMap = yamlMap;
  {
    /// this reads a [String] from [YamlMap] providing a [key]
    final _message = _yamlMap['message'] as String;
    print(_message);
  }
  {
    /// this reads a [YamlMap] from [YamlMap] providing a [key]
    final _map = _yamlMap['map'] as YamlMap;
    final _message = _map['message'] as String;
    final _another = _map['another'] as String;
    print(_message);
    print(_another);
  }
  {
    /// this reads a [YamlList] from [YamlMap] providing a [key]
    final yamlList = _yamlMap['list'] as YamlList;
    final _integers = <int>[for (YamlNode i in yamlList.nodes) i.value as int];
    print('$_integers');
  }
  {
    /// gets from [YamlMap] a [YamlMap] which has as values
    /// a [String] and a [List<int>]
    final _complex = _yamlMap['complex'] as YamlMap;
    final _message = _complex['message'] as String;
    print(_message);
    final yamlList = _complex['list'] as YamlList;
    final _integers = <int>[for (YamlNode i in yamlList.nodes) i.value as int];
    print('$_integers');
  }
  {
    /// gets from [YamlMap] a [List<YamlMap>] each of those have as values
    /// a [String] and a [List<int>]
    final _moreComplex = _yamlMap['morecomplex'] as YamlList;
    final _maps = <YamlMap>[
      for (YamlNode d in _moreComplex.nodes) d.value['complex'] as YamlMap
    ];
    for (var complex in _maps) {
      final _message = complex['message'] as String;
      print(_message);
      final _yamlList = complex['list'] as YamlList;
      final _integers = <int>[
        for (YamlNode i in _yamlList.nodes) i.value as int
      ];
      print('$_integers');
    }
  }
}

thanks

Dumping?

Any idea when dumping might be supported?

pkg/yaml: YamlMap.nodes[...].span.end incorrect

<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="96" height="96"hspace="10"> Issue by seaneagan
Originally opened as dart-lang/sdk#21841


This test fails:

https://gist.github.com/seaneagan/3697f6c6371ac57d1cf8

(See the comments there as well)

I assume this bug was introduced with the yaml 2.1 rewrite.

This is breaking den uninstall:

  http://pub.dartlang.org/packages/den

which needs to be able to find the end of the node to delete.

Spans for nested map values are needlessly multi-line

Accessing the span for a node in a nested map renders it (needlessly) multiline if it's the LAST item in a map.

Not an issue for root items, though...

import 'dart:convert';

import 'package:yaml/yaml.dart';

void main() {
  final yaml = loadYaml(const JsonEncoder.withIndent(' ').convert({
    'num': 42,
    'nested': {
      'null': null,
      'num': 42,
    },
    'null': null,
  })) as YamlMap;

  print(yaml.nodes['num'].span.message('hello'));

  final nestedNode = yaml.nodes['nested'] as YamlMap;

  print(nestedNode.nodes['null'].span.message('prints fine. not last'));
  print(nestedNode.nodes['num'].span.message('last value prints multi-line'));

  print(yaml.nodes['null'].span.message('top-level last value prints fine'));
}

output

line 2, column 9: hello
  ╷
2 │  "num": 42,
  │         ^^
  ╵
line 4, column 11: prints fine. not last
  ╷
4 │   "null": null,
  │           ^^^^
  ╵
line 5, column 10: last value prints multi-line
  ╷
5 │     "num": 42
  │ ┌──────────^
6 │ │  },
  │ └─^
  ╵
line 7, column 10: top-level last value prints fine
  ╷
7 │  "null": null
  │          ^^^^
  ╵

YamlMap should maintain order

I see that the implementation uses Hashmap.

For speed, I get it. But I'd argue that preserving order would be a good feature to add.

...or at least document that it's not.

Add support for merge tags

The yaml package (in v2.3.0 at least) does not support !!merge tags.

For implicit instances (with only a map key of <<) it gets just interpreted as a !!str node.
If the !!merge tag is given explicitly an exception is thrown.

import 'package:yaml/yaml.dart';

const yamlImplicitMerge = '''---
test: &anchor
  ancValue1: 1
  ancValue2: 2
ancUse:
  someOther: 3
  <<: *anchor
''';

const yamlExplicitMerge = '''---
test: &anchor
  ancValue1: 1
  ancValue2: 2
ancUse:
  someOther: 3
  !!merge <<: *anchor
''';

void main(List<String> arguments) {
  <String Function()>[
    () => 'implicit merge gets ignored:',
    () => loadYaml(yamlImplicitMerge),
    () => '————————————————————————————————',
    () => 'Explicit merge throws exception:',
    () => loadYaml(yamlExplicitMerge),
  ].forEach((lazyString) => print(lazyString()));
}

outputs

> dart run .\bin\yaml_test.dart
implicit merge gets ignored:
{test: {ancValue1: 1, ancValue2: 2}, ancUse: {someOther: 3, <<: {ancValue1: 1, ancValue2: 2}}}
————————————————————————————————
Explicit merge throws exception:
Unhandled exception:
Error on line 7, column 3: Undefined tag: tag:yaml.org,2002:merge.

7 │   !!merge <<: *anchor
  │   ^^^^^^^^^^

#0      Loader._parseByTag (package:yaml/src/loader.dart:201:9)
#1      Loader._loadScalar (package:yaml/src/loader.dart:120:14)
#2      Loader._loadNode (package:yaml/src/loader.dart:85:16)
#3      Loader._loadMapping (package:yaml/src/loader.dart:165:17)
#4      Loader._loadNode (package:yaml/src/loader.dart:89:16)
#5      Loader._loadMapping (package:yaml/src/loader.dart:166:19)
#6      Loader._loadNode (package:yaml/src/loader.dart:89:16)
#7      Loader._loadDocument (package:yaml/src/loader.dart:65:20)
#8      Loader.load (package:yaml/src/loader.dart:57:20)
#9      loadYamlDocument (package:yaml/yaml.dart:69:25)
#10     loadYamlNode (package:yaml/yaml.dart:54:5)
#11     loadYaml (package:yaml/yaml.dart:41:5)
#12     main.<anonymous closure> (file:///G:/My%20Drive/dev/yaml_test/bin/yaml_test.dart:27:11)   
#13     main.<anonymous closure> (file:///G:/My%20Drive/dev/yaml_test/bin/yaml_test.dart:28:31)   
#14     List.forEach (dart:core-patch/growable_array.dart:403:8)
#15     main (file:///G:/My%20Drive/dev/yaml_test/bin/yaml_test.dart:28:5)
#16     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:281:32)
#17     _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

Spans aren't correct for list nodes with a null value

Repro program:

import 'package:yaml/yaml.dart';

main() {
  var yaml = loadYaml('''
- foo
- 
- bar
''');

  print(yaml.nodes.firstWhere((n) => n.value == null).span.highlight());
}

Prints:

- bar
 ^

Where I would expect something like:

- 
^

YamlList needs to take type parameters?

I'm attempting to make some of my code strong-mode clean.

For example:

    YamlList yamlItems = yamlMob['items'];
    if (yamlItems != null) {
      yamlItems.forEach(
          (String itemName) => mob.addItem(creator.items.itemByName(itemName)));
    }

Complains:

file: 'file:///Stuff/Projects/lol_duel/lib/utils/duel.dart'
severity: 'Info'
message: 'A function of type '(String) → Item' can't be assigned to a variable of type '(dynamic) → void'.'
at: '46,11'
source: 'dart'
code: 'uses_dynamic_as_bottom'

If this were a normal list, I'd fix it by using:
List<String> items

But I can't do that for YamlList, even thought it implements ListMixin which takes a type parameter:
abstract class ListMixin<E> implements List<E> {

Cannot reread file

When I read an YAML file for the first time, everything is fine.
If I update the file externally during the runtime, the changes won't update on the second reading during the same runtime.

Order of map is nondeterministic, making read+write randomize the file

The use of a HashMap here https://github.com/dart-lang/yaml/blob/master/lib/src/equality.dart#L13
ensures that when the elements of a map are added here https://github.com/dart-lang/yaml/blob/master/lib/src/loader.dart#L156
the order is nondeterministic.

This shows itself in tools that read then write yaml - the output is needlessly reorganized.

The default behaviour should keep the input order (change HashMap to LinkedHashMap)

Sorting would be a nice option, but keeping the original order would

Dartium showing this error 2.1.7

Internal error: 'package:yaml/src/loader.dart': error: line 197 pos 32: unexpected token '?' _tryParseScalar(scalar) ?? new YamlScalar.internal(scalar.value, scalar);

I'm not sure if it's a bug or not, but I can't figure out what's causing this

using dart pub 1.12.1

issues with DDC's strong mode

The getter 'name' is not defined for the class 'Token' (lib/src/parser.dart, line 257, col 47)
The getter 'name' is not defined for the class 'Token' (lib/src/parser.dart, line 264, col 22)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 265, col 19)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 271, col 19)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 300, col 16)
The getter 'style' is not defined for the class 'Token' (lib/src/parser.dart, line 306, col 32)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 311, col 16)
The getter 'value' is not defined for the class 'Token' (lib/src/parser.dart, line 311, col 42)
The getter 'style' is not defined for the class 'Token' (lib/src/parser.dart, line 311, col 55)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 318, col 16)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 325, col 16)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 332, col 16)
The method 'expand' is not defined for the class 'SourceSpan' (lib/src/parser.dart, line 340, col 16)
The getter 'style' is not defined for the class 'Token' (lib/src/scanner.dart, line 446, col 56)

@nex3, @jmesserly, I believe these issues are all related. I'm not sure if they're real issues or if DDC's type promotion needs to be improved.

pkg/yaml: YamlMap iteration order doesn't preserve yaml document order

<img src="https://avatars.githubusercontent.com/u/444270?v=3" align="left" width="96" height="96"hspace="10"> Issue by seaneagan
Originally opened as dart-lang/sdk#21328


Here's the failing test:

import 'package:unittest/unittest.dart';
import 'package:yaml/yaml.dart';

main() {
  Map map = loadYaml(yaml);
  expect(map.keys.toList(), ['foo', 'bar', 'baz']);
}

var yaml = '''
foo: x
bar: y
baz: z
''';

Guessing it would just need to switch to an underlying LinkedHashMap so long as the keys are inserted in document order. I expected this to work given that it does with JSON.

Build fails due to bug in dependency 'source_span v1.5.5'

The source_span v1.5.5 had a bug where the span for line numbers multiple of 10 had less padding than others. Here, travis jobs with dart-sdk 2.4.0 fetch version 1.5.5 during pub get and for these jobs the _expectSpan() method fails from incorrect span information. The build that failed is here.
Reproduction program -

import 'package:source_span/source_span.dart';
void main() {
  const dtr = r'''
1
2
3
4
5
6
7
8
9
10
11
''';
  var fs = SourceFile.fromString(dtr);
  var offset = fs.getOffset(8);
  var span = fs.location(offset).pointSpan();
  print(span.message('padding of 1 space')); 

  offset = fs.getOffset(9);
  span = fs.location(offset).pointSpan();
  print(span.message('padding of 0 space'));

  offset = fs.getOffset(10);
  span = fs.location(offset).pointSpan();
  print(span.message('padding of 1 space'));
}

Output (using source_span: '1.5.5')-

line 9, column 1: padding of 1 space

9 │ 9
  │ ^

line 10, column 1: padding of 0 space

10│ 10
  │ ^

line 11, column 1: padding of 1 space

11 │ 11
   │ ^

loadYaml returns null (3.0.0-nullsafety.0 release)

When loadYaml is passed the empty string, it returns null. For example, if parsing an empty file or a file with only whitespace in it.

But since the return type is dynamic, null safety (as implemented by Dart 2.12.0-29.10.beta) doesn't behave as expected. If you check it for null, Dart (incorrectly) tells you the check is unnecessary.

How about returning Object? instead?

YamlScalars with null spans in 2.1.4.

In 2.1.3 the following code.

import 'package:yaml/yaml.dart';

main() {
  const src = """
name: linter
version: 0.0.1
author: Dart Team <[email protected]>
authors:
  - Bill
  - Ted
description: Style linter for Dart.
documentation:
homepage: https://github.com/dart-lang/linter
dependencies:
  transmogrify:
    hosted:
      name: transmogrify
      url: http://your-package-server.com
    version: '>=0.4.0 <1.0.0'
  analyzer: '0.24.0-dev.1'
  cli_util: '>=0.0.1 <0.1.0'
  semver: '>=0.2.0 <0.3.0'
  yaml: '>=2.1.2 <3.0.0'
  kittens:
    git:
      url: git://github.com/munificent/kittens.git
      ref: some-branch
  foo: any
dev_dependencies:
  markdown: '>=0.7.1+2 <0.8.0'
  unittest: '>=0.11.0 <0.12.0'
""";

  YamlMap node = loadYamlNode(src, sourceUrl: null);
  node.nodes.forEach((k, v) {
    if (k is YamlScalar) print(k.span);
  });
}

yields this:

<FileSpan: from <FileLocation: 66 unknown source:4:1> to <FileLocation: 73 unknown source:4:8> "authors">
<FileSpan: from <FileLocation: 13 unknown source:2:1> to <FileLocation: 20 unknown source:2:8> "version">
<FileSpan: from <FileLocation: 189 unknown source:10:1> to <FileLocation: 201 unknown source:10:13> "dependencies">
<FileSpan: from <FileLocation: 0 unknown source:1:1> to <FileLocation: 4 unknown source:1:5> "name">
<FileSpan: from <FileLocation: 28 unknown source:3:1> to <FileLocation: 34 unknown source:3:7> "author">
<FileSpan: from <FileLocation: 92 unknown source:7:1> to <FileLocation: 103 unknown source:7:12> "description">
<FileSpan: from <FileLocation: 143 unknown source:9:1> to <FileLocation: 151 unknown source:9:9> "homepage">
<FileSpan: from <FileLocation: 128 unknown source:8:1> to <FileLocation: 141 unknown source:8:14> "documentation">
<FileSpan: from <FileLocation: 541 unknown source:25:1> to <FileLocation: 557 unknown source:25:17> "dev_dependencies">

In 2.1.4 I get:

null
null
null
null
null
null
null
null
null

This is breaking the linter:

https://travis-ci.org/dart-lang/linter/builds/79375765

Any tips appreciated!

Support for null safety

Is it possible to have a branch with the code that is migrated to null safety so other apps/libs that use yaml package could start migrating as well?

Custom tag support

Currently, in the public API tags aren't exposed at all. Is there any reason for that? This makes custom tags (like !Foo) completely disappear.

Poor error message when mixing list and key-value syntax

Given the following input:

linter:
  rules:
    close_sinks: false
    - empty_statements 

The message produced is

Expected a key while parsing a block mapping.

While the message is technically correct, it doesn't help the author of the file figure out how to fix the issue as much as it could. A user suggested something like

You can’t mix list and key-value syntax in the same object.

Please improve the error message for this situation.

Emoji support

Current parser crashes when trying to load a yaml document with emojis in it.

    var emoji = "😃";
    String s = "YAML:  ${emoji} YAML Ain't Markup Language";
    var doc = loadYaml(s);
    print(doc['YAML']);

Error:

Error on line 1, column 8: Unexpected character.
  ╷
1 │ YAML:  😃 YAML Ain't Markup Language
  │        ^
  ╵

package:yaml/src/parser.dart 50:7    Parser.parse
package:yaml/src/loader.dart 165:37  Loader._loadMapping
package:yaml/src/loader.dart 86:16   Loader._loadNode
package:yaml/src/loader.dart 62:20   Loader._loadDocument

Problem with large numers

The lib converts in loadYaml(String yaml) a large numer, eg. 4393685097626700267668050536035 to 4.3936850976267e+30

provide more helpful message when you forget a ":"

From dart-lang/pub#1284 filed by @kwalrath :


I had a pubspec with a transformers entry like this:

transformers:
- angular2
    entry_points: web/main.dart

It of course should've had "angular2:", not "angular2" (note the colon), but the message wasn't helpful:

$ pub serve
Error on line 8, column 16 of pubspec.yaml: Mapping values are not allowed in this context.
    entry_point: web/main.dart
               ^

If you could give a hint that a colon might be missing above, that would be fantastic. Or perhaps a link to a page that gives common solutions to the issue. Or a syntax checker that's smarter. If you can provide a different error message, I can work with you on its content.

(LOTS of people get burned by little problems like this, especially when they're starting out. Anything we can do to reduce their frustration would be helpful.)

cc @cbracken

Yaml 1.0.0+1 cannot be imported

Originally opened as dart-lang/sdk#19200

This issue was originally filed by [email protected]


  1. pub upgrade
  2. yaml-1.0.0+1 retrieved
  3. test_yaml.dart file with only 'import 'package:yaml/yaml.dart';

Internal error: 'package:yaml/src/yaml_node.dart': error: line 37 pos 48: 'dynamic' may not be used as interface
class YamlMap extends YamlNode with collection.MapMixin, UnmodifiableMapMixin {

I'm running Dart VM version: 1.4.2 (Tue May 27 08:07:01 2014) on "windows_ia32"

more deprecated things with onError

Analyzing yaml...
hint • 'onError' is deprecated and shouldn't be used at lib/src/loader.dart:306:56 • deprecated_member_use
hint • 'onError' is deprecated and shouldn't be used at lib/src/loader.dart:310:48 • deprecated_member_use
hint • 'onError' is deprecated and shouldn't be used at lib/src/loader.dart:324:49 • deprecated_member_use
hint • 'onError' is deprecated and shouldn't be used at lib/src/loader.dart:327:57 • deprecated_member_use
hint • 'onError' is deprecated and shouldn't be used at lib/src/loader.dart:351:37 • deprecated_member_use
5 hints found.

Parsing of empty list or map node results in an invalid span.

The sample code below

void main() {
  final doc = loadYaml('''
key:
''');

  print((doc as YamlMap).nodes.keys.first.span);
  print((doc as YamlMap).nodes['key'].span);
}

results in:

<_FileSpan: from <FileLocation: 0 unknown source:1:1> to <FileLocation: 3 unknown source:1:4> "key">
<_FileSpan: from <FileLocation: 3 unknown source:1:4> to <FileLocation: 3 unknown source:1:4> "">

which suggests that the value node starts right where "key" ends, but this cannot be the case due to the presence of the colon.

Likewise, for lists, the sample code below:

void main() {
  final doc = loadYaml('''
- 
''');

  print((doc as YamlList).nodes.first.span);
}

results in:

<_FileSpan: from <FileLocation: 0 unknown source:1:1> to <FileLocation: 0 unknown source:1:1> "">

which again cannot be possible due to the presence of the hyphen

Expected behavior

I would have expected the spans to occur at meaningful places, i.e. after the colon for map values and after the hyphen for list values.

Add type-safe "read" methods

Very similar to dart-lang/args#95.

Helps address

... and other, unfiled issues that we've hit trying to use package:yaml with Dart2 semantics.

We don't need full coverage of every possible type to start delivering lots of value. Here's my idea:

abstract class YamlMap {
  T read<T>(dynamic key);
  List<T> readList<T>(dynamic key);
  Map<K, V> readMap<K, V>(dynamic key);
}

Example simplified use:

void _parseMap(YamlMap config) {
  // Use <T>
  final name = config.read<String>('name');

  // OR, use inference:
  final String name = config.read('name');

  // Also works well with methods that already expect types
  _validateName(config.read('name'));
}

void _validateName(String name) { ... }

We could guard against trying to read collections, as well:

T read<T>(dynamic key) {
  if (T is Iterable || T is Map) {
    throw new UnsupportedError('Use readList or readMap instead');
  }
  ...
}

Here is an example implementation of readList:

List<T> readList<T>(dynamic key) {
  List<dynamic> list = this[key];
  return list.cast<T>();
}

One trickier case is readMap, for example, values could be a List<String>.

Two ideas:

  1. Special case:
Map<K, V> readMap<K, V>(dynamic key) {
  if (v is Iterable) {
    // Special case, and use readList here with .cast.
  }
}
  1. Add yet-another method:
Map<K, List<V>> readMapList<K, V>(dynamic key);

Thoughts? @srawlins @eseidelGoogle @nex3 @natebosch @jakemac53

An unwrap mechanism?

Context: read some yaml file then process it programmatically before passing on the map

But it's not easy to turn a YamlMap into a mutable form. The mutable scenario should be fairly common. Could there be a converter for YamlMaps to normal dart maps?

Alias/Anchors do not work across includes

I'm not sure if this is something that should work and is a bug or not, but it could be handy. I would like to have an included yaml file at the top that defines some aliases for use later.

Here's an example:

abilities.yaml

# Define aliases for different abilities that are actually numbers and not strings
abilities:
  fly: &ability_fly 1
  swim: &ability_swim 2
  walk: &ability_walk 3

creatures.yaml

include: abilities.yaml
# I'd like the aliases defined in the included file to exist here

creatures:
  bat:
    abilities:
      - *ability_fly  # These don't seem to be in scope
  fish:
    abilities:
      - *ability_swim # These don't seem to be in scope
  human:
    abilities:
      - *ability_swim # These don't seem to be in scope
      - *ability_walk # These don't seem to be in scope

I've verified that the alias and anchor format is correct and this works if the 2 files are combined into 1 and there is no include. It appears that maybe include is a Dart specific addition to yaml and not in the spec? Does that mean this request could be added?

loadYaml in dart takes 200-300ms on android

16:35:57.902 load yaml

verb: RecommendCafes
recipe:
  - verb: List
    outputs: ["Cafe[]"]
  - verb: Fetch
    inputs: ["Cafe[]"]
    outputs: ["CafeWithMenu[]"]
  - verb: Flatten
    inputs: ["CafeWithMenu[]"]
    outputs: ["DishOffering[]"]
  - verb: Score
    inputs: ["DishOffering[]"]
    outputs: ["DishOffering[]/Scored"]
  - verb: Display
    inputs: ["DishOffering[]/Scored"]

16:35:58.203 load yaml done

Provision to write map to yaml file

The YAML package supports reading the YAML file. However, at the moment, writing the modified map back YAML file is not supported.

Enhancement request to provide support in writing map to YAML file.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.