-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
115 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
{-# LANGUAGE CPP #-} | ||
|
||
#if MIN_VERSION_GLASGOW_HASKELL(8,4,4,0) | ||
{-# OPTIONS_GHC -F -pgmF doctest-discover -optF components/succinct-parser--doctest/config.json #-} | ||
#else | ||
module Main where | ||
|
||
import qualified System.IO as IO | ||
|
||
main :: IO () | ||
main = IO.putStrLn "WARNING: doctest will not run on GHC versions earlier than 8.4.4" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"sourceFolders": ["components/succinct-parser"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{-# OPTIONS_GHC -F -pgmF hspec-discover #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{-# LANGUAGE FunctionalDependencies #-} | ||
{-# LANGUAGE MultiParamTypeClasses #-} | ||
|
||
module HaskellWorks.Data.Parser | ||
( Parser(..) | ||
) where | ||
|
||
import Data.ByteString (ByteString) | ||
import Data.Text (Text) | ||
import Data.Word | ||
import HaskellWorks.Data.Char.IsChar | ||
|
||
import qualified Data.Attoparsec.ByteString as ABS | ||
import qualified Data.Attoparsec.ByteString.Char8 as BC | ||
import qualified Data.Attoparsec.Text as AT | ||
import qualified Data.Attoparsec.Types as T | ||
|
||
class Parser t e | t -> e where | ||
satisfy :: (e -> Bool) -> T.Parser t e | ||
satisfyWith :: (e -> a) -> (a -> Bool) -> T.Parser t a | ||
satisfyChar :: (Char -> Bool) -> T.Parser t Char | ||
string :: t -> T.Parser t t | ||
try :: T.Parser t a -> T.Parser t a | ||
char :: Char -> T.Parser t Char | ||
(<?>) :: T.Parser t Char -> String -> T.Parser t Char | ||
rational :: Fractional f => T.Parser t f | ||
|
||
instance Parser ByteString Word8 where | ||
satisfy = ABS.satisfy | ||
satisfyWith = ABS.satisfyWith | ||
satisfyChar = ABS.satisfyWith toChar | ||
string = ABS.string | ||
try = ABS.try | ||
char = BC.char | ||
(<?>) = (BC.<?>) | ||
rational = BC.rational | ||
{-# INLINE satisfy #-} | ||
{-# INLINE satisfyWith #-} | ||
{-# INLINE satisfyChar #-} | ||
{-# INLINE string #-} | ||
{-# INLINE try #-} | ||
{-# INLINE char #-} | ||
{-# INLINE (<?>) #-} | ||
{-# INLINE rational #-} | ||
|
||
instance Parser Text Char where | ||
satisfy = AT.satisfy | ||
satisfyWith = AT.satisfyWith | ||
satisfyChar = AT.satisfyWith toChar | ||
string = AT.string | ||
try = AT.try | ||
char = AT.char | ||
(<?>) = (AT.<?>) | ||
rational = AT.rational | ||
{-# INLINE satisfy #-} | ||
{-# INLINE satisfyWith #-} | ||
{-# INLINE satisfyChar #-} | ||
{-# INLINE string #-} | ||
{-# INLINE try #-} | ||
{-# INLINE char #-} | ||
{-# INLINE (<?>) #-} | ||
{-# INLINE rational #-} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters