1
1
mirror of https://github.com/github/semantic.git synced 2024-12-20 13:21:59 +03:00

Alternation distributes through binds over Location rules.

This commit is contained in:
Rob Rix 2017-07-26 18:42:52 -04:00
parent 49449f5be2
commit 76feae64d7

View File

@ -347,6 +347,7 @@ instance Enum grammar => Alternative (Assignment ast grammar) where
(<|>) :: HasCallStack => Assignment ast grammar a -> Assignment ast grammar a -> Assignment ast grammar a
Return a <|> _ = Return a
(Children l `Then` continueL) <|> (Children r `Then` continueR) = Children (Left <$> l <|> Right <$> r) `Then` either continueL continueR
(Location `Then` continueL) <|> (Location `Then` continueR) = Location `Then` uncurry (<|>) . (continueL &&& continueR)
l <|> r | Just c <- (liftA2 (IntMap.unionWith (<|>)) `on` choices) l r = Choose c `Then` identity
| otherwise = wrap $ Alt l r
where choices :: Assignment ast grammar a -> Maybe (IntMap (Assignment ast grammar a))