From 53eac4fc5cb17b4c25e9de0a69f7e2b731c94f52 Mon Sep 17 00:00:00 2001 From: hasufell Date: Fri, 14 Nov 2014 21:20:40 +0100 Subject: [PATCH] PARSER: extend the core by the string function --- Parser/Core.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) 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