Permalink
Browse files

updates

  • Loading branch information...
1 parent dbcc8b6 commit 70e44665816e851b5d4c4e918516a8371ff412e2 Arjun Guha committed Apr 11, 2009
View
@@ -21,7 +21,7 @@ Library
src
Build-Depends:
base>=4, mtl>=1.1.0.1, parsec<3.0.0, pretty>=0.1, containers>=0.1, syb>=0.1,
- WebBits>=0.13.0, filepath, directory
+ WebBits>=0.14.0, filepath, directory
ghc-options:
-fwarn-incomplete-patterns
Extensions:
@@ -17,8 +17,7 @@ import BrownPLT.JavaScript.Parser (ParsedExpression, ParsedStatement,
parseJavaScriptFromFile, parseScriptFromString )
import BrownPLT.JavaScript.Environment (env)
import BrownPLT.JavaScript.Syntax
-import BrownPLT.JavaScript.PrettyPrint ()
-import BrownPLT.Common (pp)
+import BrownPLT.JavaScript.PrettyPrint (renderStatements)
import BrownPLT.JavaScript.Contracts.Types
import BrownPLT.JavaScript.Contracts.Parser
import BrownPLT.JavaScript.Contracts.Template
@@ -188,31 +187,30 @@ compileRelease :: String -- ^implementation
-> Maybe String -- ^the namespace name
-> String -- ^encapsulated implementation
compileRelease rawImpl implSource boilerplate interface namespace =
- libraryHeader ++ (concat $ map (render.pp) $ escapeGlobals impl exportNames)
+ libraryHeader ++ (renderStatements $ escapeGlobals impl exportNames)
++ rawImpl ++ exposeStatements ++ "\n}).apply(impl,[]);\n"
++ exportStatements ++ namespaceStatements ++ "\n})();" where
impl = case parseScriptFromString implSource rawImpl of
Left err -> error (show err)
Right (Script _ stmts) -> stmts
exports = filter isInterfaceExport interface
- exportStatements = render $ vcat $
- map (pp.exportRelease) exports
+ exportStatements = renderStatements (map exportRelease exports)
exportNames = [n | InterfaceExport n _ _ <- exports ]
instanceNames =
[n | InterfaceInstance n _ _ <- filter isInterfaceInstance interface]
- exposeStatements = render $ vcat $
- map pp (exposeImplementation (exportNames ++ instanceNames))
+ exposeStatements = renderStatements
+ (exposeImplementation (exportNames ++ instanceNames))
namespaceStatements = case namespace of
Nothing -> ""
- Just s -> render $ vcat $ map pp $ exportNamespace s
+ Just s -> renderStatements (exportNamespace s)
compileFormatted :: String -- ^implementation
-> String -- ^implementation source
-> String -- ^contract library
-> [InterfaceItem] -- ^the interface
-> String -- ^encapsulated implementation
compileFormatted rawImpl implSource boilerplate interface =
- libraryHeader ++ (concat $ map (render.pp) $ escapeGlobals impl exportNames)
+ libraryHeader ++ (renderStatements $ escapeGlobals impl exportNames)
++ rawImpl
++ exposeStatements ++ "\n}).apply(impl,[]);\n" ++ boilerplate
++ interfaceStatements
@@ -222,16 +220,16 @@ compileFormatted rawImpl implSource boilerplate interface =
Left err -> error (show err)
Right (Script _ stmts) -> stmts
exports = filter isInterfaceExport interface
- exportStatements = render.vcat $
- concatMap (map pp.makeExportStatements) interface
+ exportStatements =
+ renderStatements (concatMap makeExportStatements interface)
exportNames = [n | InterfaceExport n _ _ <- exports ]
aliases = filter isInterfaceAlias interface
- aliasStatements = concatMap (render.pp) $ compileAliases interface
+ aliasStatements = renderStatements (compileAliases interface)
instanceNames =
[n | InterfaceInstance n _ _ <- filter isInterfaceInstance interface]
- exposeStatements = concatMap (render.pp) $
+ exposeStatements = renderStatements $
exposeImplementation (exportNames ++ instanceNames)
- interfaceStatements = render.vcat $ map (pp.interfaceStatement) $
+ interfaceStatements = renderStatements $ map interfaceStatement $
filter isInterfaceStatement interface
compile' :: [ParsedStatement] -> [InterfaceItem] -> IO ParsedStatement
@@ -20,12 +20,11 @@ import Data.Generics
import Text.ParserCombinators.Parsec (parse, many1)
import Text.ParserCombinators.Parsec.Pos (initialPos, SourcePos)
import Text.PrettyPrint.HughesPJ (render)
-import BrownPLT.JavaScript.PrettyPrint ()
-import BrownPLT.Common (pp)
+import BrownPLT.JavaScript.PrettyPrint (renderExpression, renderStatements)
import BrownPLT.JavaScript.Parser
import BrownPLT.JavaScript.Syntax
import BrownPLT.JavaScript.Instances()
-
+import BrownPLT.JavaScript.Crawl() -- hack for instance
noPos :: SourcePos
noPos = initialPos "template"
@@ -52,8 +51,8 @@ stmtTemplate str = case parse (many1 parseStatement) "statement template" str of
Right stmts -> StatementTemplate stmts
renderTemplate :: JavaScriptTemplate -> String
-renderTemplate (ExpressionTemplate expr) = render (pp expr)
-renderTemplate (StatementTemplate stmts) = concatMap (render . pp) stmts
+renderTemplate (ExpressionTemplate expr) = renderExpression expr
+renderTemplate (StatementTemplate stmts) = renderStatements stmts
templateExpression :: JavaScriptTemplate -> ParsedExpression
templateExpression (ExpressionTemplate expr) = expr
View
@@ -7,13 +7,9 @@ import System.Directory
import System.FilePath
import System.Exit
import Control.Monad
-
import BrownPLT.JavaScript.Contracts
import Paths_JsContracts -- created by Cabal
-
-import BrownPLT.Common ( pp )
-import BrownPLT.JavaScript.Parser ( parseJavaScriptFromFile )
-import Text.PrettyPrint.HughesPJ ( render )
+import BrownPLT.JavaScript.Parser (parseJavaScriptFromFile)
data Flag
= Help
View
@@ -14,10 +14,8 @@ import BrownPLT.JavaScript.Contracts.Compiler
import BrownPLT.JavaScript.Contracts.Template
import BrownPLT.JavaScript.Contracts.Parser
-import BrownPLT.Common ( pp )
-import BrownPLT.JavaScript.Parser ( parseJavaScriptFromFile )
-
-import Text.PrettyPrint.HughesPJ ( render )
+import BrownPLT.JavaScript.Parser (parseJavaScriptFromFile)
+import BrownPLT.JavaScript.PrettyPrint (renderStatements)
expandTests :: String -> String
expandTests testSuite = renderTemplate
@@ -34,7 +32,8 @@ testExecution implPath interactionsJs = do
iface <- parseInterface (implPath ++ "i")
impl' <- compile' impl iface
interactions <- readFile interactionsJs
- let js = "window = {};\n" ++ (render $ pp $ impl') ++ expandTests interactions
+ let js = "window = {};\n" ++ (renderStatements [impl']) ++
+ expandTests interactions
code <- rawSystem "java" ["org.mozilla.javascript.tools.shell.Main","-e",js]
case code of
ExitSuccess -> return ()

0 comments on commit 70e4466

Please sign in to comment.