on master help sign in
Prettier printing for infix operator definitions
commit8ffcf9e80ebac239caaa75f7818cbc561b9af987 authorEvan Czaplicki <info@elm-lang.org> dateTue 23 Jul 2013, 15:43 (13 years ago) parent802be96
5 files changed+11−8
compiler/Compiler.hs+2−2 compiler/SourceSyntax/Expression.hs+2−2 compiler/SourceSyntax/Pattern.hs+2−2 compiler/SourceSyntax/PrettyPrint.hs+4−1 compiler/Type/Inference.hs+1−1
compiler/Compiler.hs+2−2
@@ -22,7 +22,7 @@ import Generate.JavaScript (jsModule)
2222import Generate.Html (createHtml, JSStyle(..), JSSource(..))
2323import Paths_Elm
2424
25−import SourceSyntax.PrettyPrint (pretty)
25+import SourceSyntax.PrettyPrint (pretty, variable)
2626import Text.PrettyPrint as P
2727import qualified Type.Type as Type
2828import qualified Parse.Type as Parse
@@ -134,7 +134,7 @@ printTypes metaModule = do
134134 putStrLn ""
135135 forM_ (Map.toList $ types metaModule) $ \(n,t) -> do
136136 pt <- Type.extraPretty t
137− print $ P.text n <+> P.text ":" <+> pt
137+ print $ variable n <+> P.text ":" <+> pt
138138 putStrLn ""
139139
140140getRuntime :: Flags -> IO FilePath
compiler/SourceSyntax/Expression.hs+2−2
@@ -52,7 +52,7 @@ instance Pretty (Expr t v) where
5252 pretty expr =
5353 case expr of
5454 Literal lit -> pretty lit
55− Var x -> parensIf (Help.isOp x) (P.text x)
55+ Var x -> variable x
5656 Range e1 e2 -> P.brackets (pretty e1 <> P.text ".." <> pretty e2)
5757 ExplicitList es -> P.brackets (commaCat (map pretty es))
5858 Binop op e1 e2 -> P.sep [ prettyParens e1 <+> P.text op, prettyParens e2 ]
@@ -99,7 +99,7 @@ instance Pretty (Def t v) where
9999 pretty def =
100100 case def of
101101 TypeAnnotation name tipe ->
102− P.text name <+> P.text ":" <+> pretty tipe
102+ variable name <+> P.text ":" <+> pretty tipe
103103 Def pattern expr ->
104104 pretty pattern <+> P.text "=" <+> pretty expr
105105
compiler/SourceSyntax/Pattern.hs+2−2
@@ -3,7 +3,7 @@ module SourceSyntax.Pattern where
33
44import Data.List (intercalate)
55import Data.Data
6−import SourceSyntax.Helpers
6+import SourceSyntax.Helpers as Help
77import SourceSyntax.PrettyPrint
88import Text.PrettyPrint as PP
99import SourceSyntax.Literal as Literal
@@ -25,7 +25,7 @@ tuple es = PData ("_Tuple" ++ show (length es)) es
2525instance Pretty Pattern where
2626 pretty pattern =
2727 case pattern of
28− PVar x -> PP.text x
28+ PVar x -> variable x
2929 PLiteral lit -> pretty lit
3030 PRecord fs -> PP.braces (commaCat $ map PP.text fs)
3131 PAlias x p -> prettyParens p <+> PP.text "as" <+> PP.text x
compiler/SourceSyntax/PrettyPrint.hs+4−1
@@ -3,6 +3,7 @@ module SourceSyntax.PrettyPrint where
33
44import Text.PrettyPrint
55import SourceSyntax.Location
6+import qualified SourceSyntax.Helpers as Help
67
78class Pretty a where
89 pretty :: a -> Doc
@@ -16,4 +17,6 @@ instance Pretty () where
1617commaCat docs = cat (punctuate comma docs)
1718commaSep docs = sep (punctuate comma docs)
1819
19−parensIf bool doc = if bool then parens doc else doc
20+parensIf bool doc = if bool then parens doc else doc
21+
22+variable x = parensIf (Help.isOp x) (text x)
compiler/Type/Inference.hs+1−1
@@ -56,7 +56,7 @@ infer interfaces' modul = unsafePerformIO $ do
5656 environ = T.CLet [ T.Scheme vars [] T.CTrue header ]
5757
5858 constraint <- environ `fmap` TcExpr.constrain env (program modul) (T.VarN var)
59− print =<< T.extraPretty constraint
59+ --print =<< T.extraPretty constraint
6060
6161 state <- execStateT (Solve.solve constraint) TS.initialState
6262 let errors = TS.sErrors state