Copyright | (c) Sebastian Galkin 2018 |
---|---|
License | GPL-3 |
Safe Haskell | None |
Language | Haskell2010 |
- program :: Parser (Program Unoptimized)
- operation :: Parser Op
- bfSimpleTokens :: String
- bfTokens :: String
- garbage :: Parser Char
- simpleOp :: Parser Op
- loopOp :: Parser Op
- parseProgram :: Text -> Either ParseError (Program Unoptimized)
- data ParseError :: *
Documentation
>>>
:set -XOverloadedStrings
>>>
import Data.Either
>>>
let parse :: Parser a -> Text -> Either ParseError a; parse p text = runP p () "" text
program :: Parser (Program Unoptimized) Source #
Parser for a full Program
.
>>>
isRight $ parse program " +[->>+ +[<] ##garbage## ],.[-] can ignore garbage"
True
operation :: Parser Op Source #
Parser for an Op
, ignoring unknown characters.
>>>
parse operation " +///"
Right (Inc 1 0)
>>>
parse operation "fooo [+>] baaar "
Right (Loop [Inc 1 0,Move 1])
bfSimpleTokens :: String Source #
The characters allowed in a Brainfuck program except for the loop characters [
and ]
.
garbage :: Parser Char Source #
Parser for unknown characters
>>>
parse garbage "this is @#! garbage"
Right 't'
>>>
isLeft $ parse garbage "+"
True
simpleOp :: Parser Op Source #
Parser for simple operations (not loops).
>>>
parse simpleOp ">"
Right (Move 1)
>>>
parse simpleOp "."
Right (Out 1 0)
Parser for loops.
>>>
parse loopOp "[+-]"
Right (Loop [Inc 1 0,Inc (-1) 0])
parseProgram :: Text -> Either ParseError (Program Unoptimized) Source #
Parse program stream. Returns an error or the parsed Program