diff options
author | Jed Barber <jjbarber@y7mail.com> | 2014-03-09 04:31:10 +1100 |
---|---|---|
committer | Jed Barber <jjbarber@y7mail.com> | 2014-03-09 04:31:10 +1100 |
commit | 5101efa873d488da43ff843dab2e8d66df34fd6d (patch) | |
tree | 171e1b6b4fb90e732dfd02d3e2c525ef034add93 /Unlambda | |
parent | 257a7a01f797560f9271a4ef779956771acc4a7b (diff) |
Added support for comments
Diffstat (limited to 'Unlambda')
-rw-r--r-- | Unlambda/Parser.hs | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/Unlambda/Parser.hs b/Unlambda/Parser.hs index 384ec8f..8b3c898 100644 --- a/Unlambda/Parser.hs +++ b/Unlambda/Parser.hs @@ -6,6 +6,7 @@ module Unlambda.Parser ( import Control.Applicative( some ) +import Data.Either import Text.ParserCombinators.Parsec @@ -27,15 +28,39 @@ data UnlambdaTerm = S | K | I | V | R | D | C | E | Bar | Reed parseUnlambda :: String -> Either ParseError UnlambdaTerm -parseUnlambda = parse unlambda "error" +parseUnlambda input = + let firstPass = parse removeComments "error" input + in case firstPass of + Left e -> Left e + Right o -> parse unlambda "error" o parseUnlambda1 :: String -> Either ParseError UnlambdaTerm -parseUnlambda1 = parse unlambda1 "error" +parseUnlambda1 input = + let firstPass = parse removeComments "error" input + in case firstPass of + Left e -> Left e + Right o -> parse unlambda1 "error" o +removeComments = uline `sepEndBy` eol >>= (return . concat) + + +uline = do + l <- many (noneOf "#\r\n") + optional (char '#' >> many (noneOf "\r\n")) + return l + + +eol = try (string "\r\n") + <|> try (string "\n\r") + <|> try (string "\r") + <|> try (string "\n") + <?> "end of line" + + unlambda = do whiteSpace t <- term @@ -92,14 +117,14 @@ bar = char '|' >> whiteSpace >> return Bar comp = do char '?' - c <- noneOf("") + c <- anyChar whiteSpace return (Compare c) dot = do char '.' - c <- noneOf("") + c <- anyChar whiteSpace return (Dot c) |