Compare commits

...

1 Commits

Author SHA1 Message Date
Yann Esposito (Yogsototh) d56c039bb8
wip
6 years ago

@ -1,11 +1,14 @@
;; This is lish core
(comment This is lish core)
(def require (fn [x] (eval (str "(do " (cat x) ")"))))
;; increment
(def inc (fn [x] (+ x 1)))
;; map
(def range (fn [from to]
(if (< from to)
(cons from (range (inc from) to))
[])))
(def map (fn [f lst]
(if (empty? lst)
[]

@ -282,6 +282,16 @@ getenv r (expr:_) = do
_ -> evalErr "getenv need on atom or a string as argument"
getenv _ _ = evalErr "getenv need on atom or a string as argument"
comment :: Command
comment _ _ = return Void
quote :: Command
quote _ exprs = return (List (map Fix exprs))
evalList :: Command
evalList r (List exprs:[]) = r (Lambda exprs)
evalList _ _ = return Void
unstrictCommands :: [(Text,InternalCommand)]
unstrictCommands = [ ("if", InternalCommand "if" lishIf)
, ("def", InternalCommand "def" def)
@ -289,9 +299,12 @@ unstrictCommands = [ ("if", InternalCommand "if" lishIf)
, ("do", InternalCommand "do" doCommand)
, ("=", InternalCommand "=" equal)
, ("export", InternalCommand "export" export)
, ("eval", InternalCommand "eval" evalStr)
, ("quote", InternalCommand "quote" quote)
, ("eval-str", InternalCommand "eval-str" evalStr)
, ("eval", InternalCommand "eval" evalList)
, ("getenv", InternalCommand "getenv" getenv)
, ("$", InternalCommand "$" getenv)
, ("comment", InternalCommand "comment" comment)
-- list ops
, ("empty?",InternalCommand "empty?" emptyCmd)
, ("first",InternalCommand "first" firstCmd)

@ -6,7 +6,6 @@ module Lish.Parser
where
import Data.Fix
import qualified Data.Text as Text
import Protolude hiding (for, many, optional, try, (<|>))
import Text.Parsec
import Text.Parsec.Text
@ -14,14 +13,7 @@ import Text.Parsec.Text
import Lish.Types
parseCmd :: Text -> Either ParseError Expr
parseCmd = parse parseExpr "S-Expr" . Text.strip . eatComment
eatComment :: Text -> Text
eatComment t =
t
& Text.lines
& map (Text.takeWhile (/= ';'))
& Text.intercalate "\n"
parseCmd = parse parseExpr "S-Expr"
parseExpr :: Parser Expr
parseExpr = parseLambda

Loading…
Cancel
Save