Skip to content

Adding a PP class for exposing pretty printers... #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 24, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion src/Language/ECMAScript3/PrettyPrint.hs
Original file line number Diff line number Diff line change
@@ -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
Expand Down