I've been trying to figure out how I can go about parsing something like following:
[server.a.metadata]
port = 1000
[server.b]
backoff = 1
[server.b.metadata]
port = 2000
In this,
server.*.metadata table exist - it could be a, b, c, prod, staging and so on (not known ahead of time)
I would like to parse it into following structure,
data ServerMetadata = ServerMetadata { port :: Int, backoff :: Maybe Int }
type Servers = Map Text ServerMetadata
-- fromList [
-- ("a", ServerMetadata 1000 Nothing),
-- ("b", ServerMetadata 1000 (Just 1)
-- ]
I tried using tableMap, and variety of combinations - but I was not able to get it to work. Appreciate any pointers on how to accomplish this.
If it helps here is the raw toml.
Right
( TOML
{ tomlPairs = fromList []
, tomlTables = fromList
[
( "server"
, Branch
( "server" :| [] ) Nothing
( fromList
[
( "a"
, Leaf
( "a" :| [ "metadata" ] )
( TOML
{ tomlPairs = fromList
[
( "port" :| []
, Integer 1000
)
]
, tomlTables = fromList []
, tomlTableArrays = fromList []
}
)
)
,
( "b"
, Leaf
( "b" :| [] )
( TOML
{ tomlPairs = fromList
[
( "backoff" :| []
, Integer 1
)
]
, tomlTables = fromList
[
( "metadata"
, Leaf
( "metadata" :| [] )
( TOML
{ tomlPairs = fromList
[
( "port" :| []
, Integer 2000
)
]
, tomlTables = fromList []
, tomlTableArrays = fromList []
}
)
)
]
, tomlTableArrays = fromList []
}
)
)
]
)
)
]
, tomlTableArrays = fromList []
}
)
I've been trying to figure out how I can go about parsing something like following:
In this,
server.*.metadatatable exist - it could bea,b,c,prod,stagingand so on (not known ahead of time)I would like to parse it into following structure,
I tried using
tableMap, and variety of combinations - but I was not able to get it to work. Appreciate any pointers on how to accomplish this.If it helps here is the raw toml.