Permalink
Browse files

Improve parsing performance (#119)

This left-factors the parser for union literals to remove an unnecessary
`try`.  This in turn improves the throughput of `dhall` on the slow
example described in #108 by 56% (2.290 s → 1.465 s)
  • Loading branch information...
Gabriel439 authored and bosu committed Sep 2, 2017
1 parent ee6bb3d commit 0e68151f7280599f2d06f5368ae8b5ebaf3231d8
Showing with 16 additions and 22 deletions.
  1. +16 −22 src/Dhall/Parser.hs
View
@@ -811,28 +811,22 @@ alternativeType embedded = do
return (a, b)
unionLit :: Show a => Parser a -> Parser (Expr Src a)
unionLit embedded =
try unionLit0
<|> unionLit1
where
unionLit0 = do
symbol "<"
a <- label
symbol "="
b <- exprA embedded
symbol ">"
return (UnionLit a b Data.Map.empty)
unionLit1 = do
symbol "<"
a <- label
symbol "="
b <- exprA embedded
symbol "|"
c <- alternativeTypes embedded
d <- toMap c
symbol ">"
return (UnionLit a b d)
unionLit embedded = do
symbol "<"
a <- label
symbol "="
b <- exprA embedded
let unionLit0 = do
symbol ">"
return (UnionLit a b Data.Map.empty)
let unionLit1 = do
symbol "|"
c <- alternativeTypes embedded
d <- toMap c
symbol ">"
return (UnionLit a b d)
unionLit0 <|> unionLit1
listLit :: Show a => Parser a -> Parser (Expr Src a)
listLit embedded = do

0 comments on commit 0e68151

Please sign in to comment.