Give parse more useful output, add more useful errors

This commit is contained in:
osmarks 2017-08-17 15:30:43 +01:00
parent 372160b040
commit 52b3b5f889

View File

@ -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
Combine.parse parser
>> Result.mapError (\(_, _, errorList) -> errorList)
>> Result.map (\(_, _, expr) -> expr) -- Convert errors/results to nicer format