summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreyChudnov <>2013-05-30 19:24:23 (GMT)
committerhdiff <hdiff@hdiff.luite.com>2013-05-30 19:24:23 (GMT)
commit567b6e04b347fa81c7e12bc20dbab47fd8aa4dc9 (patch)
treec82c3a983df472804639b87156315832e2c70f3b
parentbf8a839d0b3c8dc4ab77bc37c8edecf9ed4a4651 (diff)
version 0.140.14
-rw-r--r--CHANGELOG9
-rw-r--r--language-ecmascript.cabal10
-rw-r--r--src/Language/ECMAScript3/PrettyPrint.hs428
-rw-r--r--src/Language/ECMAScript3/Syntax/QuasiQuote.hs2
-rw-r--r--src/PrettyTest.hs9
5 files changed, 234 insertions, 224 deletions
diff --git a/CHANGELOG b/CHANGELOG
index a4f0798..302b931 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,5 +1,14 @@
Version change log.
+=0.14=
+Refactoring of the pretty-printing module: added class Pretty with a more
+comprehensive coverage of AST datatypes and better documentation. Removed
+duplicate code and deprecated all old interfaces (everything except class
+Pretty). Old interfaces would be removed in 1.0 (still a long way out).
+
+=0.13=
+Added class PP for pretty-printing
+
=0.12=
Added a 'setAnnotation' function to the 'HasAnnotation' class. Added
a 'withAnnotation' helper function to modify the top level annotation.
diff --git a/language-ecmascript.cabal b/language-ecmascript.cabal
index b0814b5..20e02a7 100644
--- a/language-ecmascript.cabal
+++ b/language-ecmascript.cabal
@@ -1,5 +1,5 @@
Name: language-ecmascript
-Version: 0.13
+Version: 0.14
Cabal-Version: >= 1.10
Copyright: (c) 2007-2012 Brown University, (c) 2008-2010 Claudiu Saftoiu,
(c) 2012-2013 Stevens Institute of Technology
@@ -11,7 +11,7 @@ Maintainer: Andrey Chudnov <oss@chudnov.com>
Homepage: http://github.com/jswebtools/language-ecmascript
Bug-reports: http://github.com/jswebtools/language-ecmascript/issues
Stability: experimental
-Tested-with: GHC==7.4.1
+Tested-with: GHC==7.4.1, GHC==7.6.3
Extra-Source-Files: tests/parse-pretty/*.js, CHANGELOG
Category: Language
Build-Type: Simple
@@ -21,8 +21,6 @@ Description:
Includes a parser, pretty-printer, and basic building blocks for more
sophisticated tools.
- This package supercedes package WebBits.
-
Source-repository head
type: git
location: git://github.com/jswebtools/language-ecmascript.git
@@ -30,7 +28,7 @@ Source-repository head
Source-repository this
type: git
location: git://github.com/jswebtools/language-ecmascript.git
- tag: 0.13
+ tag: 0.14
Library
Hs-Source-Dirs:
@@ -108,4 +106,4 @@ Test-Suite prettytest
Default-Extensions: DeriveDataTypeable, ScopedTypeVariables, DeriveFunctor, DeriveFoldable, DeriveTraversable, FlexibleContexts
Default-Language: Haskell2010
ghc-options:
- -fwarn-incomplete-patterns
+ -fwarn-incomplete-patterns \ No newline at end of file
diff --git a/src/Language/ECMAScript3/PrettyPrint.hs b/src/Language/ECMAScript3/PrettyPrint.hs
index 7b74dd7..21470b5 100644
--- a/src/Language/ECMAScript3/PrettyPrint.hs
+++ b/src/Language/ECMAScript3/PrettyPrint.hs
@@ -1,204 +1,216 @@
-{-# LANGUAGE FlexibleInstances #-}
+{-# LANGUAGE FlexibleInstances, UndecidableInstances #-}
-- | Pretty-printing JavaScript.
-module Language.ECMAScript3.PrettyPrint
- (
- javaScript
- , renderStatements
- , renderExpression
- , PP (..)
- ) where
+module Language.ECMAScript3.PrettyPrint (Pretty (..)
+ ,javaScript
+ ,renderStatements
+ ,renderExpression
+ ,PP (..)
+ ) where
import Text.PrettyPrint.HughesPJ
import Language.ECMAScript3.Syntax
-import Prelude hiding (maybe)
-
-------------------------------------------------------------------------------
+import Prelude hiding (maybe, id)
+
+{-# DEPRECATED PP, javaScript, renderStatements, renderExpression "These interfaces are outdated and would be removed/hidden in version 1.0. Use the Pretty class instead." #-}
+
+-- | A class of pretty-printable ECMAScript AST nodes.
+class Pretty a where
+ -- | Pretty-print an ECMAScript AST node. Use 'render' or 'show' to
+ -- convert 'Doc' to 'String'.
+ prettyPrint :: a -> Doc
+
+instance Pretty (JavaScript a) where
+ prettyPrint (Script _ ss) = prettyPrint ss
+
+instance Pretty [Statement a] where
+ prettyPrint = vcat . map prettyPrint
+
+instance Pretty (Expression a) where
+ prettyPrint = ppExpression True
+
+instance Pretty (Statement a) where
+ prettyPrint s = case s of
+ BlockStmt _ ss -> asBlock ss
+ EmptyStmt _ -> semi
+ ExprStmt _ e@(CallExpr _ (FuncExpr {}) _ ) ->
+ parens (ppExpression True e) <> semi
+ ExprStmt _ e -> ppExpression True e <> semi
+ IfSingleStmt _ test cons -> text "if" <+>
+ parens (ppExpression True test) $$
+ prettyPrint cons
+ IfStmt _ test cons alt -> text "if" <+> parens (ppExpression True test) $$
+ prettyPrint cons $$ text "else"
+ <+> prettyPrint alt
+ SwitchStmt _ e cases ->
+ text "switch" <+> parens (ppExpression True e) $$
+ braces (nest 2 (vcat (map prettyPrint cases)))
+ WhileStmt _ test body -> text "while" <+> parens (ppExpression True test)
+ $$ prettyPrint body
+ ReturnStmt _ Nothing -> text "return"
+ ReturnStmt _ (Just e) -> text "return" <+> ppExpression True e
+ DoWhileStmt _ s e ->
+ text "do" $$
+ (prettyPrint s <+> text "while" <+> parens (ppExpression True e)
+ <> semi)
+ BreakStmt _ Nothing -> text "break" <> semi
+ BreakStmt _ (Just label) -> text "break" <+> prettyPrint label <> semi
+ ContinueStmt _ Nothing -> text "continue" <> semi
+ ContinueStmt _ (Just label) -> text"continue" <+> prettyPrint label
+ <> semi
+ LabelledStmt _ label s -> prettyPrint label <> colon $$ prettyPrint s
+ ForInStmt p init e body ->
+ text "for" <+>
+ parens (prettyPrint init <+> text "in" <+> ppExpression True e) $+$
+ prettyPrint body
+ ForStmt _ init incr test body ->
+ text "for" <+>
+ parens (prettyPrint init <> semi <+> maybe incr (ppExpression True) <>
+ semi <+> maybe test (ppExpression True)) $$
+ prettyPrint body
+ TryStmt _ stmt mcatch mfinally ->
+ text "try" $$ inBlock stmt $$ ppCatch $$ ppFinally
+ where ppFinally = case mfinally of
+ Nothing -> empty
+ Just stmt -> text "finally" <> inBlock stmt
+ ppCatch = case mcatch of
+ Nothing -> empty
+ Just (CatchClause _ id s) ->
+ text "catch" <+> (parens.prettyPrint) id <+> inBlock s
+ ThrowStmt _ e -> text "throw" <+> ppExpression True e <> semi
+ WithStmt _ e s -> text "with" <+> parens (ppExpression True e)
+ $$ prettyPrint s
+ VarDeclStmt _ decls ->
+ text "var" <+> cat (punctuate comma (map (ppVarDecl True) decls))
+ <> semi
+ FunctionStmt _ name args body ->
+ text "function" <+> prettyPrint name <>
+ parens (cat $ punctuate comma (map prettyPrint args)) $$
+ asBlock body
+
+instance Pretty (ForInit a) where
+ prettyPrint t = case t of
+ NoInit -> empty
+ VarInit vs -> text "var"
+ <+> cat (punctuate comma $ map (ppVarDecl False) vs)
+ ExprInit e -> ppExpression False e
+
+instance Pretty (ForInInit a) where
+ prettyPrint t = case t of
+ ForInVar id -> text "var" <+> prettyPrint id
+ ForInLVal lv -> prettyPrint lv
+
+instance Pretty (LValue a) where
+ prettyPrint lv = case lv of
+ LVar _ x -> text x
+ LDot _ e x -> ppMemberExpression e <> text "." <> text x
+ LBracket _ e1 e2 -> ppMemberExpression e1 <>
+ brackets (ppExpression True e2)
+
+instance Pretty (VarDecl a) where
+ prettyPrint = ppVarDecl True
+
+instance Pretty (CaseClause a) where
+ prettyPrint c = case c of
+ CaseClause _ e ss ->
+ text "case" $+$ ppExpression True e <+> colon $$ nest 2 (prettyPrint ss)
+ CaseDefault _ ss -> text "default:" $$ nest 2 (prettyPrint ss)
+
+instance Pretty InfixOp where
+ prettyPrint op = text $ case op of
+ OpMul -> "*"
+ OpDiv -> "/"
+ OpMod -> "%"
+ OpAdd -> "+"
+ OpSub -> "-"
+ OpLShift -> "<<"
+ OpSpRShift -> ">>"
+ OpZfRShift -> ">>>"
+ OpLT -> "<"
+ OpLEq -> "<="
+ OpGT -> ">"
+ OpGEq -> ">="
+ OpIn -> "in"
+ OpInstanceof -> "instanceof"
+ OpEq -> "=="
+ OpNEq -> "!="
+ OpStrictEq -> "==="
+ OpStrictNEq -> "!=="
+ OpBAnd -> "&"
+ OpBXor -> "^"
+ OpBOr -> "|"
+ OpLAnd -> "&&"
+ OpLOr -> "||"
+
+instance Pretty AssignOp where
+ prettyPrint op = text $ case op of
+ OpAssign -> "="
+ OpAssignAdd -> "+="
+ OpAssignSub -> "-="
+ OpAssignMul -> "*="
+ OpAssignDiv -> "/="
+ OpAssignMod -> "%="
+ OpAssignLShift -> "<<="
+ OpAssignSpRShift -> ">>="
+ OpAssignZfRShift -> ">>>="
+ OpAssignBAnd -> "&="
+ OpAssignBXor -> "^="
+ OpAssignBOr -> "|="
+
+instance Pretty PrefixOp where
+ prettyPrint op = text $ case op of
+ PrefixLNot -> "!"
+ PrefixBNot -> "~"
+ PrefixPlus -> "+"
+ PrefixMinus -> "-"
+ PrefixTypeof -> "typeof"
+ PrefixVoid -> "void"
+ PrefixDelete -> "delete"
+
+instance Pretty (Prop a) where
+ prettyPrint p = case p of
+ PropId _ id -> prettyPrint id
+ PropString _ str -> doubleQuotes (text (jsEscape str))
+ PropNum _ n -> text (show n)
+
+instance Pretty (Id a) where
+ prettyPrint (Id _ str) = text str
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
-
-
-----------------------------------------------------------------------------
-
+instance Pretty a => PP a where
+ pp = prettyPrint
+-- | DEPRECATED: Use 'prettyPrint' instead! Renders a JavaScript
+-- program as a document, the show instance of 'Doc' will pretty-print
+-- it automatically
+javaScript :: JavaScript a -> Doc
+javaScript = prettyPrint
--- | Renders a list of statements as a 'String'
+-- | DEPRECATED: Use 'prettyPrint' instead! Renders a list of
+-- statements as a 'String'
renderStatements :: [Statement a] -> String
-renderStatements = render . stmtList
+renderStatements = render . prettyPrint
--- | Renders a list of statements as a 'String'
+-- | DEPRECATED: Use 'prettyPrint' instead! Renders a list of
+-- statements as a 'String'
renderExpression :: Expression a -> String
-renderExpression = render . (ppExpression True)
+renderExpression = render . prettyPrint
-- Displays the statement in { ... }, unless it is a block itself.
inBlock:: Statement a -> Doc
-inBlock s@(BlockStmt _ _) = ppStatement s
+inBlock s@(BlockStmt _ _) = prettyPrint s
inBlock s = asBlock [s]
asBlock :: [Statement a] -> Doc
-asBlock ss = lbrace $+$ nest 2 (stmtList ss) $$ rbrace
-
-ppId (Id _ str) = text str
-
-forInit :: ForInit a -> Doc
-forInit t = case t of
- NoInit -> empty
- VarInit vs -> text "var" <+> cat (punctuate comma $ map (ppVarDecl False) vs)
- ExprInit e -> ppExpression False e
-
-forInInit :: ForInInit a -> Doc
-forInInit t = case t of
- ForInVar id -> text "var" <+> ppId id
- ForInLVal lv -> ppLValue lv
-
-caseClause :: CaseClause a -> Doc
-caseClause (CaseClause _ e ss) =
- text "case" $+$ ppExpression True e <+> colon $$ nest 2 (stmtList ss)
-caseClause (CaseDefault _ ss) =
- text "default:" $$ nest 2 (stmtList ss)
+asBlock ss = lbrace $+$ nest 2 (prettyPrint ss) $$ rbrace
ppVarDecl :: Bool -> VarDecl a -> Doc
ppVarDecl hasIn vd = case vd of
- VarDecl _ id Nothing -> ppId id
- VarDecl _ id (Just e) -> ppId id <+> equals <+> ppAssignmentExpression hasIn e
-
-ppStatement :: Statement a -> Doc
-ppStatement s = case s of
- BlockStmt _ ss -> asBlock ss
- EmptyStmt _ -> semi
- ExprStmt _ e@(CallExpr _ (FuncExpr {}) _ ) ->
- parens (ppExpression True e) <> semi
- ExprStmt _ e -> ppExpression True e <> semi
- IfSingleStmt _ test cons -> text "if" <+>
- parens (ppExpression True test) $$
- ppStatement cons
- IfStmt _ test cons alt -> text "if" <+> parens (ppExpression True test) $$
- ppStatement cons $$ text "else" <+> ppStatement alt
- SwitchStmt _ e cases ->
- text "switch" <+> parens (ppExpression True e) $$
- braces (nest 2 (vcat (map caseClause cases)))
- WhileStmt _ test body -> text "while" <+> parens (ppExpression True test) $$
- ppStatement body
- ReturnStmt _ Nothing -> text "return"
- ReturnStmt _ (Just e) -> text "return" <+> ppExpression True e
- DoWhileStmt _ s e ->
- text "do" $$
- (ppStatement s <+> text "while" <+> parens (ppExpression True e) <> semi)
- BreakStmt _ Nothing -> text "break" <> semi
- BreakStmt _ (Just label) -> text "break" <+> ppId label <> semi
- ContinueStmt _ Nothing -> text "continue" <> semi
- ContinueStmt _ (Just label) -> text"continue" <+> ppId label <> semi
- LabelledStmt _ label s -> ppId label <> colon $$ ppStatement s
- ForInStmt p init e body ->
- text "for" <+>
- parens (forInInit init <+> text "in" <+> ppExpression True e) $+$
- ppStatement body
- ForStmt _ init incr test body ->
- text "for" <+>
- parens (forInit init <> semi <+> maybe incr (ppExpression True) <>
- semi <+> maybe test (ppExpression True)) $$
- ppStatement body
- TryStmt _ stmt mcatch mfinally ->
- text "try" $$ inBlock stmt $$ ppCatch $$ ppFinally
- where ppFinally = case mfinally of
- Nothing -> empty
- Just stmt -> text "finally" <> inBlock stmt
- ppCatch = case mcatch of
- Nothing -> empty
- Just (CatchClause _ id s) ->
- text "catch" <+> (parens.ppId) id <+> inBlock s
- ThrowStmt _ e -> text "throw" <+> ppExpression True e <> semi
- WithStmt _ e s -> text "with" <+> parens (ppExpression True e) $$ ppStatement s
- VarDeclStmt _ decls ->
- text "var" <+> cat (punctuate comma (map (ppVarDecl True) decls)) <> semi
- FunctionStmt _ name args body ->
- text "function" <+> ppId name <>
- parens (cat $ punctuate comma (map ppId args)) $$
- asBlock body
-
-stmtList :: [Statement a] -> Doc
-stmtList = vcat . map ppStatement
-
-prop :: Prop a -> Doc
-prop p = case p of
- PropId _ id -> ppId id
- PropString _ str -> doubleQuotes (text (jsEscape str))
- PropNum _ n -> text (show n)
-
-infixOp op = text $ case op of
- OpMul -> "*"
- OpDiv -> "/"
- OpMod -> "%"
- OpAdd -> "+"
- OpSub -> "-"
- OpLShift -> "<<"
- OpSpRShift -> ">>"
- OpZfRShift -> ">>>"
- OpLT -> "<"
- OpLEq -> "<="
- OpGT -> ">"
- OpGEq -> ">="
- OpIn -> "in"
- OpInstanceof -> "instanceof"
- OpEq -> "=="
- OpNEq -> "!="
- OpStrictEq -> "==="
- OpStrictNEq -> "!=="
- OpBAnd -> "&"
- OpBXor -> "^"
- OpBOr -> "|"
- OpLAnd -> "&&"
- OpLOr -> "||"
-
-
-prefixOp op = text $ case op of
- PrefixLNot -> "!"
- PrefixBNot -> "~"
- PrefixPlus -> "+"
- PrefixMinus -> "-"
- PrefixTypeof -> "typeof"
- PrefixVoid -> "void"
- PrefixDelete -> "delete"
-
-
-assignOp op = text $ case op of
- OpAssign -> "="
- OpAssignAdd -> "+="
- OpAssignSub -> "-="
- OpAssignMul -> "*="
- OpAssignDiv -> "/="
- OpAssignMod -> "%="
- OpAssignLShift -> "<<="
- OpAssignSpRShift -> ">>="
- OpAssignZfRShift -> ">>>="
- OpAssignBAnd -> "&="
- OpAssignBXor -> "^="
- OpAssignBOr -> "|="
+ VarDecl _ id Nothing -> prettyPrint id
+ VarDecl _ id (Just e) -> prettyPrint id <+> equals
+ <+> ppAssignmentExpression hasIn e
-- Based on:
-- http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Literals
@@ -224,17 +236,11 @@ regexpEscape ('\\':c:rest) = '\\':c:(regexpEscape rest)
regexpEscape ('/':rest) = '\\':'/':regexpEscape rest
regexpEscape (c:rest) = c:regexpEscape rest
-ppLValue :: LValue a -> Doc
-ppLValue (LVar _ x) = text x
-ppLValue (LDot _ e x) = ppMemberExpression e <> text "." <> text x
-ppLValue (LBracket _ e1 e2) = ppMemberExpression e1 <>
- brackets (ppExpression True e2)
-
-- 11.1
ppPrimaryExpression :: Expression a -> Doc
ppPrimaryExpression e = case e of
ThisRef _ -> text "this"
- VarRef _ id -> ppId id
+ VarRef _ id -> prettyPrint id
NullLit _ -> text "null"
BoolLit _ True -> text "true"
BoolLit _ False -> text "false"
@@ -248,17 +254,17 @@ ppPrimaryExpression e = case e of
brackets $ cat $ punctuate comma (map (ppAssignmentExpression True) es)
ObjectLit _ xs ->
braces (hsep (punctuate comma (map pp' xs))) where
- pp' (n,v) = prop n <> colon <+> ppAssignmentExpression True v
+ pp' (n,v) = prettyPrint n <> colon <+> ppAssignmentExpression True v
_ -> parens $ ppExpression True e
-- 11.2
ppMemberExpression :: Expression a -> Doc
ppMemberExpression e = case e of
FuncExpr _ name params body ->
- text "function" <+> maybe name ppId <+>
- parens (cat $ punctuate comma (map ppId params)) $$
+ text "function" <+> maybe name prettyPrint <+>
+ parens (cat $ punctuate comma (map prettyPrint params)) $$
asBlock body
- DotRef _ obj id -> ppMemberExpression obj <> text "." <> ppId id
+ DotRef _ obj id -> ppMemberExpression obj <> text "." <> prettyPrint id
BracketRef _ obj key ->
ppMemberExpression obj <> brackets (ppExpression True key)
NewExpr _ ctor args ->
@@ -268,8 +274,9 @@ ppMemberExpression e = case e of
ppCallExpression :: Expression a -> Doc
ppCallExpression e = case e of
CallExpr _ f args -> ppCallExpression f <> ppArguments args
- DotRef _ obj id -> ppCallExpression obj <> text "." <> ppId id
- BracketRef _ obj key ->ppCallExpression obj <> brackets (ppExpression True key)
+ DotRef _ obj id -> ppCallExpression obj <> text "." <> prettyPrint id
+ BracketRef _ obj key -> ppCallExpression obj
+ <> brackets (ppExpression True key)
_ -> ppMemberExpression e
ppArguments :: [Expression a] -> Doc
@@ -282,37 +289,38 @@ ppLHSExpression = ppCallExpression
-- 11.3
ppPostfixExpression :: Expression a -> Doc
ppPostfixExpression e = case e of
- UnaryAssignExpr _ PostfixInc e' -> ppLValue e' <> text "++"
- UnaryAssignExpr _ PostfixDec e' -> ppLValue e' <> text "--"
+ UnaryAssignExpr _ PostfixInc e' -> prettyPrint e' <> text "++"
+ UnaryAssignExpr _ PostfixDec e' -> prettyPrint e' <> text "--"
_ -> ppLHSExpression e
-- 11.4
ppUnaryExpression :: Expression a -> Doc
ppUnaryExpression e = case e of
- PrefixExpr _ op e' -> prefixOp op <+> ppUnaryExpression e'
- UnaryAssignExpr _ PrefixInc e' -> text "++" <> ppLValue e'
- UnaryAssignExpr _ PrefixDec e' -> text "--" <> ppLValue e'
+ PrefixExpr _ op e' -> prettyPrint op <+> ppUnaryExpression e'
+ UnaryAssignExpr _ PrefixInc e' -> text "++" <> prettyPrint e'
+ UnaryAssignExpr _ PrefixDec e' -> text "--" <> prettyPrint e'
_ -> ppPostfixExpression e
-- 11.5
ppMultiplicativeExpression :: Expression a -> Doc
ppMultiplicativeExpression e = case e of
InfixExpr _ op e1 e2 | op `elem` [OpMul, OpDiv, OpMod] ->
- ppMultiplicativeExpression e1 <+> infixOp op <+> ppUnaryExpression e2
+ ppMultiplicativeExpression e1 <+> prettyPrint op <+> ppUnaryExpression e2
_ -> ppUnaryExpression e
-- 11.6
ppAdditiveExpression :: Expression a -> Doc
ppAdditiveExpression e = case e of
InfixExpr _ op e1 e2 | op `elem` [OpAdd, OpSub] ->
- ppAdditiveExpression e1 <+> infixOp op <+> ppMultiplicativeExpression e2
+ ppAdditiveExpression e1 <+> prettyPrint op
+ <+> ppMultiplicativeExpression e2
_ -> ppMultiplicativeExpression e
-- 11.7
ppShiftExpression :: Expression a -> Doc
ppShiftExpression e = case e of
InfixExpr _ op e1 e2 | op `elem` [OpLShift, OpSpRShift, OpZfRShift] ->
- ppShiftExpression e1 <+> infixOp op <+> ppAdditiveExpression e2
+ ppShiftExpression e1 <+> prettyPrint op <+> ppAdditiveExpression e2
_ -> ppAdditiveExpression e
-- 11.8.
@@ -324,14 +332,15 @@ ppRelationalExpression hasIn e =
ops = if hasIn then OpIn:opsNoIn else opsNoIn
in case e of
InfixExpr _ op e1 e2 | op `elem` ops ->
- ppRelationalExpression hasIn e1 <+> infixOp op <+> ppShiftExpression e2
+ ppRelationalExpression hasIn e1 <+> prettyPrint op
+ <+> ppShiftExpression e2
_ -> ppShiftExpression e
-- 11.9
ppEqualityExpression :: Bool -> Expression a -> Doc
ppEqualityExpression hasIn e = case e of
InfixExpr _ op e1 e2 | op `elem` [OpEq, OpNEq, OpStrictEq, OpStrictNEq] ->
- ppEqualityExpression hasIn e1 <+> infixOp op <+>
+ ppEqualityExpression hasIn e1 <+> prettyPrint op <+>
ppRelationalExpression hasIn e2
_ -> ppRelationalExpression hasIn e
@@ -339,21 +348,21 @@ ppEqualityExpression hasIn e = case e of
ppBitwiseANDExpression :: Bool -> Expression a -> Doc
ppBitwiseANDExpression hasIn e = case e of
InfixExpr _ op@OpBAnd e1 e2 -> ppBitwiseANDExpression hasIn e1 <+>
- infixOp op <+>
+ prettyPrint op <+>
ppEqualityExpression hasIn e2
_ -> ppEqualityExpression hasIn e
ppBitwiseXORExpression :: Bool -> Expression a -> Doc
ppBitwiseXORExpression hasIn e = case e of
InfixExpr _ op@OpBXor e1 e2 -> ppBitwiseXORExpression hasIn e1 <+>
- infixOp op <+>
+ prettyPrint op <+>
ppBitwiseANDExpression hasIn e2
_ -> ppBitwiseANDExpression hasIn e
ppBitwiseORExpression :: Bool -> Expression a -> Doc
ppBitwiseORExpression hasIn e = case e of
InfixExpr _ op@OpBOr e1 e2 -> ppBitwiseORExpression hasIn e1 <+>
- infixOp op <+>
+ prettyPrint op <+>
ppBitwiseXORExpression hasIn e2
_ -> ppBitwiseXORExpression hasIn e
@@ -361,14 +370,14 @@ ppBitwiseORExpression hasIn e = case e of
ppLogicalANDExpression :: Bool -> Expression a -> Doc
ppLogicalANDExpression hasIn e = case e of
InfixExpr _ op@OpLAnd e1 e2 -> ppLogicalANDExpression hasIn e1 <+>
- infixOp op <+>
+ prettyPrint op <+>
ppBitwiseORExpression hasIn e2
_ -> ppBitwiseORExpression hasIn e
ppLogicalORExpression :: Bool -> Expression a -> Doc
ppLogicalORExpression hasIn e = case e of
InfixExpr _ op@OpLOr e1 e2 -> ppLogicalORExpression hasIn e1 <+>
- infixOp op <+>
+ prettyPrint op <+>
ppLogicalANDExpression hasIn e2
_ -> ppLogicalANDExpression hasIn e
@@ -383,7 +392,7 @@ ppConditionalExpression hasIn e = case e of
-- 11.13
ppAssignmentExpression :: Bool -> Expression a -> Doc
ppAssignmentExpression hasIn e = case e of
- AssignExpr _ op l r -> ppLValue l <+> assignOp op <+>
+ AssignExpr _ op l r -> prettyPrint l <+> prettyPrint op <+>
ppAssignmentExpression hasIn r
_ -> ppConditionalExpression hasIn e
@@ -396,8 +405,3 @@ ppExpression hasIn e = case e of
maybe :: Maybe a -> (a -> Doc) -> Doc
maybe Nothing _ = empty
maybe (Just a) f = f a
-
--- | Renders a JavaScript program as a document, the show instance of
--- 'Doc' will pretty-print it automatically
-javaScript :: JavaScript a -> Doc
-javaScript (Script _ ss) = stmtList ss
diff --git a/src/Language/ECMAScript3/Syntax/QuasiQuote.hs b/src/Language/ECMAScript3/Syntax/QuasiQuote.hs
index 6c17f4a..410f5b2 100644
--- a/src/Language/ECMAScript3/Syntax/QuasiQuote.hs
+++ b/src/Language/ECMAScript3/Syntax/QuasiQuote.hs
@@ -42,4 +42,4 @@ quoteCommon p s = do loc <- TH.location
case parse p2 "" s of
Left err -> do TH.report True $ show err
return $ TH.UnboxedTupE []
- Right x -> dataToExpQ (const Nothing) x \ No newline at end of file
+ Right x -> dataToExpQ (const Nothing) x
diff --git a/src/PrettyTest.hs b/src/PrettyTest.hs
index ffd9c59..933ec70 100644
--- a/src/PrettyTest.hs
+++ b/src/PrettyTest.hs
@@ -3,13 +3,12 @@ module Main where
import Language.ECMAScript3.Parser
import Language.ECMAScript3.PrettyPrint
import Language.ECMAScript3.Syntax
-import Language.ECMAScript3.Syntax.Arbitrary
+import Language.ECMAScript3.Syntax.Arbitrary()
import Language.ECMAScript3.Syntax.Annotations
import Test.QuickCheck
import System.Exit
-
-
+main :: IO ()
main =
let qcArgs = Args {maxSuccess = 50
,maxDiscardRatio = 10
@@ -25,6 +24,6 @@ main =
prettyParseEquivalence :: JavaScript () -> Bool
prettyParseEquivalence js =
- case parseScriptFromString "" $ show $ javaScript js of
+ case parseScriptFromString "" $ show $ prettyPrint js of
Left _ -> False
- Right parsed -> (reannotate (const ()) parsed) == js \ No newline at end of file
+ Right parsed -> (reannotate (const ()) parsed) == js