improved slightly

This commit is contained in:
Yann Esposito (Yogsototh) 2020-08-02 10:53:28 +02:00
parent f47c3f0280
commit 18ddac1e30
Signed by untrusted user who does not match committer: yogsototh
GPG key ID: 7B19A4C650D59646
4 changed files with 10 additions and 15 deletions

1
.envrc Normal file
View file

@ -0,0 +1 @@
eval "$(lorri direnv)"

View file

@ -7,19 +7,13 @@ This project is an experimental LISP flavoured Shell
## Build ## Build
Install [`stack`](http://haskellstack.org) Install [`nix`](https://nixos.org/nix)
And then And then
~~~ ~~~
git clone https://github.com/yogsototh/lish.git git clone https://github.com/yogsototh/lish.git
cd lish cd lish
stack setup && stack build nix-shell
stack exec -- lish-exe cabal run lish
~~~ ~~~
## To note
This Haskell project use the stack template `tasty-travis`.
Please read file `tutorial.md` for first steps in using the template.

View file

@ -22,6 +22,8 @@ parseTests =
, testCase "_foo" (simpleCommand "_foo") , testCase "_foo" (simpleCommand "_foo")
, testCase "multiline" , testCase "multiline"
(parseCmd "(fn [x]\n (+ x 1))" @?= Right incExpr) (parseCmd "(fn [x]\n (+ x 1))" @?= Right incExpr)
, testCase "multiline 2"
(parseCmd "(fn\n [x]\n (+ x 1))" @?= Right incExpr)
-- TODO: or not? support line comment -- TODO: or not? support line comment
-- , testCase "multiline command with comment" -- , testCase "multiline command with comment"
-- (parseCmd "(fn [x] ; comment \n (+ x 1))" @?= Right incExpr) -- (parseCmd "(fn [x] ; comment \n (+ x 1))" @?= Right incExpr)

View file

@ -23,21 +23,19 @@ parseExpr = parseLambda
<|> parseString <|> parseString
parseNumber :: Parser Expr parseNumber :: Parser Expr
parseNumber = (Fix . Num . fromMaybe 0 . readMaybe) <$> many1 digit parseNumber = Fix . Num . fromMaybe 0 . readMaybe <$> many1 digit
parseAtom :: Parser Expr parseAtom :: Parser Expr
parseAtom = do parseAtom = do
frst <- noneOf " \t()[]\"" frst <- noneOf " \t\n()[]{}\""
rest <- many (noneOf " \t()[]") rest <- many (noneOf " \t\n()[]{}")
case frst:rest of case frst:rest of
"true" -> return . Fix $ Bool True "true" -> return . Fix $ Bool True
"false" -> return . Fix $ Bool False "false" -> return . Fix $ Bool False
x -> return . Fix $ Atom (toS x) x -> return . Fix $ Atom (toS x)
parseString :: Parser Expr parseString :: Parser Expr
parseString = (Fix . Str . toS) <$> between (char '"') parseString = Fix . Str . toS <$> between (char '"') (char '"') (many (noneOf "\""))
(char '"')
(many (noneOf "\""))
parseExprs :: Parser [Expr] parseExprs :: Parser [Expr]
parseExprs = sepEndBy parseExpr spaces parseExprs = sepEndBy parseExpr spaces