Turing-complete YAML on steroids.
Load only data with variables:
name: "John"
count: $count
final cryaml = loadCrYAML(source);
final data = cryaml.evaluate({"count": 1}); // {"name": "John", count: 1}
Use functions inside document:
user:
name: "John"
count: multiply($count, times: 3)
final cryaml = loadCrYAML(source, Specification(
functions: {
"multiply": (int count, {int times: 1}) => count * times,
}),
);
final data = cryaml.evaluate({"count": 1}); // {"name": "John", count: 2}
Use directives:
@user
name: "John"
count: multiply($count, times: 3)
class UserDirective extends Directive {
final specification = const DirectiveSpec(
documentType: DocumentType.map,
);
User call(CrYAMLContext context, {Map document()}) {
final result = document();
return User(
name: result["name"],
count: result["count"],
);
}
}
final cryaml = loadCrYAML(
source,
Specification(
functions: {
"multiply": (int count, {int times: 1}) => count * times,
},
directives: {"user": UserDirective()},
),
);
final data = cryaml.evaluate({"count": 1}); // {"name": "John", count: 2}