git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Merge branch 'master' into typeclasses
0828e3dPhil Freeman
README.md+1−1
@@ -34,7 +34,7 @@ See the `LICENSE` file
34
34
35Contributions are always encouraged! Please see `CONTRIBUTING.md` for guidelines.
35Contributions are always encouraged! Please see `CONTRIBUTING.md` for guidelines.
36
36
37−Join the discussion on FreeNode at [irc://irc.freenode.net#purescript](irc://irc.freenode.net#purescript).
37+Join the discussion on FreeNode at <a href="irc://irc.freenode.net/#purescript">#purescript</a>.
38
38
39## Installation
39## Installation
40
40
libraries/jquery/README.mddeleted−7
@@ -1,7 +0,0 @@
1−# JQuery Library
2−
3−A work in progress.
4−
5−To build the test, use
6−
7− psc jquery.purs tests/jquery.purs
libraries/jquery/jquery.purs+15
@@ -28,3 +28,18 @@ module JQuery where
28
28
29 -- Get the document body
29 -- Get the document body
30 foreign import body "function body() { return jQuery(document.body); }" :: forall eff. Eff (dom :: DOM | eff) JQuery
30 foreign import body "function body() { return jQuery(document.body); }" :: forall eff. Eff (dom :: DOM | eff) JQuery
31+
32+ -- Get the text content of an element
33+ foreign import getText "function getText(ob) { return function() { return ob.text(); }; }" :: forall eff. JQuery -> Eff (dom :: DOM | eff) String
34+
35+ -- Set the text content of an element
36+ foreign import setText "function setText(text) { return function(ob) { return function() { ob.text(text); }; }; }" :: forall eff. String -> JQuery -> Eff (dom :: DOM | eff) JQuery
37+
38+ -- Get the value of a text field
39+ foreign import getValue "function getValue(ob) { return function() { return ob.val(); }; }" :: forall eff. JQuery -> Eff (dom :: DOM | eff) String
40+
41+ -- Set the value of a text field
42+ foreign import setValue "function setValue(val) { return function(ob) { return function() { return ob.val(val); }; }; }" :: forall eff. String -> JQuery -> Eff (dom :: DOM | eff) JQuery
43+
44+ -- Register an event handler
45+ foreign import on "function on(evt) { return function(act) { return function(ob) { return function() { return ob.on(evt, function() { act(); } ); }; }; }; }" :: forall eff a. String -> Eff eff a -> JQuery -> Eff (dom :: DOM | eff) JQuery
libraries/jquery/tests/.gitignorenew file+1
@@ -0,0 +1 @@
1+jquery.js
libraries/jquery/tests/build.shnew file+2
@@ -0,0 +1,2 @@
1+psc ../jquery.purs jquery.purs --magic-do --run-main -o jquery.js
2+
libraries/jquery/tests/index.htmlnew file+10
@@ -0,0 +1,10 @@
1+<!DOCTYPE html>
2+<html>
3+<head>
4+<title>JQuery Example</title>
5+<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.10.2/jquery.js"></script>
6+</head>
7+<body>
8+<script src="jquery.js"></script>
9+</body>
10+</html>
libraries/jquery/tests/jquery.purs+19−2
@@ -1,11 +1,28 @@
1module Main where
1module Main where
2
2
3+import Prelude
3import Eff
4import Eff
5+import Trace
4import JQuery
6import JQuery
5
7
6main = eff do
8main = eff do
9+ -- Get the document body
7 b <- body
10 b <- body
11+
12+ -- Create a text box
8 div <- create "<div>"
13 div <- create "<div>"
9− { color: "red" } `css` div
14+ input <- create "<input>"
10− appendText "Hello World" div
15+ "Your Name: " `appendText` div
16+ input `append` div
11 div `append` b
17 div `append` b
18+
19+ -- Create a paragraph to display a greeting
20+ greeting <- create "<p>"
21+ { color: "red" } `css` greeting
22+ greeting `append` b
23+
24+ -- Listen for change events on the text box
25+ flip (on "change") input $ eff do
26+ name <- getValue input
27+ trace $ "Name changed to " ++ name
28+ setText ("Hello, " ++ name) greeting
libraries/prelude/prelude.purs+2
@@ -311,6 +311,8 @@ module Trace where
311
311
312 foreign import trace "function trace(s) { return function() { console.log(s); return {}; }; }" :: forall r. String -> Eff (trace :: Trace | r) {}
312 foreign import trace "function trace(s) { return function() { console.log(s); return {}; }; }" :: forall r. String -> Eff (trace :: Trace | r) {}
313
313
314+ foreign import print "function print(o) { return function() { console.log(JSON.stringify(o)); return {}; }; }" :: forall a r. a -> Eff (trace :: Trace | r) {}
315+
314module ST where
316module ST where
315
317
316 import Eff
318 import Eff
src/Main.hs → psc/Main.hsrenamed

The content is the same.

psci/Main.hsnew file+148
@@ -0,0 +1,148 @@
1+-----------------------------------------------------------------------------
2+--
3+-- Module : Main
4+-- Copyright : (c) Phil Freeman 2013
5+-- License : MIT
6+--
7+-- Maintainer : Phil Freeman <paf31@cantab.net>
8+-- Stability : experimental
9+-- Portability :
10+--
11+-- |
12+--
13+-----------------------------------------------------------------------------
14+
15+{-# LANGUAGE FlexibleContexts #-}
16+
17+module Main where
18+
19+import Control.Monad.IO.Class
20+import Control.Applicative
21+import Control.Monad.Trans.Class
22+
23+import Data.List (nub, isPrefixOf)
24+import Data.Maybe (mapMaybe)
25+
26+import System.Process
27+import System.Console.Haskeline
28+
29+import qualified Language.PureScript as P
30+import qualified Paths_purescript as Paths
31+import qualified System.IO.UTF8 as U (readFile)
32+import qualified Text.Parsec as Parsec (eof)
33+
34+getPreludeFilename :: IO FilePath
35+getPreludeFilename = Paths.getDataFileName "libraries/prelude/prelude.purs"
36+
37+options :: P.Options
38+options = P.Options True False True True
39+
40+completion :: [P.Module] -> CompletionFunc IO
41+completion ms = completeWord Nothing " \t\n\r" findCompletions
42+ where
43+ findCompletions :: String -> IO [Completion]
44+ findCompletions str = do
45+ files <- listFiles str
46+ let names = nub $ [ show qual
47+ | P.Module moduleName ds <- ms
48+ , ident <- mapMaybe getDeclName ds
49+ , qual <- [ P.Qualified Nothing ident
50+ , P.Qualified (Just (P.ModuleName moduleName)) ident]
51+ ]
52+ let matches = filter (isPrefixOf str) names
53+ return $ map simpleCompletion matches ++ files
54+ getDeclName :: P.Declaration -> Maybe P.Ident
55+ getDeclName (P.ValueDeclaration ident _ _ _) = Just ident
56+ getDeclName _ = Nothing
57+
58+createTemporaryModule :: [P.ProperName] -> P.Value -> P.Module
59+createTemporaryModule imports value =
60+ let
61+ moduleName = P.ProperName "Main"
62+ importDecl m = P.ImportDeclaration m Nothing
63+ effModule = P.ModuleName (P.ProperName "Eff")
64+ traceModule = P.ModuleName (P.ProperName "Trace")
65+ effMonad = P.Var (P.Qualified (Just effModule) (P.Ident "eff"))
66+ trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
67+ mainDecl = P.ValueDeclaration (P.Ident "main") [] Nothing
68+ (P.Do effMonad [ P.DoNotationBind (P.VarBinder (P.Ident "it")) value
69+ , P.DoNotationValue (P.App trace [ P.Var (P.Qualified Nothing (P.Ident "it")) ] )
70+ ])
71+ in
72+ P.Module moduleName $ map (importDecl . P.ModuleName) imports ++ [mainDecl]
73+
74+handleDeclaration :: [P.Module] -> [P.ProperName] -> P.Value -> InputT IO ()
75+handleDeclaration loadedModules imports value = do
76+ let m = createTemporaryModule imports value
77+ case P.compile options (loadedModules ++ [m]) of
78+ Left err -> outputStrLn err
79+ Right (js, _, _) -> do
80+ output <- liftIO $ readProcess "nodejs" [] js
81+ outputStrLn output
82+
83+data Command
84+ = Empty
85+ | Expression [String]
86+ | Import String
87+ | LoadModule FilePath
88+ | Reload deriving (Show, Eq)
89+
90+getCommand :: InputT IO Command
91+getCommand = do
92+ firstLine <- getInputLine "> "
93+ case firstLine of
94+ Nothing -> return Empty
95+ Just (':':'i':' ':moduleName) -> return $ Import moduleName
96+ Just (':':'m':' ':modulePath) -> return $ LoadModule modulePath
97+ Just ":r" -> return Reload
98+ Just (':':_) -> outputStrLn "Unknown command" >> getCommand
99+ Just other -> Expression <$> go [other]
100+ where
101+ go ls = do
102+ l <- getInputLine " "
103+ case l of
104+ Nothing -> return $ reverse ls
105+ Just l' -> go (l' : ls)
106+
107+loadModule :: FilePath -> IO (Either String [P.Module])
108+loadModule moduleFile = do
109+ print moduleFile
110+ moduleText <- U.readFile moduleFile
111+ return . either (Left . show) Right $ P.runIndentParser P.parseModules moduleText
112+
113+main :: IO ()
114+main = do
115+ preludeFilename <- getPreludeFilename
116+ (Right prelude) <- loadModule preludeFilename
117+ runInputT (setComplete (completion prelude) defaultSettings) $ do
118+ outputStrLn " ____ ____ _ _ "
119+ outputStrLn "| _ \\ _ _ _ __ ___/ ___| ___ _ __(_)_ __ | |_ "
120+ outputStrLn "| |_) | | | | '__/ _ \\___ \\ / __| '__| | '_ \\| __|"
121+ outputStrLn "| __/| |_| | | | __/___) | (__| | | | |_) | |_ "
122+ outputStrLn "|_| \\__,_|_| \\___|____/ \\___|_| |_| .__/ \\__|"
123+ outputStrLn " |_| "
124+ outputStrLn ""
125+ outputStrLn "Expressions are terminated using Ctrl+D"
126+ go [P.ProperName "Prelude"] prelude
127+ where
128+ go imports loadedModules = do
129+ cmd <- getCommand
130+ case cmd of
131+ Empty -> go imports loadedModules
132+ Expression ls -> do
133+ case P.runIndentParser (P.whiteSpace *> P.parseValue <* Parsec.eof) (unlines ls) of
134+ Left err -> outputStrLn (show err)
135+ Right decl -> handleDeclaration loadedModules imports decl
136+ go imports loadedModules
137+ Import moduleName -> go (imports ++ [P.ProperName moduleName]) loadedModules
138+ LoadModule moduleFile -> do
139+ ms <- lift $ loadModule moduleFile
140+ case ms of
141+ Left err -> outputStrLn err
142+ Right ms' -> go imports (loadedModules ++ ms')
143+ Reload -> do
144+ preludeFilename <- lift getPreludeFilename
145+ (Right prelude) <- lift $ loadModule preludeFilename
146+ go [P.ProperName "Prelude"] prelude
147+
148+
purescript.cabal+13−2
@@ -69,13 +69,24 @@ executable psc
69 directory -any, filepath -any, mtl -any, parsec -any,
69 directory -any, filepath -any, mtl -any, parsec -any,
70 purescript -any, syb -any, transformers -any, utf8-string -any
70 purescript -any, syb -any, transformers -any, utf8-string -any
71 main-is: Main.hs
71 main-is: Main.hs
72+ hs-source-dirs: psc
73+ buildable: True
74+ other-modules:
75+ ghc-options: -Wall -O2 -fno-warn-unused-do-bind
76+
77+executable psci
78+ build-depends: base >=4 && <5, containers -any,
79+ mtl -any, parsec -any, haskeline -any,
80+ purescript -any, syb -any, transformers -any, utf8-string -any,
81+ process -any
82+ main-is: Main.hs
83+ hs-source-dirs: psci
72 buildable: True
84 buildable: True
73− hs-source-dirs: src
74 other-modules:
85 other-modules:
75 ghc-options: -Wall -O2
86 ghc-options: -Wall -O2
76
87
77test-suite tests
88test-suite tests
78− build-depends: base >=4 && <5, cmdtheline -any, containers -any,
89+ build-depends: base >=4 && <5, containers -any,
79 directory -any, filepath -any, mtl -any, parsec -any,
90 directory -any, filepath -any, mtl -any, parsec -any,
80 purescript -any, syb -any, transformers -any, utf8-string -any
91 purescript -any, syb -any, transformers -any, utf8-string -any
81 type: exitcode-stdio-1.0
92 type: exitcode-stdio-1.0
src/Language/PureScript/Parser/Values.hs+2−1
@@ -16,7 +16,8 @@ module Language.PureScript.Parser.Values (
16 parseValue,
16 parseValue,
17 parseGuard,
17 parseGuard,
18 parseBinder,
18 parseBinder,
19− parseBinderNoParens
19+ parseBinderNoParens,
20+ parseDoNotationElement
20) where
21) where
21
22
22import Language.PureScript.Values
23import Language.PureScript.Values