PARSER: extend the core by the string function

This commit is contained in:
hasufell 2014-11-14 21:20:40 +01:00
parent 62d7c9ffcd
commit 53eac4fc5c
No known key found for this signature in database
GPG Key ID: 220CD1C5BDEED020

View File

@ -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