packages feed

language-ecmascript 0.13 → 0.14

raw patch · 5 files changed

+222/−212 lines, 5 files

Files

CHANGELOG view
@@ -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.
language-ecmascript.cabal view
@@ -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 @@ 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 @@   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 this    type: git    location: git://github.com/jswebtools/language-ecmascript.git-   tag: 0.13+   tag: 0.14  Library   Hs-Source-Dirs:
src/Language/ECMAScript3/PrettyPrint.hs view
@@ -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." #-} -class PP a where -  pp :: a -> Doc+-- | 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 PP [Statement a] where -  pp = stmtList +instance Pretty (JavaScript a) where+  prettyPrint (Script _ ss) = prettyPrint ss -instance PP (Expression a) where -  pp = ppExpression True+instance Pretty [Statement a] where +  prettyPrint = vcat . map prettyPrint -instance PP (Statement a) where -  pp = ppStatement+instance Pretty (Expression a) where +  prettyPrint = ppExpression True -instance PP (ForInit a) where -  pp = forInit +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 PP (LValue a) where -  pp = ppLValue +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 PP InfixOp where -  pp = infixOp +instance Pretty (ForInInit a) where+  prettyPrint t = case t of+    ForInVar id  -> text "var" <+> prettyPrint id+    ForInLVal lv -> prettyPrint lv -instance PP AssignOp where -  pp = assignOp+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 PP PrefixOp where -  pp = prefixOp+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" --- | Renders a list of statements as a 'String'+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 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++-- | 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 ('/':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 @@     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 @@ 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 @@ -- 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 @@       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 @@ 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 @@ 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 @@ -- 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 @@ 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
src/Language/ECMAScript3/Syntax/QuasiQuote.hs view
src/PrettyTest.hs view
@@ -3,13 +3,12 @@ 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 @@          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