mirror of
https://github.com/carp-lang/Carp.git
synced 2024-11-05 04:44:12 +03:00
Merge branch 'master' of https://github.com/carp-lang/Carp
This commit is contained in:
commit
787f29e629
@ -1642,6 +1642,25 @@
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
<div class="binder">
|
||||
<a class="anchor" href="#write-file">
|
||||
<h3 id="write-file">
|
||||
write-file
|
||||
</h3>
|
||||
</a>
|
||||
<div class="description">
|
||||
command
|
||||
</div>
|
||||
<p class="sig">
|
||||
Dynamic
|
||||
</p>
|
||||
<span>
|
||||
|
||||
</span>
|
||||
<p class="doc">
|
||||
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -814,6 +814,22 @@ commandReadFile [filename] =
|
||||
_ ->
|
||||
return (Left (EvalError ("The argument to `read-file` must be a string, I got `" ++ pretty filename ++ "`") (info filename)))
|
||||
|
||||
commandWriteFile :: CommandCallback
|
||||
commandWriteFile [filename, contents] =
|
||||
case filename of
|
||||
XObj (Str fname) _ _ -> do
|
||||
case contents of
|
||||
XObj (Str s) _ _ -> do
|
||||
exceptional <- liftIO $ ((try $ writeFile fname s) :: (IO (Either IOException ())))
|
||||
case exceptional of
|
||||
Right () -> return dynamicNil
|
||||
Left _ ->
|
||||
return (Left (EvalError ("Cannot write to argument to `" ++ fname ++ "`, an argument to `write-file`") (info filename)))
|
||||
_ ->
|
||||
return (Left (EvalError ("The second argument to `write-file` must be a string, I got `" ++ pretty contents ++ "`") (info contents)))
|
||||
_ ->
|
||||
return (Left (EvalError ("The first argument to `write-file` must be a string, I got `" ++ pretty filename ++ "`") (info filename)))
|
||||
|
||||
commandSaveDocsInternal :: CommandCallback
|
||||
commandSaveDocsInternal [modulePath] = do
|
||||
ctx <- get
|
||||
|
@ -244,6 +244,7 @@ dynamicModule = Env { envBindings = bindings
|
||||
, addCommand "relative-include" 1 commandAddRelativeInclude
|
||||
, addCommand "save-docs-internal" 1 commandSaveDocsInternal
|
||||
, addCommand "read-file" 1 commandReadFile
|
||||
, addCommand "write-file" 2 commandWriteFile
|
||||
]
|
||||
++ [("String", Binder emptyMeta (XObj (Mod dynamicStringModule) Nothing Nothing))
|
||||
,("Symbol", Binder emptyMeta (XObj (Mod dynamicSymModule) Nothing Nothing))
|
||||
|
Loading…
Reference in New Issue
Block a user