I added a few prisms and a lens to language-puppet
. I use it mainly for manipulating manifest files. Here is an example, with some ‘type annotation’ that should give an idea on how this work :
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
import Control.Lens
import Puppet.Lens
import Control.Lens.Aeson
import qualified Data.Text as T
import qualified Data.Text.IO as T
content :: T . Text
content = "node 'test' { $x = 12 }"
main :: IO ()
main = T . putStrLn $ content -- T.Text
& _PParse -- [Vector Statement]
. traverse -- [Statement]
. _Statements -- [[Statement]]
. traverse -- [Statement]
. _VariableAssignment -- [(T.Text, Expression, PPosition)]
. _2 -- [Expression]
. _PResolveExpression -- [PValue]
. _Integer -- [Integer]
+~ 2
The result of this program is :
1
2
3
4
node "test"
{
$x = "14"
}
This is much nicer than the many ad-hoc transformations I have written.