-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/
-- | Scrap Your Reprinter
--
-- A datatype generic algorithm for layout-preserving refactoring
@package reprinter
@version 0.3.0.0
module Text.Reprinter.StringLike
-- | Data types that can be used as a list-like structure of Chars.
--
-- Clumsy solution to allow parameterising over the input type (Text,
-- ByteString, String), rather than converting to and from an internal
-- concrete type. Only operations required by the reprinting algorithm
-- are included. Where possible, operations are prefilled using
-- presumed-existing instances (any [Char]-like should be a
-- monoid and have a String -> a).
class (Monoid a, IsString a) => StringLike a
slCons :: StringLike a => Char -> a -> a
slUncons :: StringLike a => a -> Maybe (Char, a)
slNull :: StringLike a => a -> Bool
slReverse :: StringLike a => a -> a
-- | like unpack
slToString :: StringLike a => a -> String
-- | Class for string-like datastructures; used by the overloaded string
-- extension (-XOverloadedStrings in GHC).
class IsString a
fromString :: IsString a => String -> a
instance (a GHC.Types.~ GHC.Types.Char) => Text.Reprinter.StringLike.StringLike [a]
instance Text.Reprinter.StringLike.StringLike Data.Text.Internal.Text
instance Text.Reprinter.StringLike.StringLike Data.Text.Internal.Lazy.Text
instance Text.Reprinter.StringLike.StringLike Data.ByteString.Internal.ByteString
instance Text.Reprinter.StringLike.StringLike Data.ByteString.Lazy.Internal.ByteString
module Text.Reprinter
-- | Two positions give the lower and upper bounds of a source span
type Span = (Position, Position)
-- | A position in a text (imagine a cursor)
type Position = (Line, Col)
-- | The initial position
initPosition :: Position
-- | Columns start at 1
initCol :: Col
-- | Lines start at 1
initLine :: Line
-- | Smart constructor for a Col, checks that column >= 1
mkCol :: Int -> Either String Col
-- | Smart constructor for a Line, checks that line >= 1
mkLine :: Int -> Either String Line
-- | Given a position, advance by one column
advanceCol :: Position -> Position
-- | Given a position, go down a line, going back to the initial column
advanceLine :: Position -> Position
-- | Specify a refactoring type
data RefactorType
Before :: RefactorType
After :: RefactorType
Replace :: RefactorType
-- | Infrastructure for building the reprinter "plugins"
class Refactorable t
isRefactored :: Refactorable t => t -> Maybe RefactorType
getSpan :: Refactorable t => t -> Span
-- | Type of a reprinting function
--
-- i is the input type (something with a '[Char]'-like
-- interface)
type Reprinting i m = forall node. (Typeable node) => node -> m (Maybe (RefactorType, i, Span))
-- | Catch all generic query
catchAll :: Monad m => a -> m (Maybe b)
-- | Essentially wraps the refactorable interface
genReprinting :: (Monad m, Refactorable t, Typeable t, StringLike i) => (t -> m i) -> t -> m (Maybe (RefactorType, i, Span))
-- | The reprint algorithm takes a refactoring (parameteric in | some monad
-- m) and turns an arbitrary pretty-printable type ast | into a
-- monadic 'StringLike i' transformer.
reprint :: (Monad m, Data ast, StringLike i) => Reprinting i m -> ast -> i -> m i
-- | The reprint algorithm takes a refactoring (parameteric in | some monad
-- m) and turns an arbitrary pretty-printable type ast | into a
-- monadic 'StringLike i' transformer.
reprintSort :: (Monad m, Data ast, StringLike i) => Reprinting i m -> ast -> i -> m i
instance GHC.Show.Show Text.Reprinter.Line
instance GHC.Classes.Ord Text.Reprinter.Line
instance GHC.Classes.Eq Text.Reprinter.Line
instance Data.Data.Data Text.Reprinter.Line
instance GHC.Show.Show Text.Reprinter.Col
instance GHC.Classes.Ord Text.Reprinter.Col
instance GHC.Classes.Eq Text.Reprinter.Col
instance Data.Data.Data Text.Reprinter.Col
instance GHC.Show.Show Text.Reprinter.RefactorType
module Text.Reprinter.Example
type AST a = [Decl a]
data Decl a
Decl :: a -> Span -> String -> Expr a -> Decl a
data Expr a
Plus :: a -> Span -> Expr a -> Expr a -> Expr a
Var :: a -> Span -> String -> Expr a
Const :: a -> Span -> Int -> Expr a
exBasic :: String
exPrettier :: String
exComment :: String
exPaper :: String
refactorZero :: AST Bool -> AST Bool
exprReprinter :: Reprinting String Identity
-- | Print an expression in canonical string form.
prettyExpr :: Expr a -> String
-- | Parse and refactor, then run the reprinter with the original source
-- and updated AST.
refactor :: String -> String
commentPrinter :: Reprinting String (State [(String, Int)])
eval :: Expr a -> State [(String, Int)] (Maybe Int)
refactorComment :: String -> String
parse :: String -> AST Bool
type Parser = State (String, Position)
parseDecl :: Parser (AST Bool)
commentPrefix :: String -> Maybe (String, String)
parseExpr :: Parser (Expr Bool)
getPos :: Parser Position
many :: (Char -> Bool) -> Parser String
spaces :: Parser String
char :: Char -> Parser ()
charP :: Char -> Parser Bool
peekChar :: (Char -> Bool) -> Parser Bool
instance GHC.Show.Show a => GHC.Show.Show (Text.Reprinter.Example.Expr a)
instance Data.Data.Data a => Data.Data.Data (Text.Reprinter.Example.Expr a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Reprinter.Example.Expr a)
instance GHC.Show.Show a => GHC.Show.Show (Text.Reprinter.Example.Decl a)
instance Data.Data.Data a => Data.Data.Data (Text.Reprinter.Example.Decl a)
instance GHC.Classes.Eq a => GHC.Classes.Eq (Text.Reprinter.Example.Decl a)
instance Text.Reprinter.Refactorable (Text.Reprinter.Example.Expr GHC.Types.Bool)