Skip to content

Commit

Permalink
Merge new spiff to spiff++ release 1.0.8-ms.7
Browse files Browse the repository at this point in the history
  • Loading branch information
mandelsoft committed Dec 13, 2016
2 parents 4ef5515 + 1e6bffc commit 37ed0c2
Show file tree
Hide file tree
Showing 14 changed files with 588 additions and 421 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ spiff++/spiff_darwin_amd64.zip
spiff++/spiff_linux_amd64.zip
*.coverprofile
/spiff
spiff_darwin_amd64.zip
spiff_linux_amd64.zip

2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: go

go:
- 1.2
- 1.7

install:
- go get -v github.com/kr/godep
Expand Down
5 changes: 5 additions & 0 deletions Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Contents:
- [(( list_to_map(list, "key") ))](#-list_to_maplist-key-)
- [(( makemap(fieldlist) ))](#-makemapfieldlist-)
- [(( makemap(key, value) ))](#-makemapkey-value-)
- [(( merge(map1, map2) ))](#-mergemap1-map2-)
- [(( lambda |x|->x ":" port ))](#-lambda-x-x--port-)
- [(( &temporary ))](#-temporary-)
- [Mappings](#mappings)
Expand Down Expand Up @@ -1689,6 +1690,56 @@ map:
In contrast to the previous `makemap` flavor, this one could also be handled by
[map literals](#--alice--25--).

### `(( merge(map1, map2) ))`

Beside the keyword ` merge` there is also a function called `merge` (It must always be followed by an opensing bracket). It can be used to merge severals maps taken from the actual document. If the maps are specified by reference expressions, they cannot contain
any _dynaml_ expressions, because they are always evaluated in the context of the actual document before evaluating the arguments.

e.g.:

```yaml
map1:
alice: 24
bob: 25
map2:
alice: 26
peter: 8
result: (( merge(map1,map2) ))
```

resolves `result` to

```yaml
result:
alice: 26
bob: 25
```

A map might also be given by a map expression. Here it is possible to specify
dynaml expressions using the usual syntax:

e.g.:

```yaml
map1:
alice: 24
bob: 25
map2:
alice: 26
peter: 8
result: (( merge(map1, map2, { "bob"="(( carl ))", "carl"=100 }) ))
```

resolves `result` to

```yaml
result:
alice: 26
bob: 100
```

## `(( lambda |x|->x ":" port ))`

Lambda expressions can be used to define additional anonymous functions. They can be assigned to yaml nodes as values and referenced with path expressions to call the function with approriate arguments in other dynaml expressions. For the final document they are mapped to string values.
Expand Down
3 changes: 3 additions & 0 deletions dynaml/call.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,9 @@ func (e CallExpr) Evaluate(binding Binding, locally bool) (interface{}, Evaluati
case "ipset":
result, sub, ok = func_ipset(values, binding)

case "merge":
result, sub, ok = func_merge(values, binding)

default:
return info.Error("unknown function '%s'", funcName)
}
Expand Down
2 changes: 1 addition & 1 deletion dynaml/dynaml.peg
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ Assignment <- Expression '=' Expression

Merge <- RefMerge / SimpleMerge
RefMerge <- 'merge' !( req_ws Required ) ( req_ws (Replace / On ))? req_ws Reference
SimpleMerge <- 'merge' ( req_ws (Replace/Required/On) )?
SimpleMerge <- 'merge' !'(' ( req_ws (Replace/Required/On) )?
Replace <- 'replace'
Required <- 'required'
On <- 'on' req_ws Name
Expand Down
Loading

0 comments on commit 37ed0c2

Please sign in to comment.