From 129d962041ef76b71e98cbfd187b2f5f37a57dc7 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Wed, 26 Apr 2017 12:31:00 -0400 Subject: [PATCH] Add a leaf combinator. --- src/Language/Ruby/Syntax.hs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 443eb4585..05bf3be4b 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -105,6 +105,9 @@ literal = term <*> (Literal.true <$ symbol Language.Ruby.Syntax.True <* source term :: InUnion Syntax' f => Assignment (Node grammar) (f (Term Syntax Location) -> Term Syntax Location) term = (\ a f -> cofree $ a :< inj f) <$> location +leaf :: (Enum symbol, Eq symbol, InUnion Syntax' f) => (ByteString -> f (Term Syntax Location)) -> symbol -> Assignment (Node symbol) (Term Syntax Location) +leaf f s = symbol s *> pure (\ a -> cofree . (a :<) . inj . f) <*> location <*> source + optional :: Assignment (Node Grammar) (Term Syntax Location) -> Assignment (Node Grammar) (Term Syntax Location) optional a = a <|> term <*> pure Syntax.Empty