-
Notifications
You must be signed in to change notification settings - Fork 0
/
dsl.tiny
91 lines (77 loc) · 2.04 KB
/
dsl.tiny
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
############################################################
#
# An example of a DSC-like (Puppet-like) DSL written in Tiny
#
############################################################
import 'DataUtils'
#
# Example using the DSL
#
# Create a configuration named 'FirstConfiguration'.
configuration 'FirstConfiguration'
{
# Configuration metadata
{
author: "bob"
date : getdate()
}
# An optional file resource
if (args) {
file 'file1' {
path : "foo/bar.txt"
content : "some content"
}
}
# A registry resource
registry 'registry1'
{
path : "foo/bar"
key : "zork"
value : if (getdate().Day % 2 == 0)
{ "even" }
else
{ "odd" }
}
# Another file resource
file 'file2'
{
path : "foo/buz.txt"
content : "some other content"
}
}
###########################################################
#
# Implementation of the DSL. 'keywords' correspond to
# simple functions.
#
# A function used to contain the entire configuration.
# Returns the complete configuration as a JSON string.
fn configuration [<string>] name {
if ((body is [<TinyLambda>]) |> not) {
throw "configuration: argument 'lambda' was null"
}
# Set the name in the configuration
complete = {configurationName: name};
# individually evaluate each statement in the body
foreach (val in body.DotReturnAll()) {
if (val is [<IDictionary>]) {
complete += val
}
}
# Turn the result into a JSON object
DataUtils.ToJson( complete )
}
# Mocking the file resource
fn file id {
if (body == null || not (body is [<IDictionary>])) {
throw 'file: body must be a dictionary'
}
newhash("resource:file:" + id, body)
}
# Mocking the registry resource
fn registry id {
if (body == null || not (body is [<IDictionary>])) {
throw 'registry: body must be a dictionary'
}
newhash("resource:registry:" + id, body)
}