PARSER: extend the core by the string function
This commit is contained in:
parent
62d7c9ffcd
commit
53eac4fc5c
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user