-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathParameter.hs
More file actions
35 lines (23 loc) · 830 Bytes
/
Parameter.hs
File metadata and controls
35 lines (23 loc) · 830 Bytes
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
{-# LANGUAGE OverloadedStrings #-}
module Parameter (
Parameter (..)
,packParam
) where
import Control.Applicative ((<$>), (<*>))
import Data.Aeson
import Common
import qualified Data.Text as T
import Types
import Data
import Auto
packParam :: Parameter -> Auto [Byte]
packParam (Parameter _ (Var name)) = envLookup name >>= packParam
packParam (Parameter _ d) = return . packData $ d
instance FromJSON Parameter where
parseJSON (Object o) = Parameter <$> o .:? "label" .!= "unnamed"<*> parseJSON (Object o)
parseJSON (String s) = return $ Parameter (T.unpack s) (Var (T.unpack s))
parseJSON _ = error "Invalid parameter type."
instance AutoShow Parameter where
autoShow p@(Parameter s _) = do
packed <- packParam p
return $ s ++ ": " ++ concatMap ((++ "|") . showHex') packed