3 import Control.Applicative ( (<|>), some )
5 import Text.ParserCombinators.ReadP
6 import System.Environment
18 - wait ::= wait for (pred+ | any)
22 - block ::= str wait send?
25 data Block = Block String Wait (Maybe Send)
27 data Wait = WaitPred [Predicate]
30 data Predicate = Predicate String String
32 data Send = Send [Message]
36 skip = skipMany $ satisfy isSpace <|> char '\n' <|> char '\r'
38 strLit :: ReadP String
39 strLit = between (char '"') (char '"') (many (satisfy (/= '"')))
48 s <- option Nothing (Just <$> send)
49 return $ Block name w s
56 where f = string "any" >> return WaitAny
57 g = WaitPred <$> some predicate
59 predicate :: ReadP Predicate
67 return $ Predicate x y
73 Send <$> some (skip >> strLit)
75 parseScript :: String -> [Block]
76 parseScript = fst . last . readP_to_S (some block)
79 fileName <- head <$> getArgs
80 print . parseScript =<< readFile fileName