lang: Add edges to lexer and parser

This adds some initial syntax for external edges to the language.

There are still improvements which are necessary for send/recv.
This commit is contained in:
James Shubin
2018-02-10 11:22:18 -05:00
parent 80784bb8f1
commit 6370f0cb95
14 changed files with 354 additions and 11 deletions

14
examples/lang/edges0.mcl Normal file
View File

@@ -0,0 +1,14 @@
exec "exec0" {
cmd => "sleep 10s",
shell => "/bin/bash",
}
exec "exec1" {
cmd => "sleep 10s",
shell => "/bin/bash",
}
exec "exec2" {
cmd => "sleep 10s",
shell => "/bin/bash",
}
Exec["exec0"] -> Exec["exec1"] -> Exec["exec2"]

View File

@@ -0,0 +1,8 @@
password "pass0" {
length => 8,
}
file "/tmp/mgmt/password" {
}
Password["pass0"].password -> File["/tmp/mgmt/password"].content

View File

@@ -0,0 +1,9 @@
exec "exec0" {
cmd => "echo hello world && echo goodbye world 1>&2", # to stdout && stderr
shell => "/bin/bash",
}
print "print0" {
}
Exec["exec0"].output -> Print["print0"].msg

View File

@@ -0,0 +1,14 @@
file "/tmp/mgmt/foo" {
content => "hello from foo\n",
}
print "print0" {
}
File["/tmp/mgmt/foo"].content -> Print["print0"].msg
print "print1" {
msg => "hello",
}
Print["print0"] -> Print["print1"]

View File

@@ -0,0 +1,8 @@
file "/tmp/mgmt/foo" {
content => "hello from foo\n",
}
file "/tmp/mgmt/bar" {
}
File["/tmp/mgmt/foo"].content -> File["/tmp/mgmt/bar"].content

View File

@@ -0,0 +1,21 @@
$ns = "estate"
$exchanged = kvlookup($ns)
$state = maplookup($exchanged, $hostname, "default")
exec "exec0" {
cmd => "echo hello world && echo goodbye world 1>&2", # to stdout && stderr
shell => "/bin/bash",
}
kv "kv0" {
key => $ns,
#value => "two",
}
Exec["exec0"].output -> Kv["kv0"].value
if $state != "default" {
file "/tmp/mgmt/state" {
content => printf("state: %s\n", $state),
}
}

View File

@@ -8,28 +8,43 @@ if $state == "one" || $state == "default" {
file "/tmp/mgmt/state" {
content => "state: one\n",
}
exec "timer" {
cmd => "/usr/bin/sleep 1s",
}
kv "${ns}" {
key => $ns,
value => "two",
}
Exec["timer"] -> Kv["${ns}"]
}
if $state == "two" {
file "/tmp/mgmt/state" {
content => "state: two\n",
}
exec "timer" {
cmd => "/usr/bin/sleep 1s",
}
kv "${ns}" {
key => $ns,
value => "three",
}
Exec["timer"] -> Kv["${ns}"]
}
if $state == "three" {
file "/tmp/mgmt/state" {
content => "state: three\n",
}
exec "timer" {
cmd => "/usr/bin/sleep 1s",
}
kv "${ns}" {
key => $ns,
value => "one",
}
Exec["timer"] -> Kv["${ns}"]
}