runnable bf6 scripts with shebangs

This commit is contained in:
voidlizard 2025-02-19 11:29:31 +03:00
parent d9ae9febdd
commit 62aae7ccc3
2 changed files with 15 additions and 1 deletions

View File

@ -21,7 +21,6 @@ BINS := \
hbs2-keyman \
hbs2-git-subscribe \
git-remote-hbs2 \
git-hbs2 \
hbs2-cli \
hbs2-sync \
fixme-new \

View File

@ -1522,6 +1522,21 @@ internalEntries = do
_ -> throwIO (BadFormException @c nil)
let dropShebang = id
-- skips shebang
entry $ bindMatch "top:file:run" $ nil_ $ \case
(StringLike fn : args) -> do
liftIO (TIO.readFile fn)
<&> either (error.show) (fmap (fixContext @C @c) . dropShebang ) . parseTop
<&> \case
(ListVal (SymbolVal "#!" : _) : rest) -> rest
rest -> rest
>>= evalTop
_ -> throwIO (BadFormException @c nil)
brief "parses string as toplevel and produces a form"
$ desc "parse:top:string SYMBOL STRING-LIKE"
$ entry $ bindMatch "parse:top:string" $ \case