Skip to content

Commit d9e57d9

Browse files
committed
Merge pull request #8 from UCSD-PL/pp
Adding a PP class for exposing pretty printers...
2 parents 20a2304 + 158b748 commit d9e57d9

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

src/Language/ECMAScript3/PrettyPrint.hs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,52 @@
1-
-- |Pretty-printing JavaScript.
1+
{-# LANGUAGE FlexibleInstances #-}
2+
3+
-- | Pretty-printing JavaScript.
24
module Language.ECMAScript3.PrettyPrint
35
(
46
javaScript
57
, renderStatements
68
, renderExpression
9+
, PP (..)
710
) where
811

912
import Text.PrettyPrint.HughesPJ
1013
import Language.ECMAScript3.Syntax
1114
import Prelude hiding (maybe)
1215

16+
------------------------------------------------------------------------------
17+
18+
class PP a where
19+
pp :: a -> Doc
20+
21+
instance PP [Statement a] where
22+
pp = stmtList
23+
24+
instance PP (Expression a) where
25+
pp = ppExpression True
26+
27+
instance PP (Statement a) where
28+
pp = ppStatement
29+
30+
instance PP (ForInit a) where
31+
pp = forInit
32+
33+
instance PP (LValue a) where
34+
pp = ppLValue
35+
36+
instance PP InfixOp where
37+
pp = infixOp
38+
39+
instance PP AssignOp where
40+
pp = assignOp
41+
42+
instance PP PrefixOp where
43+
pp = prefixOp
44+
45+
46+
----------------------------------------------------------------------------
47+
48+
49+
1350
-- | Renders a list of statements as a 'String'
1451
renderStatements :: [Statement a] -> String
1552
renderStatements = render . stmtList

0 commit comments

Comments
 (0)