@@ -21,9 +21,10 @@ pub fn foo(&self) -> ! { }
21
21
it :: Doc a
22
22
23
23
-}
24
+ {-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
24
25
25
26
module Language.Rust.Pretty (
26
- PrettyAnnotated (.. ), Pretty (.. ), Resolve (.. ), Doc , writeSourceFile
27
+ Pretty (.. ), PrettyAnnotated (.. ), Resolve (.. ), Doc , writeSourceFile
27
28
) where
28
29
29
30
import Language.Rust.Data.Position
@@ -35,19 +36,13 @@ import Language.Rust.Syntax.Ident
35
36
import Language.Rust.Pretty.Internal
36
37
import Language.Rust.Pretty.Resolve
37
38
38
- import Text.PrettyPrint.Annotated.WL (Doc , noAnnotate , text , displayIO , renderPretty )
39
+ import Data.Text.Prettyprint.Doc (Doc , Pretty (.. ), unAnnotate , layoutPretty , LayoutOptions (.. ), PageWidth (.. ))
40
+ import Data.Text.Prettyprint.Doc.Render.Text (renderIO )
39
41
import System.IO (Handle )
40
42
41
43
-- | Given a handle, write into it the given 'SourceFile' (with file width will be 100).
42
44
writeSourceFile :: Handle -> SourceFile a -> IO ()
43
- writeSourceFile hdl = displayIO hdl . renderPretty 1.0 100 . pretty
44
-
45
- -- | Class of things that can be pretty printed (without any annotations). The is very similar to
46
- -- the class defined in 'wl-pprint-annotated' itself. However, in order to avoid having orphan
47
- -- instances or extra instance that don't make sense, we are redefining it.
48
- class Pretty p where
49
- -- | Pretty-print the given value without any annotations.
50
- pretty :: p -> Doc a
45
+ writeSourceFile hdl = renderIO hdl . layoutPretty (LayoutOptions (AvailablePerLine 100 1.0 )) . pretty
51
46
52
47
instance Pretty Abi where pretty = printAbi
53
48
instance Pretty BindingMode where pretty = printBindingMode
@@ -62,40 +57,38 @@ instance Pretty TokenTree where pretty = printTt
62
57
instance Pretty TokenStream where pretty = printTokenStream
63
58
instance Pretty UnOp where pretty = printUnOp
64
59
instance Pretty Unsafety where pretty = printUnsafety
65
- instance Pretty (Attribute a ) where pretty = noAnnotate . prettyAnn
66
- instance Pretty (Block a ) where pretty = noAnnotate . prettyAnn
67
- instance Pretty (SourceFile a ) where pretty = noAnnotate . prettyAnn
68
- instance Pretty (Expr a ) where pretty = noAnnotate . prettyAnn
69
- instance Pretty (Field a ) where pretty = noAnnotate . prettyAnn
70
- instance Pretty (FieldPat a ) where pretty = noAnnotate . prettyAnn
71
- instance Pretty (FnDecl a ) where pretty = noAnnotate . prettyAnn
72
- instance Pretty (ForeignItem a ) where pretty = noAnnotate . prettyAnn
73
- instance Pretty (Generics a ) where pretty = noAnnotate . prettyAnn
74
- instance Pretty (ImplItem a ) where pretty = noAnnotate . prettyAnn
75
- instance Pretty (InlineAsm a ) where pretty = noAnnotate . prettyAnn
76
- instance Pretty (InlineAsmOutput a ) where pretty = noAnnotate . prettyAnn
77
- instance Pretty (Item a ) where pretty = noAnnotate . prettyAnn
78
- instance Pretty (Lifetime a ) where pretty = noAnnotate . prettyAnn
79
- instance Pretty (LifetimeDef a ) where pretty = noAnnotate . prettyAnn
80
- instance Pretty (Lit a ) where pretty = noAnnotate . prettyAnn
81
- instance Pretty (Nonterminal a ) where pretty = noAnnotate . prettyAnn
82
- instance Pretty (Pat a ) where pretty = noAnnotate . prettyAnn
83
- instance Pretty (Path a ) where pretty = noAnnotate . prettyAnn
84
- instance Pretty (PolyTraitRef a ) where pretty = noAnnotate . prettyAnn
85
- instance Pretty (Stmt a ) where pretty = noAnnotate . prettyAnn
86
- instance Pretty (StructField a ) where pretty = noAnnotate . prettyAnn
87
- instance Pretty (TraitItem a ) where pretty = noAnnotate . prettyAnn
88
- instance Pretty (TraitRef a ) where pretty = noAnnotate . prettyAnn
89
- instance Pretty (Ty a ) where pretty = noAnnotate . prettyAnn
90
- instance Pretty (TyParam a ) where pretty = noAnnotate . prettyAnn
91
- instance Pretty (TyParamBound a ) where pretty = noAnnotate . prettyAnn
92
- instance Pretty (Variant a ) where pretty = noAnnotate . prettyAnn
93
- instance Pretty (ViewPath a ) where pretty = noAnnotate . prettyAnn
94
- instance Pretty (Visibility a ) where pretty = noAnnotate . prettyAnn
95
- instance Pretty (WhereClause a ) where pretty = noAnnotate . prettyAnn
96
- instance Pretty (WherePredicate a ) where pretty = noAnnotate . prettyAnn
97
- instance Pretty Position where pretty = text . prettyPosition
98
- instance Pretty Span where pretty = text . prettySpan
60
+ instance Pretty (Attribute a ) where pretty = unAnnotate . prettyAnn
61
+ instance Pretty (Block a ) where pretty = unAnnotate . prettyAnn
62
+ instance Pretty (SourceFile a ) where pretty = unAnnotate . prettyAnn
63
+ instance Pretty (Expr a ) where pretty = unAnnotate . prettyAnn
64
+ instance Pretty (Field a ) where pretty = unAnnotate . prettyAnn
65
+ instance Pretty (FieldPat a ) where pretty = unAnnotate . prettyAnn
66
+ instance Pretty (FnDecl a ) where pretty = unAnnotate . prettyAnn
67
+ instance Pretty (ForeignItem a ) where pretty = unAnnotate . prettyAnn
68
+ instance Pretty (Generics a ) where pretty = unAnnotate . prettyAnn
69
+ instance Pretty (ImplItem a ) where pretty = unAnnotate . prettyAnn
70
+ instance Pretty (Item a ) where pretty = unAnnotate . prettyAnn
71
+ instance Pretty (Lifetime a ) where pretty = unAnnotate . prettyAnn
72
+ instance Pretty (LifetimeDef a ) where pretty = unAnnotate . prettyAnn
73
+ instance Pretty (Lit a ) where pretty = unAnnotate . prettyAnn
74
+ instance Pretty (Nonterminal a ) where pretty = unAnnotate . prettyAnn
75
+ instance Pretty (Pat a ) where pretty = unAnnotate . prettyAnn
76
+ instance Pretty (Path a ) where pretty = unAnnotate . prettyAnn
77
+ instance Pretty (PolyTraitRef a ) where pretty = unAnnotate . prettyAnn
78
+ instance Pretty (Stmt a ) where pretty = unAnnotate . prettyAnn
79
+ instance Pretty (StructField a ) where pretty = unAnnotate . prettyAnn
80
+ instance Pretty (TraitItem a ) where pretty = unAnnotate . prettyAnn
81
+ instance Pretty (TraitRef a ) where pretty = unAnnotate . prettyAnn
82
+ instance Pretty (Ty a ) where pretty = unAnnotate . prettyAnn
83
+ instance Pretty (TyParam a ) where pretty = unAnnotate . prettyAnn
84
+ instance Pretty (TyParamBound a ) where pretty = unAnnotate . prettyAnn
85
+ instance Pretty (Variant a ) where pretty = unAnnotate . prettyAnn
86
+ instance Pretty (ViewPath a ) where pretty = unAnnotate . prettyAnn
87
+ instance Pretty (Visibility a ) where pretty = unAnnotate . prettyAnn
88
+ instance Pretty (WhereClause a ) where pretty = unAnnotate . prettyAnn
89
+ instance Pretty (WherePredicate a ) where pretty = unAnnotate . prettyAnn
90
+ instance Pretty Position where pretty = pretty . prettyPosition
91
+ instance Pretty Span where pretty = pretty . prettySpan
99
92
100
93
-- | Similar to 'Pretty', but for types which are parametrized over an annotation type.
101
94
class PrettyAnnotated p where
@@ -113,8 +106,6 @@ instance PrettyAnnotated FnDecl where prettyAnn = printFnArgsAndRet
113
106
instance PrettyAnnotated ForeignItem where prettyAnn = printForeignItem
114
107
instance PrettyAnnotated Generics where prettyAnn = printGenerics
115
108
instance PrettyAnnotated ImplItem where prettyAnn = printImplItem
116
- instance PrettyAnnotated InlineAsm where prettyAnn = printInlineAsm
117
- instance PrettyAnnotated InlineAsmOutput where prettyAnn = printInlineAsmOutput
118
109
instance PrettyAnnotated Item where prettyAnn = printItem
119
110
instance PrettyAnnotated Lifetime where prettyAnn = printLifetime
120
111
instance PrettyAnnotated LifetimeDef where prettyAnn = printLifetimeDef
0 commit comments