This repository has been archived by the owner on May 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
106 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,17 @@ | ||
module App where | ||
|
||
import Args ( args ) | ||
|
||
import Args ( args | ||
, path | ||
) | ||
import Mbl ( parseMbl, interpret ) | ||
import qualified Data.ByteString as BS | ||
import qualified Data.Text as T | ||
|
||
main :: IO () | ||
main = do | ||
config <- args | ||
print config | ||
config <- args | ||
contents <- BS.readFile $ T.unpack $ path config | ||
mbl <- either (fail) pure $ parseMbl contents | ||
interpret mbl | ||
putStrLn "3" | ||
putStrLn "4" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module Mbl where | ||
|
||
import qualified Mbl.Types as Types | ||
import qualified Mbl.Parser as Parser | ||
import qualified Mbl.Interpreter as Interpreter | ||
import qualified Data.ByteString as BS | ||
|
||
parseMbl :: BS.ByteString -> Either String Types.MBL | ||
parseMbl = Parser.parse | ||
|
||
interpret :: Types.MBL -> IO () | ||
interpret = Interpreter.interpret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Mbl.Interpreter where | ||
|
||
import Mbl.Types | ||
import qualified Control.Concurrent as C | ||
|
||
|
||
interpret :: MBL -> IO () | ||
interpret _ = C.threadDelay 30000000 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
module Mbl.Parser where | ||
|
||
import Prelude hiding ( takeWhile | ||
) | ||
import Data.Attoparsec.ByteString.Char8 | ||
( Parser | ||
, endOfInput | ||
, parseOnly | ||
, char | ||
, takeWhile1 | ||
) | ||
import Data.ByteString ( ByteString ) | ||
import Control.Applicative ( many | ||
, (<|>) | ||
) | ||
import Mbl.Types | ||
|
||
parse :: ByteString -> Either String MBL | ||
parse = parseOnly (mbl <* endOfInput) | ||
|
||
delimiter :: Char | ||
delimiter = '-' | ||
|
||
wait :: Parser Action | ||
wait = char delimiter *> pure Wait | ||
|
||
print :: Parser Action | ||
print = Print <$> takeWhile1 (\c -> c /= delimiter) | ||
|
||
mbl :: Parser MBL | ||
mbl = many $ wait <|> print |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module Mbl.Types where | ||
|
||
|
||
import Data.ByteString ( ByteString ) | ||
|
||
data Action = Wait | Print ByteString deriving (Show, Eq) | ||
|
||
type MBL = [Action] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module MblSpec where | ||
|
||
import Test.Hspec | ||
import Mbl | ||
import Mbl.Types | ||
|
||
-- TODO spaces between | ||
|
||
spec :: Spec | ||
spec = do | ||
describe "Mbl" $ do | ||
describe "Simple" $ do | ||
it "can parse waits" $ do | ||
parseMbl "---" `shouldBe` Right [Wait, Wait, Wait] | ||
it "can parse prints" $ do | ||
parseMbl "foo" `shouldBe` Right [Print "foo"] | ||
describe "Combo" $ do | ||
it "can parse waits and prints" $ do | ||
parseMbl "-foo--bar" | ||
`shouldBe` Right [Wait, Print "foo", Wait, Wait, Print "bar"] | ||
describe "Edge case" $ do | ||
it "parses empty string ok" $ do | ||
parseMbl "" | ||
`shouldBe` Right [] | ||
describe "Escaped" $ do | ||
it "can print the delimiter if escaped with \\ " $ do | ||
parseMbl "--this is a\\-somewhat\\-convoluted example" | ||
`shouldBe` Right [Wait, Wait, Print "this is a-somewhat-convoluted example"] |