Skip to content

Commit

Permalink
bundle bel.bel into interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremyschlatter committed Dec 19, 2019
1 parent 490992c commit 7dcd6c4
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
1 change: 1 addition & 0 deletions package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ library:
dependencies:
- bytestring
- directory
- file-embed
- filepath
- haskeline
- lens
Expand Down
13 changes: 9 additions & 4 deletions src/Eval.hs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Control.Monad.Trans.Maybe
import Control.Monad.Trans.State hiding (get, put)
import Data.Bitraversable
import qualified Data.ByteString as B
import Data.FileEmbed
import Data.List.NonEmpty as NE (nonEmpty, head, tail, reverse, (<|))
import Data.Text (singleton)
import Data.Text.Encoding
Expand Down Expand Up @@ -752,12 +753,13 @@ getOrCreateHistoryFile = do

preludeIO :: IO EvalState
preludeIO = do
let input = "reference/bel.bel"
es <- bel input
b <- builtinsIO
prog <- either (die . errorBundlePretty) id (parseMany "bel.bel" belDotBel)
(x, s) <- runEval (traverse_ evaluate prog $> Symbol Nil) b
either
(\e -> interpreterBug $ "failed to parse " <> input <> ": " <> e)
(\e -> interpreterBug $ "failed to interpret bel.bel: " <> e)
withNativeFns
es
(x $> s)

red :: String -> String
red s = "\ESC[31m" <> s <> "\ESC[0m"
Expand Down Expand Up @@ -795,3 +797,6 @@ repl = do
isUnexpectedEOF b = case toList (bundleErrors b) of
[TrivialError _ (Just EndOfInput) _] -> True
_ -> False

belDotBel :: String
belDotBel = $(embedStringFile "reference/bel.bel")

0 comments on commit 7dcd6c4

Please sign in to comment.