-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | A modern parser combinator library with convenient diagnostics -- -- A modern parser combinator library with slicing and Clang-style -- colored diagnostics @package trifecta @version 1.4.3 -- | Fast zero based arrays, based on the implementation in the HAMT-branch -- of unordered-containers module Text.Trifecta.Util.Array data Array a data MArray s a -- | Create a new mutable array of specified size, in the specified state -- thread, with each element containing the specified initial value. new :: Int -> a -> ST s (MArray s a) new_ :: Int -> ST s (MArray s a) empty :: Array a singleton :: a -> Array a length :: Array a -> Int lengthM :: MArray s a -> Int read :: MArray s a -> Int -> ST s a write :: MArray s a -> Int -> a -> ST s () index :: Array a -> Int -> a index_ :: Array a -> Int -> ST s a indexM_ :: MArray s a -> Int -> ST s a -- | O(n) Update the element at the given position in this array. update :: Array e -> Int -> e -> Array e -- | O(n) Insert an element at the given position in this array, -- increasing its size by one. insert :: Array e -> Int -> e -> Array e -- | O(n) Delete an element at the given position in this array, -- decreasing its size by one. delete :: Array e -> Int -> Array e unsafeFreeze :: MArray s a -> ST s (Array a) run :: (forall s. ST s (MArray s e)) -> Array e run2 :: (forall s. ST s (MArray s e, a)) -> (Array e, a) -- | Unsafely copy the elements of an array. Array bounds are not checked. copy :: Array e -> Int -> MArray s e -> Int -> Int -> ST s () -- | Unsafely copy the elements of an array. Array bounds are not checked. copyM :: MArray s e -> Int -> MArray s e -> Int -> Int -> ST s () foldl' :: (b -> a -> b) -> b -> Array a -> b foldr :: (a -> b -> b) -> b -> Array a -> b thaw :: Array e -> Int -> Int -> ST s (MArray s e) map :: (a -> b) -> Array a -> Array b -- | Strict version of map. map' :: (a -> b) -> Array a -> Array b traverse :: Applicative f => (a -> f b) -> Array a -> f (Array b) filter :: (a -> Bool) -> Array a -> Array a instance NFData a => NFData (Array a) -- | Interval maps implemented using the FingerTree type, following -- section 4.8 of -- --
-- In file included from baz.c:9
-- In file included from bar.c:4
-- foo.c:8:36: note
-- int main(int argc, char ** argv) { int; }
-- ^
--
data Caret
Caret :: !Delta -> {-# UNPACK #-} !ByteString -> Caret
class HasCaret t
caret :: HasCaret t => Lens' t Caret
data Careted a
(:^) :: a -> Caret -> Careted a
drawCaret :: Delta -> Delta -> Lines -> Lines
addCaret :: Delta -> Rendering -> Rendering
caretEffects :: [SGR]
renderingCaret :: Delta -> ByteString -> Rendering
data Span
Span :: !Delta -> !Delta -> {-# UNPACK #-} !ByteString -> Span
class HasSpan t
span :: HasSpan t => Lens' t Span
data Spanned a
(:~) :: a -> Span -> Spanned a
spanEffects :: [SGR]
drawSpan :: Delta -> Delta -> Delta -> Lines -> Lines
-- |
-- int main(int argc, char ** argv) { int; }
-- ^~~
--
addSpan :: Delta -> Delta -> Rendering -> Rendering
data Fixit
Fixit :: {-# UNPACK #-} !Span -> !ByteString -> Fixit
_fixitSpan :: Fixit -> {-# UNPACK #-} !Span
_fixitReplacement :: Fixit -> !ByteString
class HasFixit t_awjl where fixitReplacement = (fixit . go_awjn) where go_awjn _f_awjo (Fixit __fixitSpan_awjp __fixitReplacement'_awjq) = ((\ __fixitReplacement_awjr -> Fixit __fixitSpan_awjp __fixitReplacement_awjr) <$> (_f_awjo __fixitReplacement'_awjq)) fixitSpan = (fixit . go_awjs) where go_awjs _f_awjt (Fixit __fixitSpan'_awju __fixitReplacement_awjw) = ((\ __fixitSpan_awjv -> Fixit __fixitSpan_awjv __fixitReplacement_awjw) <$> (_f_awjt __fixitSpan'_awju))
fixit :: HasFixit t_awjl => Lens' t_awjl Fixit
fixitReplacement :: HasFixit t_awjl => Lens' t_awjl ByteString
fixitSpan :: HasFixit t_awjl => Lens' t_awjl Span
drawFixit :: Delta -> Delta -> String -> Delta -> Lines -> Lines
addFixit :: Delta -> Delta -> String -> Rendering -> Rendering
type Lines = Array (Int, Int64) ([SGR], Char)
draw :: [SGR] -> Int -> Int64 -> String -> Lines -> Lines
ifNear :: Delta -> (Lines -> Lines) -> Delta -> Lines -> Lines
(.#) :: (Delta -> Lines -> Lines) -> Rendering -> Rendering
instance Renderable Fixit
instance Reducer Fixit Rendering
instance Hashable Fixit
instance HasSpan Fixit
instance HasFixit Fixit
instance Typeable Caret
instance Typeable1 Careted
instance Typeable Span
instance Typeable1 Spanned
instance Typeable Fixit
instance Show a => Show (Rendered a)
instance Eq Caret
instance Ord Caret
instance Show Caret
instance Data Caret
instance Generic Caret
instance Eq a => Eq (Careted a)
instance Ord a => Ord (Careted a)
instance Show a => Show (Careted a)
instance Data a => Data (Careted a)
instance Generic (Careted a)
instance Eq Span
instance Ord Span
instance Show Span
instance Data Span
instance Generic Span
instance Eq a => Eq (Spanned a)
instance Ord a => Ord (Spanned a)
instance Show a => Show (Spanned a)
instance Data a => Data (Spanned a)
instance Generic (Spanned a)
instance Eq Fixit
instance Ord Fixit
instance Show Fixit
instance Data Fixit
instance Generic Fixit
instance Datatype D1Caret
instance Constructor C1_0Caret
instance Datatype D1Careted
instance Constructor C1_0Careted
instance Datatype D1Span
instance Constructor C1_0Span
instance Datatype D1Spanned
instance Constructor C1_0Spanned
instance Datatype D1Fixit
instance Constructor C1_0Fixit
instance Selector S1_0_0Fixit
instance Selector S1_0_1Fixit
instance Hashable a => Hashable (Spanned a)
instance Renderable (Spanned a)
instance Reducer (Spanned a) Rendering
instance Traversable Spanned
instance Foldable Spanned
instance ComonadApply Spanned
instance Comonad Spanned
instance Functor Spanned
instance HasSpan (Spanned a)
instance Hashable Span
instance Reducer Span Rendering
instance Semigroup Span
instance Renderable Span
instance HasSpan Span
instance Hashable a => Hashable (Careted a)
instance Reducer (Careted a) Rendering
instance Renderable (Careted a)
instance Traversable Careted
instance Foldable Careted
instance ComonadApply Careted
instance Comonad Careted
instance HasBytes (Careted a)
instance HasDelta (Careted a)
instance Functor Careted
instance HasCaret (Careted a)
instance Semigroup Caret
instance Reducer Caret Rendering
instance Renderable Caret
instance HasDelta Caret
instance HasBytes Caret
instance Hashable Caret
instance HasCaret Caret
instance Renderable (Rendered a)
instance Traversable Rendered
instance Foldable Rendered
instance ComonadApply Rendered
instance Comonad Rendered
instance HasBytes (Rendered a)
instance HasDelta (Rendered a)
instance Functor Rendered
instance Pretty Rendering
instance Source ByteString
instance Source String
instance Renderable Rendering
instance HasDelta Rendering
instance Monoid Rendering
instance Semigroup Rendering
instance Show Rendering
instance HasRendering Rendering
module Text.Trifecta.Combinators
-- | This class provides parsers with easy access to:
--
-- 1) the current line contents. 2) the current position as a
-- Delta. 3) the ability to use sliced on any parser.
class (MonadPlus m, TokenParsing m) => DeltaParsing m where rend = rendered <$> position <*> line restOfLine = drop . fromIntegral . columnByte <$> position <*> line
line :: DeltaParsing m => m ByteString
position :: DeltaParsing m => m Delta
slicedWith :: DeltaParsing m => (a -> ByteString -> r) -> m a -> m r
rend :: (DeltaParsing m, DeltaParsing m) => m Rendering
restOfLine :: (DeltaParsing m, DeltaParsing m) => m ByteString
-- | Run a parser, grabbing all of the text between its start and end
-- points and discarding the original result
sliced :: DeltaParsing m => m a -> m ByteString
-- | Grab a Caret pointing to the current location.
careting :: DeltaParsing m => m Caret
-- | Parse a Careted result. Pointing the Caret to where you
-- start.
careted :: DeltaParsing m => m a -> m (Careted a)
-- | Discard the result of a parse, returning a Span from where we
-- start to where it ended parsing.
spanning :: DeltaParsing m => m a -> m Span
-- | Parse a Spanned result. The Span starts here and runs to
-- the last position parsed.
spanned :: DeltaParsing m => m a -> m (Spanned a)
-- | Grab a fixit.
fixiting :: DeltaParsing m => m ByteString -> m Fixit
-- | This class is a refinement of DeltaParsing that adds the
-- ability to mark your position in the input and return there for
-- further parsing later.
class (DeltaParsing m, HasDelta d) => MarkParsing d m | m -> d
mark :: MarkParsing d m => m d
release :: MarkParsing d m => d -> m ()
instance (MonadPlus m, MarkParsing d m) => MarkParsing d (IdentityT m)
instance (MonadPlus m, MarkParsing d m, Monoid w, Show s, Show w) => MarkParsing d (RWST r w s m)
instance (MonadPlus m, MarkParsing d m, Monoid w, Show s, Show w) => MarkParsing d (RWST r w s m)
instance (MonadPlus m, MarkParsing d m, Monoid w, Show w) => MarkParsing d (WriterT w m)
instance (MonadPlus m, MarkParsing d m, Monoid w, Show w) => MarkParsing d (WriterT w m)
instance (MonadPlus m, MarkParsing d m) => MarkParsing d (ReaderT e m)
instance (MonadPlus m, MarkParsing d m, Show s) => MarkParsing d (StateT s m)
instance (MonadPlus m, MarkParsing d m, Show s) => MarkParsing d (StateT s m)
instance (MonadPlus m, DeltaParsing m) => DeltaParsing (IdentityT m)
instance (MonadPlus m, DeltaParsing m, Monoid w, Show s, Show w) => DeltaParsing (RWST r w s m)
instance (MonadPlus m, DeltaParsing m, Monoid w, Show s, Show w) => DeltaParsing (RWST r w s m)
instance (MonadPlus m, DeltaParsing m, Monoid w, Show w) => DeltaParsing (WriterT w m)
instance (MonadPlus m, DeltaParsing m, Monoid w, Show w) => DeltaParsing (WriterT w m)
instance (MonadPlus m, DeltaParsing m) => DeltaParsing (ReaderT e m)
instance (MonadPlus m, DeltaParsing m, Show s) => DeltaParsing (StateT s m)
instance (MonadPlus m, DeltaParsing m, Show s) => DeltaParsing (StateT s m)
-- | Results and Parse Errors
module Text.Trifecta.Result
-- | The result of parsing. Either we succeeded or something went wrong.
data Result a
Success :: a -> Result a
Failure :: Doc -> Result a
-- | A Prism that lets you embed or retrieve a Result in a
-- potentially larger type.
class AsResult s t a b | s -> a, t -> b, s b -> t, t a -> s
_Result :: AsResult s t a b => Prism s t (Result a) (Result b)
-- | The Prism for the Success constructor of Result
_Success :: AsResult s t a b => Prism s t a b
-- | The Prism for the Failure constructor of Result
_Failure :: AsResult s s a a => Prism' s Doc
-- | This is used to report an error. What went wrong, some supplemental
-- docs and a set of things expected at the current location. This does
-- not, however, include the actual location.
data Err
Err :: Maybe Doc -> [Doc] -> Set String -> Err
_reason :: Err -> Maybe Doc
_footnotes :: Err -> [Doc]
_expected :: Err -> Set String
class HasErr t_a14R5 where expected = (err . go_a14R7) where go_a14R7 _f_a14R8 (Err __reason_a14R9 __footnotes_a14Ra __expected'_a14Rb) = ((\ __expected_a14Rc -> Err __reason_a14R9 __footnotes_a14Ra __expected_a14Rc) <$> (_f_a14R8 __expected'_a14Rb)) footnotes = (err . go_a14Rd) where go_a14Rd _f_a14Re (Err __reason_a14Rf __footnotes'_a14Rg __expected_a14Ri) = ((\ __footnotes_a14Rh -> Err __reason_a14Rf __footnotes_a14Rh __expected_a14Ri) <$> (_f_a14Re __footnotes'_a14Rg)) reason = (err . go_a14Rj) where go_a14Rj _f_a14Rk (Err __reason'_a14Rl __footnotes_a14Rn __expected_a14Ro) = ((\ __reason_a14Rm -> Err __reason_a14Rm __footnotes_a14Rn __expected_a14Ro) <$> (_f_a14Rk __reason'_a14Rl))
err :: HasErr t_a14R5 => Lens' t_a14R5 Err
expected :: HasErr t_a14R5 => Lens' t_a14R5 (Set String)
footnotes :: HasErr t_a14R5 => Lens' t_a14R5 [Doc]
reason :: HasErr t_a14R5 => Lens' t_a14R5 (Maybe Doc)
class Errable m
raiseErr :: Errable m => Err -> m a
-- | Convert a location and an Err into a Doc
explain :: Rendering -> Err -> Doc
-- | Generate a simple Err word-wrapping the supplied message.
failed :: String -> Err
instance Show a => Show (Result a)
instance Functor Result
instance Foldable Result
instance Traversable Result
instance Alternative Result
instance Applicative Result
instance Show a => Pretty (Result a)
instance AsResult (Result a) (Result b) a b
instance Monoid Err
instance Semigroup Err
instance HasErr Err
module Text.Trifecta.Parser
newtype Parser a
Parser :: (forall r. (a -> Err -> It Rope r) -> (Err -> It Rope r) -> (a -> Set String -> Delta -> ByteString -> It Rope r) -> (Doc -> It Rope r) -> Delta -> ByteString -> It Rope r) -> Parser a
unparser :: Parser a -> forall r. (a -> Err -> It Rope r) -> (Err -> It Rope r) -> (a -> Set String -> Delta -> ByteString -> It Rope r) -> (Doc -> It Rope r) -> Delta -> ByteString -> It Rope r
manyAccum :: (a -> [a] -> [a]) -> Parser a -> Parser [a]
data Step a
StepDone :: !Rope -> a -> Step a
StepFail :: !Rope -> Doc -> Step a
StepCont :: !Rope -> (Result a) -> (Rope -> Step a) -> Step a
feed :: Reducer t Rope => t -> Step r -> Step r
starve :: Step a -> Result a
stepParser :: Parser a -> Delta -> ByteString -> Step a
stepResult :: Rope -> Result a -> Step a
stepIt :: It Rope a -> Step a
-- | parseFromFile p filePath runs a parser p on the
-- input read from filePath using readFile. All
-- diagnostic messages emitted over the course of the parse attempt are
-- shown to the user on the console.
--
-- -- main = do -- result <- parseFromFile numbers "digits.txt" -- case result of -- Nothing -> return () -- Just a -> print $ sum a --parseFromFile :: MonadIO m => Parser a -> String -> m (Maybe a) -- | parseFromFileEx p filePath runs a parser p on the -- input read from filePath using readFile. Returns all -- diagnostic messages emitted over the course of the parse and the -- answer if the parse was successful. -- --
-- main = do -- result <- parseFromFileEx (many number) "digits.txt" -- case result of -- Failure xs -> displayLn xs -- Success a -> print (sum a) --parseFromFileEx :: MonadIO m => Parser a -> String -> m (Result a) parseString :: Parser a -> Delta -> String -> Result a -- | parseByteString p delta i runs a parser p on -- i. parseByteString :: Parser a -> Delta -> ByteString -> Result a parseTest :: (MonadIO m, Show a) => Parser a -> String -> m () instance Functor Step instance Show a => Show (Step a) instance MarkParsing Delta Parser instance DeltaParsing Parser instance TokenParsing Parser instance CharParsing Parser instance LookAheadParsing Parser instance Errable Parser instance Parsing Parser instance MonadPlus Parser instance Monad Parser instance Monoid a => Monoid (Parser a) instance Semigroup a => Semigroup (Parser a) instance Alternative Parser instance Applicative Parser instance Functor Parser module Text.Trifecta