git.iko.soy/rowtype-yoga/purescript-native
on golang help sign in
Handle lets properly
commit3d954fe6264cd0f73e157db7a3e3989dd12882aa authorjoneshf <jones3.hardy@gmail.com> dateWed 19 Feb 2014, 10:59 (13 years ago) parent7c19115
1 file changed+8−14
psci/Main.hs+8−14
psci/Main.hs+8−14
@@ -39,7 +39,7 @@ import qualified Paths_purescript as Paths
3939import qualified System.IO.UTF8 as U (readFile)
4040import qualified Text.Parsec as Parsec (Parsec, eof)
4141
42−data PSCI = PSCI [P.ProperName] [P.Module] [P.DoNotationElement]
42+data PSCI = PSCI [P.ProperName] [P.Module] [P.Value -> P.Value]
4343
4444-- State helpers
4545inputTToState :: InputT IO a -> StateT PSCI (InputT IO) a
@@ -54,7 +54,7 @@ updateImports name (PSCI i m b) = PSCI (i ++ [P.ProperName name]) m b
5454updateModules :: [P.Module] -> PSCI -> PSCI
5555updateModules modules (PSCI i m b) = PSCI i (m ++ modules) b
5656
57−updateBinders :: P.DoNotationElement -> PSCI -> PSCI
57+updateBinders :: (P.Value -> P.Value) -> PSCI -> PSCI
5858updateBinders name (PSCI i m b) = PSCI i m (b ++ [name])
5959
6060-- File helpers
@@ -121,18 +121,15 @@ completion ms = completeWord Nothing " \t\n\r" findCompletions
121121options :: P.Options
122122options = P.Options True False True (Just "Main") True "PS" []
123123
124−createTemporaryModule :: [P.ProperName] -> [P.DoNotationElement] -> P.Value -> P.Module
124+createTemporaryModule :: [P.ProperName] -> [P.Value -> P.Value] -> P.Value -> P.Module
125125createTemporaryModule imports binders value =
126126 let
127127 moduleName = P.ModuleName [P.ProperName "Main"]
128128 importDecl m = P.ImportDeclaration m Nothing
129129 traceModule = P.ModuleName [P.ProperName "Trace"]
130130 trace = P.Var (P.Qualified (Just traceModule) (P.Ident "print"))
131− mainDecl = P.ValueDeclaration (P.Ident "main") [] Nothing
132− (P.Do (binders ++
133− [ P.DoNotationBind (P.VarBinder (P.Ident "it")) value
134− , P.DoNotationValue (P.App trace (P.Var (P.Qualified Nothing (P.Ident "it"))) )
135− ]))
131+ value' = foldr ($) value binders
132+ mainDecl = P.ValueDeclaration (P.Ident "main") [] Nothing (P.App trace value')
136133 in
137134 P.Module moduleName $ map (importDecl . P.ModuleName . return) imports ++ [mainDecl]
138135
@@ -150,12 +147,9 @@ handleDeclaration value (PSCI imports loadedModules binders) = do
150147 Nothing -> outputStrLn "Couldn't find node.js"
151148
152149-- Parser helpers
153−parseDoNotationLet :: Parsec.Parsec String P.ParseState P.DoNotationElement
154−parseDoNotationLet = P.DoNotationLet <$> (P.reserved "let" *> P.indented *> P.parseBinder)
155− <*> (P.indented *> P.reservedOp "=" *> P.parseValue)
156−
157−parseDoNotationBind :: Parsec.Parsec String P.ParseState P.DoNotationElement
158−parseDoNotationBind = P.DoNotationBind <$> P.parseBinder <*> (P.indented *> P.reservedOp "<-" *> P.parseValue)
150+parseDoNotationLet :: Parsec.Parsec String P.ParseState (P.Value -> P.Value)
151+parseDoNotationLet = P.Let <$> (P.reserved "let" *> P.indented *> P.parseBinder)
152+ <*> (P.indented *> P.reservedOp "=" *> P.parseValue)
159153
160154parseExpression :: Parsec.Parsec String P.ParseState P.Value
161155parseExpression = P.whiteSpace *> P.parseValue <* Parsec.eof