hbf-0.2.0.0: An optimizing Brainfuck compiler and evaluator

Copyright(c) Sebastian Galkin 2018
LicenseGPL-3
Safe HaskellNone
LanguageHaskell2010

HBF.Parser

Contents

Description

Parsing Text into Program Unparsed

Synopsis

Documentation

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 ].

bfTokens :: String Source #

The characters allowed in a Brainfuck program.

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)

loopOp :: Parser Op Source #

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

Reexport from Text.Parsec

data ParseError #

The abstract data type ParseError represents parse errors. It provides the source position (SourcePos) of the error and a list of error messages (Message). A ParseError can be returned by the function parse. ParseError is an instance of the Show and Eq classes.

Instances
Eq ParseError 
Instance details

Defined in Text.Parsec.Error

Show ParseError 
Instance details

Defined in Text.Parsec.Error