summaryrefslogtreecommitdiff
path: root/Fractran/Parser.hs
diff options
context:
space:
mode:
authorJed Barber <jjbarber@y7mail.com>2014-04-10 05:25:03 +1000
committerJed Barber <jjbarber@y7mail.com>2014-04-10 05:25:03 +1000
commit281425310c5db21f87981eeb9601a71d1974d98d (patch)
treebef4643d906c93622c311fef2cf758fe94f1f651 /Fractran/Parser.hs
parente8695600977769008f285f9958eb043cca1b9b29 (diff)
Rearranging files
Diffstat (limited to 'Fractran/Parser.hs')
-rw-r--r--Fractran/Parser.hs68
1 files changed, 0 insertions, 68 deletions
diff --git a/Fractran/Parser.hs b/Fractran/Parser.hs
deleted file mode 100644
index 95aa954..0000000
--- a/Fractran/Parser.hs
+++ /dev/null
@@ -1,68 +0,0 @@
-module Fractran.Parser (
- FractranProgram(..),
-
- parseFractran
- ) where
-
-
-import Control.Applicative( some )
-import Text.ParserCombinators.Parsec
-
-
-
-data FractranProgram = FractranProgram { fractions :: [(Int,Int)]
- , initialValue :: Int }
- deriving (Show, Eq)
-
-
-
-
-parseFractran :: String -> Either ParseError FractranProgram
-parseFractran = parse fractran "error"
-
-
-
-
-fractran = do
- whiteSpace
- value <- initVal
- fractionList <- many intPair
- eof
- return (FractranProgram fractionList value)
-
-
-intPair = do
- numerator <- wholeNumber
- slash
- denominator <- positiveNumber
- whiteSpace
- return (numerator,denominator)
-
-
-slash = char '/'
- <?> "slash character"
-
-
-initVal = do
- value <- wholeNumber
- whiteSpace
- return value
-
-
-wholeNumber = do
- value <- some digit
- return (read value)
-
-
-positiveNumber = do
- firstDigit <- nonZeroDigit
- rest <- many digit
- return (read (firstDigit:rest))
-
-
-nonZeroDigit = oneOf "123456789"
- <?> "non-zero digit"
-
-
-whiteSpace = many (oneOf "\t\n\r ")
-