Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rework with mir #271

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,14 @@ example.yaml

# Unittest Coverage output #
*.lst
dyaml-test-library
examples/mir-serde/mir_serde
examples/representer/representer-test-application
examples/resolver/resolver-test-application
examples/tojson/tojson
examples/tojson/tojson-test-application
examples/yaml_bench/benchmark
examples/yaml_bench/benchmark-test-application
examples/yaml_gen/yaml_gen-test-application
examples/yaml_stats/yaml_stats-test-application
examples/constructor/constructor-test-application
19 changes: 10 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,16 @@ script:
- meson build && ninja -j8 -C build
- ninja -j8 -C build test -v
- dub build
- "dub build dyaml:benchmark"
- "dub build dyaml:constructor"
- "dub build dyaml:getting-started"
- "dub build dyaml:representer"
- "dub build dyaml:resolver"
- "dub build dyaml:testsuite"
- "dub build dyaml:tojson"
- "dub build dyaml:yaml_gen"
- "dub build dyaml:yaml_stats"
- dub build dyaml:benchmark
- dub build dyaml:constructor
- dub build dyaml:getting-started
- dub build dyaml:representer
- dub build dyaml:resolver
- dub build dyaml:testsuite
- dub build dyaml:tojson
- dub build dyaml:yaml_gen
- dub build dyaml:yaml_stats
- dub test --build=unittest-cov
- dub --root examples/mir-serde
after_success:
- bash <(curl -s https://codecov.io/bash)
1 change: 1 addition & 0 deletions contrib/mir-algorithm
Submodule mir-algorithm added at 979e39
4 changes: 4 additions & 0 deletions contrib/mir-algorithm.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wrap-git]
directory=mir-algorithm
url=https://github.com/libmir/mir-algorithm.git
revision=head
1 change: 1 addition & 0 deletions contrib/mir-core
Submodule mir-core added at 5e97e0
4 changes: 4 additions & 0 deletions contrib/mir-core.wrap
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[wrap-git]
directory=mir-core
url=https://github.com/libmir/mir-core.git
revision=head
1 change: 1 addition & 0 deletions contrib/tinyendian
Submodule tinyendian added at 7b67bd
6 changes: 3 additions & 3 deletions docs/tutorials/yaml_syntax.md
Original file line number Diff line number Diff line change
Expand Up @@ -230,12 +230,12 @@ Some of these might change in the future (especially !!map and !!set).

|YAML tag |D type |
|-----------------------|-----------------------|
|!!null |dyaml.node.YAMLNull |
|!!null |typeof(null) |
|!!bool |bool |
|!!int |long |
|!!float |real |
|!!float |double |
|!!binary |ubyte[] |
|!!timestamp |std.datetime.SysTime |
|!!timestamp |mir.timestamp.Timestamp|
|!!map, !!omap, !!pairs |dyaml.node.Node.Pair[] |
|!!seq, !!set |dyaml.node.Node[] |
|!!str |string |
3 changes: 2 additions & 1 deletion dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
],
"license": "BSL-1.0",
"dependencies": {
"tinyendian" : "~>0.2.0"
"tinyendian" : "~>0.2.0",
"mir-algorithm" : ">=3.10.71"
},
"homepage": "https://github.com/dlang-community/D-YAML",
"copyright": "Copyright © 2011-2018, Ferdinand Majerech",
Expand Down
2 changes: 1 addition & 1 deletion examples/constructor/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"mainSourceFile": "main.d",
"dependencies":
{
"dyaml": { "version" : "*"}
"dyaml": { "path" : "../../"}
}
}
2 changes: 1 addition & 1 deletion examples/getting_started/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"mainSourceFile": "main.d",
"dependencies":
{
"dyaml": { "version" : "*" }
"dyaml": { "path" : "../../"}
}
}
3 changes: 3 additions & 0 deletions examples/mir-serde/dub.sdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
name "mir_serde"
dependency "mir-ion" version="*"
dependency "dyaml" path="../../"
69 changes: 69 additions & 0 deletions examples/mir-serde/source/main.d
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import dyaml;

import mir.algebraic_alias.json;
import mir.format;
import mir.ion.conv: json2ion;
import mir.ion.deser.ion: deserializeIon;
import mir.ion.ser.ion: serializeIon;
import mir.ion.ser.json: serializeJsonPretty;
import mir.serde;

static immutable yaml = `
type: request
value: 123.4
name: "London"
`;

struct S
{
enum Type {
response,
request,
}

private this(Type type, string name, JsonAlgebraic value) {
this.type = type;
this._name = name;
this.value = value;
}

Type type;

private string _name;

@serdeKeys("name")
void setName(string name) @property
{
_name = name;
}

@serdeKeys("name")
auto getName() @property
{
return _name;
}

JsonAlgebraic value;
}

static immutable json = "{
\t\"type\": \"request\",
\t\"value\": 123.4,
\t\"name\": \"London\"
}";

import std.stdio;

void main()
{
assert(Loader.fromString(yaml).load().serializeJsonPretty == json);
auto s = Loader.fromString(yaml).load().serializeIon.deserializeIon!S;
assert(s == S(S.Type.request, "London", JsonAlgebraic(123.4)));

auto app = stringBuf();
Dumper().dump(&app, json.json2ion.deserializeIon!Node);
auto yamlData = app.data.idup;
import std.stdio;
writeln(s);
writeln(yamlData);
}
2 changes: 1 addition & 1 deletion examples/representer/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"mainSourceFile": "main.d",
"dependencies":
{
"dyaml": { "version" : "*" }
"dyaml": { "path" : "../../"}
}
}
2 changes: 1 addition & 1 deletion examples/resolver/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"mainSourceFile": "main.d",
"dependencies":
{
"dyaml": { "version" : "*" }
"dyaml": { "path" : "../../"}
}
}
2 changes: 1 addition & 1 deletion examples/tojson/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"targetType": "executable",
"dependencies":
{
"dyaml": "*"
"dyaml": { "path" : "../../"}
}
}
8 changes: 4 additions & 4 deletions examples/tojson/source/app.d
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module dyaml.tojson;
import std.datetime;

import mir.timestamp;
import std.json;
import std.stdio;
import dyaml;
Expand Down Expand Up @@ -37,18 +38,17 @@ JSONValue toJSON(Node node)
output = node.as!long;
break;
case NodeType.decimal:
output = node.as!real;
output = node.as!double;
break;
case NodeType.boolean:
output = node.as!bool;
break;
case NodeType.timestamp:
output = node.as!SysTime.toISOExtString();
output = node.as!Timestamp.toISOExtString;
break;
case NodeType.merge:
case NodeType.null_:
case NodeType.binary:
case NodeType.invalid:
}
return output;
}
2 changes: 1 addition & 1 deletion examples/yaml_bench/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"mainSourceFile": "yaml_bench.d",
"dependencies":
{
"dyaml": { "version" : "*" }
"dyaml": { "path" : "../../"}
}
}
8 changes: 4 additions & 4 deletions examples/yaml_bench/yaml_bench.d
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
module dyaml.yaml_bench;
//Benchmark that loads, and optionally extracts data from and/or emits a YAML file.

import mir.timestamp;
import std.algorithm;
import std.conv;
import std.datetime.systime;
import std.datetime.stopwatch;
import std.file;
import std.getopt;
Expand All @@ -23,12 +23,12 @@ void extract(ref Node document) @safe
case NodeID.scalar:
switch(root.tag)
{
case "tag:yaml.org,2002:null": auto value = root.as!YAMLNull; break;
case "tag:yaml.org,2002:null": auto value = root.as!(typeof(null)); break;
case "tag:yaml.org,2002:bool": auto value = root.as!bool; break;
case "tag:yaml.org,2002:int": auto value = root.as!long; break;
case "tag:yaml.org,2002:float": auto value = root.as!real; break;
case "tag:yaml.org,2002:float": auto value = root.as!double; break;
case "tag:yaml.org,2002:binary": auto value = root.as!(ubyte[]); break;
case "tag:yaml.org,2002:timestamp": auto value = root.as!SysTime; break;
case "tag:yaml.org,2002:timestamp": auto value = root.as!Timestamp; break;
case "tag:yaml.org,2002:str": auto value = root.as!string; break;
default: writeln("Unrecognozed tag: ", root.tag);
}
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml_gen/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"mainSourceFile": "yaml_gen.d",
"dependencies":
{
"dyaml": { "version" : "*" }
"dyaml": { "path" : "../../"}
}
}
8 changes: 4 additions & 4 deletions examples/yaml_gen/yaml_gen.d
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ static this()
generators["set"] = &genSet;
}

real randomNormalized(const string distribution = "linear")
double randomNormalized(const string distribution = "linear")
{
auto generator = Random(unpredictableSeed());
const r = uniform!"[]"(0.0L, 1.0L, generator);
Expand All @@ -58,7 +58,7 @@ long randomLong(const long min, const long max, const string distribution = "lin
return min + cast(long)round((max - min) * randomNormalized(distribution));
}

real randomReal(const real min, const real max, const string distribution = "linear")
double randomReal(const double min, const double max, const string distribution = "linear")
{
return min + (max - min) * randomNormalized(distribution);
}
Expand Down Expand Up @@ -111,7 +111,7 @@ Node genFloat(bool root = false)
{
auto range = config["float"]["range"];

const result = randomReal(range["min"].as!real, range["max"].as!real,
const result = randomReal(range["min"].as!double, range["max"].as!double,
range["dist"].as!string);

return Node(result);
Expand All @@ -129,7 +129,7 @@ Node genTimestamp(bool root = false)
auto hnsecs = randomLong(range["min"].as!ulong, range["max"].as!ulong,
range["dist"].as!string);

if(randomNormalized() <= config["timestamp"]["round-chance"].as!real)
if(randomNormalized() <= config["timestamp"]["round-chance"].as!double)
{
hnsecs -= hnsecs % 10000000;
}
Expand Down
2 changes: 1 addition & 1 deletion examples/yaml_stats/dub.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@
"mainSourceFile": "yaml_stats.d",
"dependencies":
{
"dyaml": { "version" : "*" }
"dyaml": { "path" : "../../"}
}
}
4 changes: 2 additions & 2 deletions examples/yaml_stats/yaml_stats.d
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ string statistics(ref Node document)
"\nAverage mapping length: %s" ~
"\n\n%s",
nodes, scalars, sequences, mappings,
sequences == 0.0 ? 0.0 : cast(real)seqItems / sequences,
mappings == 0.0 ? 0.0 : cast(real)mapPairs / mappings,
sequences == 0.0 ? 0.0 : cast(double)seqItems / sequences,
mappings == 0.0 ? 0.0 : cast(double)mapPairs / mappings,
tagStats);
}

Expand Down
16 changes: 13 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,20 @@ dyaml_src = [
]
install_subdir('source/dyaml', install_dir: 'include/d/yaml/')

tinyendian_dep = dependency('tinyendian', version: '>=0.2.0', fallback: ['tinyendian', 'tinyendian_dep'])
subprojects = ['mir-core', 'mir-algorithm']

required_deps = []

foreach p : subprojects
required_deps += dependency(p, fallback : [p, 'this_dep'])
endforeach

required_deps += dependency('tinyendian', version: '>=0.2.0', fallback: ['tinyendian', 'tinyendian_dep'])

dyaml_lib = library('dyaml',
[dyaml_src],
include_directories: [src_dir],
dependencies: [tinyendian_dep],
dependencies: required_deps,
install: true,
version: meson.project_version(),
soversion: project_soversion
Expand All @@ -66,5 +74,7 @@ pkgc.generate(name: 'dyaml',
dyaml_dep = declare_dependency(
link_with: dyaml_lib,
include_directories: [src_dir],
dependencies: [tinyendian_dep]
dependencies: required_deps
)

this_dep = dyaml_dep
2 changes: 2 additions & 0 deletions output.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
%YAML 1.1
--- [!color 'FF0000', !color '00FF00', !color '0000FF']
Loading