From 158b7486e6d6dad48a9810795bf1e7da420bb8f8 Mon Sep 17 00:00:00 2001 From: Ranjit Jhala Date: Sun, 21 Apr 2013 10:05:25 -0700 Subject: [PATCH] what, where is PP --- src/Language/ECMAScript3/PrettyPrint.hs | 39 ++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Language/ECMAScript3/PrettyPrint.hs b/src/Language/ECMAScript3/PrettyPrint.hs index be82b6b6..7b74dd71 100644 --- a/src/Language/ECMAScript3/PrettyPrint.hs +++ b/src/Language/ECMAScript3/PrettyPrint.hs @@ -1,15 +1,52 @@ --- |Pretty-printing JavaScript. +{-# LANGUAGE FlexibleInstances #-} + +-- | Pretty-printing JavaScript. module Language.ECMAScript3.PrettyPrint ( javaScript , renderStatements , renderExpression + , PP (..) ) where import Text.PrettyPrint.HughesPJ import Language.ECMAScript3.Syntax import Prelude hiding (maybe) +------------------------------------------------------------------------------ + +class PP a where + pp :: a -> Doc + +instance PP [Statement a] where + pp = stmtList + +instance PP (Expression a) where + pp = ppExpression True + +instance PP (Statement a) where + pp = ppStatement + +instance PP (ForInit a) where + pp = forInit + +instance PP (LValue a) where + pp = ppLValue + +instance PP InfixOp where + pp = infixOp + +instance PP AssignOp where + pp = assignOp + +instance PP PrefixOp where + pp = prefixOp + + +---------------------------------------------------------------------------- + + + -- | Renders a list of statements as a 'String' renderStatements :: [Statement a] -> String renderStatements = render . stmtList