Giter Site home page Giter Site logo

dlang-community / d-yaml Goto Github PK

View Code? Open in Web Editor NEW
116.0 14.0 39.0 3.95 MB

YAML parser and emitter for the D programming language

Home Page: https://dlang-community.github.io/D-YAML/

License: Boost Software License 1.0

D 99.62% Meson 0.38%
yaml parser emitter dlang yaml-parser

d-yaml's Introduction

D:YAML

travis-ci codecov code.dlang.org

Introduction

D:YAML is an open source YAML parser and emitter library for the D programming language. It is almost compliant to the YAML 1.1 specification. D:YAML is based on PyYAML created by Kirill Simonov.

D:YAML is designed to be easy to use while supporting the full feature set of YAML. To start using it in your project, see the Getting Started tutorial.

Features

  • Easy to use, high level API and detailed debugging messages.
  • Detailed API documentation and tutorials.
  • Code examples.
  • Supports all YAML 1.1 constructs. All examples from the YAML 1.1 specification are parsed correctly.
  • Reads from and writes from/to YAML files or in-memory buffers.
  • UTF-8, UTF-16 and UTF-32 encodings are supported, both big and little endian (plain ASCII also works as it is a subset of UTF-8).
  • Support for both block (Python-like, based on indentation) and flow (JSON-like, based on bracing) constructs.
  • Support for YAML anchors and aliases.
  • Support for default values in mappings.
  • Support for custom tags (data types), and implicit tag resolution for custom scalar tags.
  • All tags (data types) described at http://yaml.org/type/ are supported, with the exception of tag:yaml.org,2002:yaml, which is used to represent YAML code in YAML.
  • Remembers YAML style information between loading and dumping if possible.
  • Reuses input memory and uses slices to minimize memory allocations.
  • There is no support for recursive data structures. There are no plans to implement this at the moment.

Directory structure

Directory Contents
./ This README, utility scripts.
./docs Documentation.
./source Source code.
./examples/ Example projects using D:YAML.
./test Unittest data.

Installing and tutorial

See the Getting Started. Tutorial and other tutorials that can be found at the GitHub pages or in the docs directory of the repository.

API documentation is available here.

License

D:YAML is released under the terms of the Boost Software License 1.0. This license allows you to use the source code in your own projects, open source or proprietary, and to modify it to suit your needs. However, in source distributions, you have to preserve the license headers in the source code and the accompanying license file.

Full text of the license can be found in file LICENSE_1_0.txt and is also displayed here:

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Credits

D:YAML was created by Ferdinand Majerech aka Kiith-Sa and is handled by the dlang-community organization since 2017. Parts of code based on PyYAML created by Kirill Simonov.

d-yaml's People

Contributors

asperan avatar bbasile avatar burner avatar carlor avatar coldencullen avatar dkorpel avatar dlang-bot avatar forbjok avatar geod24 avatar herringway avatar japplegame avatar jmdavis avatar john-colvin avatar kiith-sa avatar kubo39 avatar majiang avatar martinnowak avatar mihails-strasuns-sociomantic avatar petarkirov avatar russel avatar soarqin avatar stefanhepp avatar tom-tan avatar wilzbach avatar ximion 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

d-yaml's Issues

Support for non-BMP Unicode characters

This should work and produce a mapping from a to π’…— (U+12157, Cuneiform Ka):

Loader.fromString("a: π’…—".dup).load();

Even when supplying a byte order mark, it's forbidden: Special unicode characters are not allowed

Switching it to U+0587, an Armenian ligature for ech yiwn, works:

Loader.fromString("a: Φ‡".dup).load();

Something about the basic multilingual plane, I'm guessing?

Broken with dmd-nigthly

dlang/dmd#6839 fixed some holes in the safety system. Unfortunately D-YAML is affected:

source/dyaml/emitter.d(614,20): Error: address of variable this assigned to this with longer lifetime
source/dyaml/emitter.d(639,20): Error: address of variable this assigned to this with longer lifetime

For the next days I am a bit low on time, so if anyone has time to prepare fix, please go for it ;-)

Add default values.

Add a way to get a default value if the node does not exist.

Current:

name = node.containsKey("Name") ? node["Name"].as!string : "Default Value";

New

name = node["Name", "Default Value"].as!string;

Compilation fail with 2.067-rc1

Upcoming release of 2.067 is breaking compilation:

Building dyaml 0.5.0 configuration "library", build type debug.
Running dmd...
../../../.dub/packages/dyaml-0.5.0/source/dyaml/constructor.d(862): Error: redundant attribute 'const'
../../../.dub/packages/dyaml-0.5.0/source/dyaml/representer.d(605): Error: redundant attribute 'const'

Compilation error with dmd v2.062

Can't compile D:YAML using dub + dmd v2.062 on Windows 7

Building configuration "application", build type release
Copying files...
Running dmd (compile)...
.dub\packages\dyaml\source\dyaml\node.d(1539): Error: not a property this.type().toString
.dub\packages\dyaml\source\dyaml\node.d(1408): Error: template instance dyaml.node.Node.cmp!(cast(Flag)true) error instantiating
.dub\packages\dyaml\source\dyaml\node.d(510): instantiated from here: equals!(cast(Flag)true, const(Node))
.dub\packages\dyaml\source\dyaml\node.d(133): instantiated from here: opEquals!(Node)
.dub\packages\dyaml\source\dyaml\node.d(510): Error: template instance dyaml.node.Node.equals!(cast(Flag)true, const(Node)) error instantiating
.dub\packages\dyaml\source\dyaml\node.d(133): instantiated from here: opEquals!(Node)

Opening a large yaml file is very slow

this line:

auto yamlRoot = Loader("typeIDs.yaml").load();

Is taking multiple minutes.

Parsing the file using YamlDotNet is a matter of seconds:

var yaml = new YamlStream();
yaml.Load(new StreamReader("typeIDs.yaml"));

(For both libraries then iterating over the data is about equally fast)

Check the Eve Online Static Data Export for some large files to test

build failing with dmd 2.071

using DMD64 D Compiler v2.071.0 this library does not compile... there is anyone that maintain this project?

../../.dub/packages/dyaml-0.5.2/source/dyaml/dumper.d(15,8): Deprecation: module std.stream is deprecated - It will be removed from Phobos in October 2016. If you still need it, go to https://github.com/DigitalMars/undeaD
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(21,8): Deprecation: module std.stream is deprecated - It will be removed from Phobos in October 2016. If you still need it, go to https://github.com/DigitalMars/undeaD
../../.dub/packages/dyaml-0.5.2/source/dyaml/representer.d(679,8): Deprecation: module std.stream is deprecated - It will be removed from Phobos in October 2016. If you still need it, go to https://github.com/DigitalMars/undeaD
../../.dub/packages/dyaml-0.5.2/source/dyaml/streamcompat.d(10,8): Deprecation: module std.stream is deprecated - It will be removed from Phobos in October 2016. If you still need it, go to https://github.com/DigitalMars/undeaD
../../.dub/packages/dyaml-0.5.2/source/dyaml/testcommon.d(14,15): Deprecation: module std.stream is deprecated - It will be removed from Phobos in October 2016. If you still need it, go to https://github.com/DigitalMars/undeaD
../../.dub/packages/dyaml-0.5.2/source/dyaml/loader.d(171,16): Deprecation: module std.stream is deprecated - It will be removed from Phobos in October 2016. If you still need it, go to https://github.com/DigitalMars/undeaD
../../.dub/packages/dyaml-0.5.2/source/dyaml/constructor.d(611,27): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/constructor.d(627,23): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(286,34): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (EventID[], const(EventID))
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(287,37): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (EventID[], const(EventID))
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(904,55): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (dstring, const(dchar))
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(925,71): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (dstring, const(dchar))
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(971,69): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (dstring, const(dchar))
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(997,55): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (dstring, const(dchar))
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(1041,79): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (dstring, immutable(char))
../../.dub/packages/dyaml-0.5.2/source/dyaml/emitter.d(1384,77): Error: function dyaml.emitter.FastCharSearch!("\x0a\x85\x28\x20\x29\x20"d, 256u).canFind (const(dchar) c) is not callable using argument types (dstring, const(dchar))
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(221,46): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(222,46): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(223,46): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(224,46): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(286,26): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(287,26): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(288,26): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.
../../.dub/packages/dyaml-0.5.2/source/dyaml/testconstructor.d(291,26): Deprecation: constructor std.datetime.SysTime.this is deprecated - Please use the overload which takes a Duration instead of a FracSec.

on as key is dumped as 'on'

e.g. travis ghpages deploy likes:

on:
  branch: master

if i write this with dyaml i get 'on' ...
i think its not necessary to escape on, On, Off, .. on the left side of a colon.

Dumper does not close file/stream (?)

Hello,

I might be missing something, but this code:

import std.stdio;
import dyaml.all;

void main()
{
    //Read the input.
    Node root = Loader("test.yaml").load();

    //Display the data read.
    foreach(string word; root["Hello World"])
    {
        writeln(word);
    }
    writeln("The answer is ", root["Answer"].as!int);

    //Dump the loaded document to output.yaml.
    Dumper("test.yaml").dump(root);

    //Read it again
    Node root2 = Loader("test.yaml").load();
}

Causes an exception on Windows because Dumper does not close the file when it finished dumping.
image

  • Is this intended behavior?
  • How can I close the file?

My temporary workaround is a close method in Dumper.

Thanks

Provide up-to-date and easily browseable docs

Imho instead of committing the docs in the source code, we could run ddox on Travis/Circle Ci
For CircleCi it can be reduced down to something like:

test:
  override:
    - make -f doc/Makefile html # or any other command to create the docs
deployment:
  aws:
    branch: master
    commands:
      - AWS_DEFAULT_REGION=eu-west-1 aws s3 sync --acl public-read --delete web s3://docs.mir.dlang.io/latest

source

The AWS S3 key can be conveniently added to CircleCi via their web interface.

findPair isn't being automatically inferred as @safe

When compiling as a dependency, I get the following error:

../../../../.dub/packages/dyaml-master/dyaml/source/dyaml/node.d(726,36): Error: @​safe function dyaml.node.Node.opIndex!string.opIndex cannot call @​system function dyaml.node.Node.findPair!(string, cast(Flag)true).findPair
../../../../.dub/packages/dyaml-master/dyaml/source/dyaml/node.d(590,38): Error: template instance dyaml.node.Node.opIndex!string error instantiating
../../../../.dub/packages/dyaml-master/dyaml/source/dyaml/node.d(1837,35): instantiated from here: get!(const(string), cast(Flag)false)
../../../../.dub/packages/dyaml-master/dyaml/source/dyaml/node.d(521,39): instantiated from here: equals!(cast(Flag)true, const(string))
../../../../.dub/packages/dyaml-master/dyaml/source/dyaml/node.d(2147,33): instantiated from here: opEquals!string
../../../../.dub/packages/dyaml-master/dyaml/source/dyaml/node.d(2080,24): ... (4 instantiations, -v to show) ...

The problem is that apparently findPair is not being inferred as safe. If I just add the @safe attribute manually here, it works as expected.

Failure to compile when assigning a `const(bool)` to a node.

The following snippet doesn't compile:

void main()
{
    import dyaml;

    string[string] mapping;
    auto node = Node(mapping);
    const bool f = true;

    node["foo"] = f;
}

Compilation fails with following output:

<irrelevant>/dyaml-0.6.3/source/dyaml/node.d(112,25): Error: no property 'opCmp' for type 'const(bool)'
<irrelevant>/dyaml-0.6.3/dyaml/source/dyaml/node.d(1423,46): Error: template instance dyaml.node.YAMLContainer!(const(bool)) error instantiating
<irrelevant>/dyaml-0.6.3/dyaml/source/dyaml/node.d(265,71):        instantiated from here: userValue!(const(bool))
<irrelevant>/dyaml-0.6.3/dyaml/source/dyaml/node.d(137,62):        instantiated from here: __ctor!(const(bool))
<irrelevant>/dyaml-0.6.3/dyaml/source/dyaml/node.d(1234,26):        instantiated from here: __ctor!(string, const(bool))
<irrelevant>/dyaml-0.6.3/dyaml/source/dyaml/node.d(982,32):        instantiated from here: add!(string, const(bool))
source/app.d(8,14):        instantiated from here: opIndexAssign!(string, const(bool))

If const is removed, the above snippet compiles. If const is replaced with immutable it fails as well. Other types I've tried don't seem to have this behaviour, just bools. D-YAML v0.6.3. It is weird that plain bool works.

build fails with latest dmd

with the latest dmd from github:

$ rdmd cdc.d
building release target
CDC: dmd -O -inline -release -noboundscheck -oflibdyaml -lib -w -wi -op dyaml/resolver.d dyaml/representer.d dyaml/parser.d dyaml/encoding.d dyaml/exception.d dyaml/reader.d dyaml/node.d dyaml/style.d dyaml/zerostring.d dyaml/constructor.d dyaml/loader.d dyaml/dumper.d dyaml/queue.d dyaml/tag.d dyaml/flags.d dyaml/escapes.d dyaml/scanner.d dyaml/tagdirective.d dyaml/event.d dyaml/token.d dyaml/linebreak.d dyaml/anchor.d dyaml/fastcharsearch.d dyaml/serializer.d dyaml/emitter.d dyaml/composer.d yaml.d -L-ldl
dyaml/node.d(149): Error: safe function 'this' cannot call system function 'opAssign'
dyaml/node.d(151): Error: safe function 'this' cannot call system function 'opAssign'
dyaml/representer.d(402): Error: template instance dyaml.node.Node.Pair.__ctor!(Node,Node) error instantiating
dyaml/representer.d(537): Error: safe function 'representNodes' cannot call system function 'opAssign'
dyaml/node.d(150): Error: safe function 'this' cannot call system function 'opAssign'
dyaml/node.d(152): Error: safe function 'this' cannot call system function 'opAssign'
dyaml/representer.d(636): Error: template instance dyaml.node.Node.Pair.ctor!(string,int) error instantiating
dyaml/parser.d(142): Error: this.states
.reserve is not nothrow
dyaml/parser.d(143): Error: this.marks
.reserve is not nothrow
dyaml/parser.d(138): Error: constructor dyaml.parser.Parser.this 'this' is nothrow yet may throw
dyaml/exception.d(64): Error: contextMark.toString is not nothrow
dyaml/exception.d(60): Error: constructor dyaml.exception.MarkedYAMLException.this 'this' is nothrow yet may throw
dyaml/exception.d(73): Error: problemMark.toString is not nothrow
dyaml/exception.d(70): Error: constructor dyaml.exception.MarkedYAMLException.this 'this' is nothrow yet may throw
dyaml/node.d(45): Error: start.toString is not nothrow
dyaml/node.d(42): Error: constructor dyaml.node.NodeException.this 'this' is nothrow yet may throw
dyaml/node.d(1772): Error: safe function 'merge' cannot call system function 'opAssign'
dyaml/constructor.d(51): Error: start.toString is not nothrow
dyaml/constructor.d(48): Error: constructor dyaml.constructor.ConstructorException.this 'this' is nothrow yet may throw
dyaml/dumper.d(172): Error: constructor this is not nothrow
dyaml/dumper.d(173): Error: constructor this is not nothrow
Compiler failed: Process dmd exited with status 1
DONE

Of course this could be a dmd bug, but I personally don't know enough to tell the difference in this case.

P.S. just wanted to say that this is an awesome project, I recently moved to it from trying to hack my way through std.xml for config files for a recent project. Now my read_cfg function is now only a third of the lines it was and has gone from nearly illegible to simple and concise.

__FILE_FULL_PATH__.dirName duplicate

When I compile tests:

dub test big-d:test -v --coverage --combined --build-mode=singleFile

Build is OK!
But after run:

../../.dub/packages/dyaml-0.6.3/dyaml/source/../../.dub/packages/dyaml-0.6.3/dyaml/source/dyaml/../../test/data
std.file.FileException@std/file.d(3676): ../../.dub/packages/dyaml-0.6.3/dyaml/source/../../.dub/packages/dyaml-0.6.3/dyaml/source/dyaml/../../test/data: No such file or directory

Why this line generate duplicate __FILE_FULL_PATH__???

immutable string dataDir = __FILE_FULL_PATH__.dirName ~  "/../../test/data"

No way to dump "pretty" YAML

As far as I can tell, there is currently no way to dump "pretty" YAML.

This would be very nice to have, since you sometimes need to be able to generate YAML that needs to be human-readable, such as configuration files.

Question about D-YAML

Where can I send you an email?

Question:
Does D-YAML support writing just a single piece of data to the file instead of writing the whole file each time you want to save something. For instance, this would be great if you wanted to continually save an applications project file in the background. If the file's huge it would be to much overhead to write the whole thing each time and that limits you to having the user choose when to save their project.

SDLang-D doesn't support this afaik.

Thank you!

ASCII-only Scanner/Reader versions

Reader/Scanner should have a compile-time flag parameter specifying whether they only work with ASCII to remove code handling Unicode newlines, decoding, etc. If an ASCII-only file is being loaded, it should use ASCII versions of Reader/Scanner.

Unitest fails

I get this error when I run tests for my d program that uses dyaml as one of its dependecies.

dub test --compiler=ldc2 results in:

D:YAML Resolver unittest
D:YAML Constructor unittest
std.file.FileException@/build/ldc-I3nwWj/ldc-0.17.1/runtime/phobos/std/file.d(2796): test/data: No such file or directory
----------------
Flags unittest
Program exited with code 1

Don't compile anymore with dmd 2.068

compiling C:\...\projects\D-YAML.coedit
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(277): Error: safe function 'dyaml.node.Node.__ctor!string.this' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!string.this'
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(320): Error: template instance dyaml.node.Node.__ctor!string error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\composer.d(242):        instantiated from here: node!(string, immutable(ScalarStyle))
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(332): Error: safe function 'dyaml.node.Node.__ctor!(Node).this' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!(Node[]).this'
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(320): Error: template instance dyaml.node.Node.__ctor!(Node) error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\composer.d(269):        instantiated from here: node!(Node[], immutable(CollectionStyle))
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1756): Error: safe function 'dyaml.node.Node.findPair!(string, cast(Flag)true).findPair' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.get!(const(Pair[])).get'
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(783): Error: template instance dyaml.node.Node.findPair!(string, cast(Flag)true) error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(620):        instantiated from here: opIndex!string
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1098):        instantiated from here: get!(Pair[], cast(Flag)true)
C:\Dev\metad\repos\D-YAML\source\dyaml\composer.d(310):        instantiated from here: opApply!(Node, Node)
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1042): Error: template instance dyaml.node.Node.get!(Node[], cast(Flag)true) error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\composer.d(330):        instantiated from here: opApply!(Node)
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(332): Error: safe function 'dyaml.node.Node.__ctor!(Pair).this' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!(Pair[]).this'
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(320): Error: template instance dyaml.node.Node.__ctor!(Pair) error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\composer.d(387):        instantiated from here: node!(Pair[], immutable(CollectionStyle))
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1431): Error: safe function 'dyaml.node.Node.value!(YAMLNull).value' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!(YAMLNull).this'
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(361): Error: template instance dyaml.node.Node.value!(YAMLNull) error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(189):        instantiated from here: addConstructor!(YAMLNull)
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(88):        instantiated from here: addConstructorScalar!(YAMLNull)
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1431): Error: safe function 'dyaml.node.Node.value!bool.value' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!bool.this'
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(361): Error: template instance dyaml.node.Node.value!bool error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(189):        instantiated from here: addConstructor!bool
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(89):        instantiated from here: addConstructorScalar!bool
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1431): Error: safe function 'dyaml.node.Node.value!long.value' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!long.this'
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(361): Error: template instance dyaml.node.Node.value!long error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(189):        instantiated from here: addConstructor!long
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(90):        instantiated from here: addConstructorScalar!long
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1431): Error: safe function 'dyaml.node.Node.value!real.value' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!real.this'
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(361): Error: template instance dyaml.node.Node.value!real error instantiating
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(189):        instantiated from here: addConstructor!real
C:\Dev\metad\repos\D-YAML\source\dyaml\constructor.d(91):        instantiated from here: addConstructorScalar!real
C:\Dev\metad\repos\D-YAML\source\dyaml\node.d(1431): Error: safe function 'dyaml.node.Node.value!(ubyte[]).value' cannot call system function 'std.variant.VariantN!(16u, YAMLNull, YAMLMerge, bool, long, real, ubyte[], SysTime, string, Pair[], Node[], YAMLObject).VariantN.__ctor!(ubyte[]).this'
C:\...\projects\D-YAML.coedit has not been compiled

Make style accessible to other applications

Would it be okay if an @Property was created so that we could get at the Scalar/Collection style of a node, to verify that a user has used double quotes, single quotes etc. I would gladly make a pull request if you'd merge it.

request for including tinyendian

I suggest you either to put tinyendian as a sub repository (so that when cloning a sub folder is automatically created) or to include it totally in the lib (as it's only 160 LOC).

Compilation errors

Can't compile current version (c1caf47) of 64-bit Linux:

$ ./cdc
building release target
CDC:  dmd -O -inline -release -noboundscheck -oflibdyaml -lib -w -wi -op source/yaml.d source/dyaml/zerostring.d source/dyaml/representer.d source/dyaml/emitter.d source/dyaml/reader.d source/dyaml/resolver.d source/dyaml/loader.d source/dyaml/fastcharsearch.d source/dyaml/token.d source/dyaml/anchor.d source/dyaml/linebreak.d source/dyaml/style.d source/dyaml/constructor.d source/dyaml/exception.d source/dyaml/node.d source/dyaml/scanner.d source/dyaml/escapes.d source/dyaml/queue.d source/dyaml/composer.d source/dyaml/tagdirective.d source/dyaml/event.d source/dyaml/flags.d source/dyaml/serializer.d source/dyaml/all.d source/dyaml/parser.d source/dyaml/tag.d source/dyaml/dumper.d source/dyaml/encoding.d -L-ldl
source/dyaml/emitter.d(73): Error: undefined identifier 'tagdirective'
source/dyaml/emitter.d(73): Error: undefined identifier 'tagdirective'
source/dyaml/emitter.d(76): Error: undefined identifier 'tagdirective'
source/dyaml/emitter.d(76): Error: dyaml.tagdirective.TagDirective is used as a type
source/dyaml/emitter.d(73): Error: undefined identifier 'tagdirective'
source/dyaml/emitter.d(143): Error: undefined identifier 'tagdirective'
source/dyaml/emitter.d(143): Error: dyaml.tagdirective.TagDirective is used as a type
Compiler failed: Process dmd exited with status 1
DONE

Support for Comments

sorry if this is already solved, but cannot find any clue in the documentation, neither in the examples, neither in the source, that yaml-comments are supported.

Would love to use D-Yaml if comments could be supported. Want to format a yaml document and for that comments are essential.

Thanks!

Iteration over `const` Nodes

Would it be possible to enable iterating over const (and immutable) nodes? At the moment the following doesn't compile (assuming the node in question is a sequence):

void
foo(const Node n)
{
    import std.stdio;
    foreach (string elem; n)
        writeln(elem);
}

Simple means (sticking inout, const, etc. at some methods) didn't help, and I'm, unfortunately, not familiar enough with the source to find out what needs changing to support such iteration.

Dumping without BOM

I'd like to dump some document to YAML file in UTF-8 without BOM, but emitter.d always writes BOM. Is there any plan or obstacle to support, or workaround for this?

With latest dmd 2.072.0 it is impossible to compile

There are many deprecation, but these are errors:
source/dyaml/emitter.d(1011,13): Error: field ScalarAnalysis.scalar cannot modify misaligned pointers in @safe code
source/dyaml/event.d(230,5): Error: field Event.anchor cannot access pointers in @safe code that overlap other fields
source/dyaml/event.d(231,5): Error: field Event.tag cannot access pointers in @safe code that overlap other fields
source/dyaml/loader.d(186,43): Error: cast from void[] to ubyte[] not allowed in safe code

CTFE Ability

Hi

I am using D-yaml in some of my projects, and would like to be able to use it in a compile time executed function. I was wondering if you would be willing to consider making D-Yaml CTFE friendly.

Thanks for your time.

Unittests of package fails when calling as dependency

Using Ubuntu 16.04 with GDC 5.4.0 and DUB 0.9.24-2.
Trying to install and test package d-yaml using commands:

> cd ~
> dub fetch dyaml
> dub test dyaml

Expected: all tests finished successful.
Result: many errors like:

std.file.FileException@../../../../src/libphobos/src/std/file.d(2795): test/data: No such file or directory

Reason: path to test data in file source/dyaml/testtokens.d is relative.
Proposal: use absolute path.

Cannot store time

I'd like to read a timestamp that looks like HH:MM:SS into a TimeOfDay, but the type seems to be parsed inconsistently:

writeln(Loader.fromString("0:20:15".dup).load().as!string);
writeln(Loader.fromString("20:20:15".dup).load().as!string);

prints:

0:20:15
73215

The former seems to be a string, the latter a long. .as!SysTime doesn't work on either.

Ranges for foreach over sequence/mapping nodes

Should be the first step to making D:YAML Nodes range based. Also, when this is added, the current opApply() should be deprecated (but kept for one/more releases).

E.g. sequence, mapping, mappingKeys, mappingValues. These will assert that the key is a sequence/mapping.

Example: string[] strings = node.mappingKeys.map!(n => n.as!string).array;

Range primitives of these ranges could be more @safe/pure/nothrow/@nogc than current monolithic opApply().

Future ranges could also include depth/breadth first range over all Nodes and their subnodes. The element of such ranges should include Node packed with current depth and maybe some more info.

Broken with dmd-nightly

https://travis-ci.org/dlang-tour/core/jobs/242126360

../../../.dub/packages/dyaml-0.6.2/dyaml/source/dyaml/constructor.d(547,51): Deprecation: function std.string.removechars!string.removechars is deprecated - This function is obsolete and will be removed May 2018. See the docs for more details
../../../.dub/packages/dyaml-0.6.2/dyaml/source/dyaml/scanner.d(166,9): Error: @safe constructor 'dyaml.scanner.Scanner.this' cannot call @system destructor 'dyaml.scanner.Scanner.~this'
dmd failed with exit code 1.

Isn't this fun?

@nogc?

Would like to get some thoughts on this before I put much work into it.

Many parts of this library are marked @nogc. However, despite that, this library cannot be used in @nogc code. Some (limited) testing also shows that any performance gains from this are minimal.

These parts of D-YAML depend on modified copies of phobos functions, making this library quite a bit larger than it needs to be.

My proposal is to completely remove the redundant functions and remove any @nogc annotations that are no longer valid, making this library noticeably slimmer.

Dumper doesn't dump yaml document

I tried this code in DMD 2.071.0,:

import std.stdio;

import yaml;

void main() {
    char[] test =   "Hello World : [Hello, World]\n"
                    "Answer: 42".dup;
    //Read the input.
    Node root = Loader.fromString(test).load();

    //Display the data read.
    foreach(string word; root["Hello World"])
    {
        writeln(word);
    }
    writeln("The answer is ", root["Answer"].as!int);

    //Dump the loaded document to output.yaml.
    Dumper("output.yaml").dump(root);
}

then this code dumped this.:

[239, 187, 191][37, 89, 65, 77, 76, 32][49, 46, 49][10][45, 45, 45][10][72, 101, 108, 108, 111][32][87, 111, 114, 108, 100][58][32][91][72, 101, 108, 108, 111][44][32][87, 111, 114, 108, 100][93][10][65, 110, 115, 119, 101, 114][58][32][52, 50][10]

I think this is caused by dyaml.stream's writing buffer as ubyte[], not char[].
https://github.com/kiith-sa/D-YAML/blob/master/source/dyaml/stream.d#L64

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.