From 52b3b5f889dfecfd4c1a1a2dfd570fbbdc2ac0c2 Mon Sep 17 00:00:00 2001 From: osmarks Date: Thu, 17 Aug 2017 15:30:43 +0100 Subject: [PATCH] Give parse more useful output, add more useful errors --- src/Expr.elm | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Expr.elm b/src/Expr.elm index 3cd7952..f9f9f9d 100644 --- a/src/Expr.elm +++ b/src/Expr.elm @@ -16,7 +16,8 @@ type Expr num : Parser () Expr num = - Num <$> Num.float <|> Num << toFloat <$> Num.int + (Num <$> Num.float <|> Num << toFloat <$> Num.int) + "expected a number (int or float)" stringIs : String -> a -> Parser s a stringIs str val = @@ -33,12 +34,15 @@ op = group : Parser () Expr group = between (string "(") (string ")") (sepBy1 whitespace (lazy <| \_ -> parser)) -- Avoid bad recursion issues using lazy parser evaluation + "expected a group (whitespace-separated expressions between brackets)" |> map Group parser : Parser () Expr parser = (lazy <| \_ -> group) <|> op <|> num -parse : String -> Result (ParseErr ()) (ParseOk () Expr) +parse : String -> Result (List String) Expr parse = - Combine.parse parser \ No newline at end of file + Combine.parse parser + >> Result.mapError (\(_, _, errorList) -> errorList) + >> Result.map (\(_, _, expr) -> expr) -- Convert errors/results to nicer format \ No newline at end of file