1
1
mirror of https://github.com/github/semantic.git synced 2024-12-29 18:06:14 +03:00

Coalesce returns on the left into committed choices.

This commit is contained in:
Rob Rix 2017-07-26 19:09:31 -04:00
parent 86e7837e76
commit 368aca225d

View File

@ -355,10 +355,12 @@ instance Enum grammar => Alternative (Assignment ast grammar) where
where choices :: Assignment ast grammar a -> Maybe (IntMap (Assignment ast grammar a))
choices (Choose choices _ `Then` continue) = Just (continue <$> choices)
choices (Many rule `Then` continue) = ((Many rule `Then` continue) <$) <$> choices rule
choices (Return _) = Just IntMap.empty
choices _ = Nothing
atEnd :: Assignment ast grammar a -> Maybe (Assignment ast grammar a)
atEnd (Choose _ atEnd `Then` continue) = continue <$> atEnd
atEnd (Many rule `Then` continue) = Just (Many rule `Then` continue)
atEnd (Return a) = Just (Return a)
atEnd _ = Nothing
many :: HasCallStack => Assignment ast grammar a -> Assignment ast grammar [a]
many a = Many a `Then` return