switch parsing and evaluation to use Data.Text
This commit is contained in:
parent
87bf27b6d0
commit
86be5ca06d
12
Interp.hs
12
Interp.hs
|
@ -178,7 +178,7 @@ _eval (TupleV [StrV code, DictV env]) = do
|
||||||
let trySome :: IO a -> IO (Either SomeException a)
|
let trySome :: IO a -> IO (Either SomeException a)
|
||||||
trySome = try
|
trySome = try
|
||||||
state = [fromDict env]
|
state = [fromDict env]
|
||||||
ret <- liftIO . trySome $ evalStateT (evalString $ T.unpack code) state
|
ret <- liftIO . trySome $ evalStateT (evalString code) state
|
||||||
case ret of
|
case ret of
|
||||||
Left err -> return $ TupleV [StrV (T.pack "err"), StrV $ T.pack (show err)]
|
Left err -> return $ TupleV [StrV (T.pack "err"), StrV $ T.pack (show err)]
|
||||||
Right v -> return v
|
Right v -> return v
|
||||||
|
@ -459,7 +459,7 @@ interpret state = evalStateT state initialState
|
||||||
evalProgram :: [AST] -> InterpState Value
|
evalProgram :: [AST] -> InterpState Value
|
||||||
evalProgram nodes = foldl1' (>>) $ map eval nodes
|
evalProgram nodes = foldl1' (>>) $ map eval nodes
|
||||||
|
|
||||||
evalString :: String -> InterpState Value
|
evalString :: T.Text -> InterpState Value
|
||||||
evalString program =
|
evalString program =
|
||||||
case parseProgram program of
|
case parseProgram program of
|
||||||
Left err -> error $ show err
|
Left err -> error $ show err
|
||||||
|
@ -470,14 +470,14 @@ isLiterate path = snd (splitExtension path) == ".lilamb"
|
||||||
|
|
||||||
-- Takes the lines of a literate program and returns the lines for a new executable program
|
-- Takes the lines of a literate program and returns the lines for a new executable program
|
||||||
-- from lines beginning with four spaces.
|
-- from lines beginning with four spaces.
|
||||||
parseLiterate :: [String] -> [String]
|
parseLiterate :: [T.Text] -> [T.Text]
|
||||||
parseLiterate lns = [drop 4 line | line <- lns, take 4 line == " "]
|
parseLiterate lns = [T.drop 4 line | line <- lns, T.take 4 line == T.pack " "]
|
||||||
|
|
||||||
evalFile :: FilePath -> InterpState Value
|
evalFile :: FilePath -> InterpState Value
|
||||||
evalFile path = do
|
evalFile path = do
|
||||||
contents <- liftIO $ if path == "-" then getContents else readFile path
|
contents <- liftIO $ if path == "-" then TIO.getContents else TIO.readFile path
|
||||||
if isLiterate path then
|
if isLiterate path then
|
||||||
evalString . unlines . parseLiterate . lines $ contents
|
evalString . T.unlines . parseLiterate . T.lines $ contents
|
||||||
else evalString contents
|
else evalString contents
|
||||||
|
|
||||||
evalFileV :: FilePath -> IO Value
|
evalFileV :: FilePath -> IO Value
|
||||||
|
|
Loading…
Reference in New Issue