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 #-}
|
{-# OPTIONS_HADDOCK ignore-exports #-}
|
||||||
|
|
||||||
module Parser.Core (Parser,
|
module Parser.Core (Parser(MkParser),
|
||||||
runParser,
|
runParser,
|
||||||
satisfy,
|
satisfy,
|
||||||
char,
|
char,
|
||||||
|
string,
|
||||||
posInt,
|
posInt,
|
||||||
posDouble,
|
posDouble,
|
||||||
negDouble,
|
negDouble,
|
||||||
@ -14,6 +15,8 @@ module Parser.Core (Parser,
|
|||||||
|
|
||||||
import Control.Applicative
|
import Control.Applicative
|
||||||
import Data.Char
|
import Data.Char
|
||||||
|
import Data.List
|
||||||
|
import Data.Maybe
|
||||||
import MyPrelude
|
import MyPrelude
|
||||||
|
|
||||||
|
|
||||||
@ -66,6 +69,17 @@ char :: Char -> Parser Char
|
|||||||
char c = satisfy (== c)
|
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.
|
-- |Creates a Parser that accepts positive integers.
|
||||||
posInt :: Parser Integer
|
posInt :: Parser Integer
|
||||||
posInt = MkParser f
|
posInt = MkParser f
|
||||||
|
Loading…
Reference in New Issue
Block a user