diff --git a/Parser/Core.hs b/Parser/Core.hs index 66f620d..e13dee2 100644 --- a/Parser/Core.hs +++ b/Parser/Core.hs @@ -1,9 +1,10 @@ {-# OPTIONS_HADDOCK ignore-exports #-} -module Parser.Core (Parser, +module Parser.Core (Parser(MkParser), runParser, satisfy, char, + string, posInt, posDouble, negDouble, @@ -14,6 +15,8 @@ module Parser.Core (Parser, import Control.Applicative import Data.Char +import Data.List +import Data.Maybe import MyPrelude @@ -66,6 +69,17 @@ char :: Char -> Parser Char char c = satisfy (== c) +-- |Creates a Parser that accepts a given String. +string :: String -> Parser String +string str = MkParser f + where + f [] = Nothing + f allstr + | str `isPrefixOf` allstr = + Just(str, fromJust . stripPrefix str $ allstr) + | otherwise = Nothing + + -- |Creates a Parser that accepts positive integers. posInt :: Parser Integer posInt = MkParser f