Skip to content

Commit 845e631

Browse files
committed
Change to 'prettyprinter', remove 'InlineAsm'
Move pretty printing facility to 'prettyprinter' library. Remove 'InlineAsm' since we have no good way of parsing it, we don't represent it properly, and we don't support 'GlobalAsm'. This is tracked in #24.
1 parent 0459efc commit 845e631

File tree

10 files changed

+263
-292
lines changed

10 files changed

+263
-292
lines changed

language-rust.cabal

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ library
4949
Language.Rust.Parser.Reversed
5050
Language.Rust.Pretty.Resolve
5151
Language.Rust.Pretty.Literals
52+
Language.Rust.Pretty.Util
5253
Language.Rust.Syntax.AST
5354
Language.Rust.Syntax.Ident
5455
Language.Rust.Syntax.Token
@@ -62,7 +63,7 @@ library
6263
, DeriveFunctor
6364

6465
build-depends: base >=4.9 && <5.0
65-
, wl-pprint-annotated >=0.1.0.0 && <0.2.0.0
66+
, prettyprinter >=1.1
6667
, transformers >=0.5 && <0.6
6768
, array >=0.5 && <0.6
6869
, deepseq >=1.4.2.0
@@ -89,7 +90,7 @@ test-suite unit-tests
8990
default-language: Haskell2010
9091
build-depends: base >=4.9 && <5.0
9192
, HUnit >=1.5.0.0
92-
, wl-pprint-annotated >=0.1.0.0 && <0.2.0.0
93+
, prettyprinter >=1.1
9394
, test-framework >=0.8.0
9495
, test-framework-hunit >= 0.3.0
9596
, language-rust

src/Language/Rust/Parser/Internal.y

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1736,7 +1736,6 @@ addAttrs as (AddrOf as' m e s) = AddrOf (as ++ as') m e s
17361736
addAttrs as (Break as' l e s) = Break (as ++ as') l e s
17371737
addAttrs as (Continue as' l s) = Continue (as ++ as') l s
17381738
addAttrs as (Ret as' e s) = Ret (as ++ as') e s
1739-
addAttrs as (InlineAsmExpr as' a s) = InlineAsmExpr (as ++ as') a s
17401739
addAttrs as (MacExpr as' m s) = MacExpr (as ++ as') m s
17411740
addAttrs as (Struct as' p f e a) = Struct (as ++ as') p f e a
17421741
addAttrs as (Repeat as' e1 e2 s) = Repeat (as ++ as') e1 e2 s

src/Language/Rust/Pretty.hs

Lines changed: 37 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ pub fn foo(&self) -> ! { }
2121
it :: Doc a
2222
2323
-}
24+
{-# OPTIONS_GHC -Wall -fno-warn-orphans #-}
2425

2526
module Language.Rust.Pretty (
26-
PrettyAnnotated(..), Pretty(..), Resolve(..), Doc, writeSourceFile
27+
Pretty(..), PrettyAnnotated(..), Resolve(..), Doc, writeSourceFile
2728
) where
2829

2930
import Language.Rust.Data.Position
@@ -35,19 +36,13 @@ import Language.Rust.Syntax.Ident
3536
import Language.Rust.Pretty.Internal
3637
import Language.Rust.Pretty.Resolve
3738

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)
3941
import System.IO (Handle)
4042

4143
-- | Given a handle, write into it the given 'SourceFile' (with file width will be 100).
4244
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
5146

5247
instance Pretty Abi where pretty = printAbi
5348
instance Pretty BindingMode where pretty = printBindingMode
@@ -62,40 +57,38 @@ instance Pretty TokenTree where pretty = printTt
6257
instance Pretty TokenStream where pretty = printTokenStream
6358
instance Pretty UnOp where pretty = printUnOp
6459
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
9992

10093
-- | Similar to 'Pretty', but for types which are parametrized over an annotation type.
10194
class PrettyAnnotated p where
@@ -113,8 +106,6 @@ instance PrettyAnnotated FnDecl where prettyAnn = printFnArgsAndRet
113106
instance PrettyAnnotated ForeignItem where prettyAnn = printForeignItem
114107
instance PrettyAnnotated Generics where prettyAnn = printGenerics
115108
instance PrettyAnnotated ImplItem where prettyAnn = printImplItem
116-
instance PrettyAnnotated InlineAsm where prettyAnn = printInlineAsm
117-
instance PrettyAnnotated InlineAsmOutput where prettyAnn = printInlineAsmOutput
118109
instance PrettyAnnotated Item where prettyAnn = printItem
119110
instance PrettyAnnotated Lifetime where prettyAnn = printLifetime
120111
instance PrettyAnnotated LifetimeDef where prettyAnn = printLifetimeDef

0 commit comments

Comments
 (0)