Safe Haskell | None |
---|---|
Language | Haskell98 |
Debian.Control.TextLazy
Synopsis
- newtype Control' a = Control {
- unControl :: [Paragraph' a]
- newtype Paragraph' a = Paragraph [Field' a]
- data Field' a
- type Control = Control' Text
- type Paragraph = Paragraph' Text
- type Field = Field' Text
- class ControlFunctions a where
- parseControlFromFile :: FilePath -> IO (Either ParseError (Control' a))
- parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' a))
- parseControl :: String -> a -> Either ParseError (Control' a)
- lookupP :: String -> Paragraph' a -> Maybe (Field' a)
- stripWS :: a -> a
- protectFieldText :: a -> a
- asString :: a -> String
- mergeControls :: [Control' a] -> Control' a
- fieldValue :: ControlFunctions a => String -> Paragraph' a -> Maybe a
- removeField :: Eq a => a -> Paragraph' a -> Paragraph' a
- prependFields :: [Field' a] -> Paragraph' a -> Paragraph' a
- appendFields :: [Field' a] -> Paragraph' a -> Paragraph' a
- renameField :: Eq a => a -> a -> Paragraph' a -> Paragraph' a
- modifyField :: Eq a => a -> (a -> a) -> Paragraph' a -> Paragraph' a
- raiseFields :: Eq a => (a -> Bool) -> Paragraph' a -> Paragraph' a
- decodeControl :: Control -> Control
- decodeParagraph :: Paragraph -> Paragraph
- decodeField :: Field' ByteString -> Field' Text
Types
Constructors
Control | |
Fields
|
Instances
Eq a => Eq (Control' a) Source # | |
Ord a => Ord (Control' a) Source # | |
Read a => Read (Control' a) Source # | |
Defined in Debian.Control.Common | |
Show a => Show (Control' a) Source # | |
(ControlFunctions a, Pretty (PP a)) => Pretty (Control' a) Source # | This may have bad performance issues (dsf: Whoever wrote this comment should have explained why.) |
Defined in Debian.Control.Common |
newtype Paragraph' a Source #
Instances
Eq a => Eq (Paragraph' a) Source # | |
Defined in Debian.Control.Common | |
Ord a => Ord (Paragraph' a) Source # | |
Defined in Debian.Control.Common Methods compare :: Paragraph' a -> Paragraph' a -> Ordering (<) :: Paragraph' a -> Paragraph' a -> Bool (<=) :: Paragraph' a -> Paragraph' a -> Bool (>) :: Paragraph' a -> Paragraph' a -> Bool (>=) :: Paragraph' a -> Paragraph' a -> Bool max :: Paragraph' a -> Paragraph' a -> Paragraph' a min :: Paragraph' a -> Paragraph' a -> Paragraph' a | |
Read a => Read (Paragraph' a) Source # | |
Defined in Debian.Control.Common Methods readsPrec :: Int -> ReadS (Paragraph' a) readList :: ReadS [Paragraph' a] readPrec :: ReadPrec (Paragraph' a) readListPrec :: ReadPrec [Paragraph' a] | |
Show a => Show (Paragraph' a) Source # | |
Defined in Debian.Control.Common Methods showsPrec :: Int -> Paragraph' a -> ShowS show :: Paragraph' a -> String showList :: [Paragraph' a] -> ShowS | |
(ControlFunctions a, Pretty (PP a)) => Pretty (Paragraph' a) Source # | |
Defined in Debian.Control.Common |
NOTE: we do not strip the leading or trailing whitespace in the name or value
Instances
Eq a => Eq (Field' a) Source # | |
Ord a => Ord (Field' a) Source # | |
Defined in Debian.Control.Common | |
Read a => Read (Field' a) Source # | |
Defined in Debian.Control.Common | |
Show a => Show (Field' a) Source # | |
(ControlFunctions a, Pretty (PP a)) => Pretty (Field' a) Source # | |
Defined in Debian.Control.Common |
type Paragraph = Paragraph' Text Source #
type Field = Field' Text Source #
parseFromFile p filePath
runs a string parser p
on the
input read from filePath
using readFile
. Returns either a ParseError
(Left
) or a value of type a
(Right
).
main = do{ result <- parseFromFile numbers "digits.txt" ; case result of Left err -> print err Right xs -> print (sum xs) }
class ControlFunctions a where Source #
Methods
parseControlFromFile :: FilePath -> IO (Either ParseError (Control' a)) Source #
parseControlFromFile
filepath
is a simple wrapper function
that parses filepath
using pControl
parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' a)) Source #
parseControlFromHandle
sourceName
handle
- sourceName
is only used for error reporting
parseControl :: String -> a -> Either ParseError (Control' a) Source #
parseControlFromString
sourceName
text
- sourceName
is only used for error reporting
lookupP :: String -> Paragraph' a -> Maybe (Field' a) Source #
lookupP
fieldName paragraph
looks up a Field
in a Paragraph
.
N.B.
trailing and leading whitespace is not stripped.
Strip the trailing and leading space and tab characters from a string. Folded whitespace is not unfolded. This should probably be moved to someplace more general purpose.
protectFieldText :: a -> a Source #
Protect field value text so the parser doesn't split it into multiple fields or paragraphs. This must modify all field text to enforce two conditions: (1) All lines other than the initial one must begin with a space or a tab, and (2) the trailing white space must not contain newlines. This is called before pretty printing to prevent the parser from misinterpreting field text as multiple fields or paragraphs.
Instances
ControlFunctions String Source # | |
Defined in Debian.Control.String Methods parseControlFromFile :: FilePath -> IO (Either ParseError (Control' String)) Source # parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' String)) Source # parseControl :: String -> String -> Either ParseError (Control' String) Source # lookupP :: String -> Paragraph' String -> Maybe (Field' String) Source # stripWS :: String -> String Source # protectFieldText :: String -> String Source # | |
ControlFunctions Builder Source # | |
Defined in Debian.Control.Builder Methods parseControlFromFile :: FilePath -> IO (Either ParseError (Control' Builder)) Source # parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' Builder)) Source # parseControl :: String -> Builder -> Either ParseError (Control' Builder) Source # lookupP :: String -> Paragraph' Builder -> Maybe (Field' Builder) Source # stripWS :: Builder -> Builder Source # protectFieldText :: Builder -> Builder Source # | |
ControlFunctions Text Source # | |
Defined in Debian.Control.TextLazy Methods parseControlFromFile :: FilePath -> IO (Either ParseError (Control' Text)) Source # parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' Text)) Source # parseControl :: String -> Text -> Either ParseError (Control' Text) Source # lookupP :: String -> Paragraph' Text -> Maybe (Field' Text) Source # stripWS :: Text -> Text Source # protectFieldText :: Text -> Text Source # | |
ControlFunctions Text Source # | |
Defined in Debian.Control.Text Methods parseControlFromFile :: FilePath -> IO (Either ParseError (Control' Text)) Source # parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' Text)) Source # parseControl :: String -> Text -> Either ParseError (Control' Text) Source # lookupP :: String -> Paragraph' Text -> Maybe (Field' Text) Source # stripWS :: Text -> Text Source # protectFieldText :: Text -> Text Source # | |
ControlFunctions ByteString Source # | |
Defined in Debian.Control.ByteString Methods parseControlFromFile :: FilePath -> IO (Either ParseError (Control' ByteString)) Source # parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' ByteString)) Source # parseControl :: String -> ByteString -> Either ParseError (Control' ByteString) Source # lookupP :: String -> Paragraph' ByteString -> Maybe (Field' ByteString) Source # stripWS :: ByteString -> ByteString Source # protectFieldText :: ByteString -> ByteString Source # asString :: ByteString -> String Source # |
Control File Parser
Helper Functions
mergeControls :: [Control' a] -> Control' a Source #
fieldValue :: ControlFunctions a => String -> Paragraph' a -> Maybe a Source #
removeField :: Eq a => a -> Paragraph' a -> Paragraph' a Source #
prependFields :: [Field' a] -> Paragraph' a -> Paragraph' a Source #
appendFields :: [Field' a] -> Paragraph' a -> Paragraph' a Source #
renameField :: Eq a => a -> a -> Paragraph' a -> Paragraph' a Source #
modifyField :: Eq a => a -> (a -> a) -> Paragraph' a -> Paragraph' a Source #
raiseFields :: Eq a => (a -> Bool) -> Paragraph' a -> Paragraph' a Source #
Move selected fields to the beginning of a paragraph.
decodeControl :: Control -> Control Source #
decodeParagraph :: Paragraph -> Paragraph Source #
decodeField :: Field' ByteString -> Field' Text Source #
Orphan instances
ControlFunctions Text Source # | |
Methods parseControlFromFile :: FilePath -> IO (Either ParseError (Control' Text)) Source # parseControlFromHandle :: String -> Handle -> IO (Either ParseError (Control' Text)) Source # parseControl :: String -> Text -> Either ParseError (Control' Text) Source # lookupP :: String -> Paragraph' Text -> Maybe (Field' Text) Source # stripWS :: Text -> Text Source # protectFieldText :: Text -> Text Source # |