From ef9886972da2e6126a509f3ab9f5b4c05f1f1569 Mon Sep 17 00:00:00 2001 From: Timothy Clem Date: Fri, 16 Jun 2017 15:52:11 -0600 Subject: [PATCH] Two version of empty --- src/Data/Syntax.hs | 2 +- src/Language/Python/Syntax.hs | 2 +- src/Language/Ruby/Syntax.hs | 7 +++---- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/src/Data/Syntax.hs b/src/Data/Syntax.hs index 995e44d2f..173017b18 100644 --- a/src/Data/Syntax.hs +++ b/src/Data/Syntax.hs @@ -36,7 +36,7 @@ instance Show1 Identifier where liftShowsPrec = genericLiftShowsPrec -- | Empty syntax, with essentially no-op semantics. -- -- This can be used to represent an implicit no-op, e.g. the alternative in an 'if' statement without an 'else'. -data Empty a = Empty +data Empty a = Empty (Maybe ByteString) deriving (Eq, Foldable, Functor, GAlign, Generic1, Show, Traversable) instance Eq1 Empty where liftEq _ _ _ = True diff --git a/src/Language/Python/Syntax.hs b/src/Language/Python/Syntax.hs index 88588237b..806aee617 100644 --- a/src/Language/Python/Syntax.hs +++ b/src/Language/Python/Syntax.hs @@ -358,7 +358,7 @@ makeTerm :: (HasCallStack, f :< fs) => a -> f (Term.Term (Union fs) a) -> Term.T makeTerm a f = cofree (a :< inj f) emptyTerm :: Assignment -emptyTerm = makeTerm <$> location <*> pure Syntax.Empty +emptyTerm = makeTerm <$> location <*> pure (Syntax.Empty Nothing) handleError :: Assignment -> Assignment handleError = flip catchError $ \ error -> case errorCause error of diff --git a/src/Language/Ruby/Syntax.hs b/src/Language/Ruby/Syntax.hs index 8753e4561..17c3a8e73 100644 --- a/src/Language/Ruby/Syntax.hs +++ b/src/Language/Ruby/Syntax.hs @@ -189,16 +189,15 @@ while' = -- <|> makeTerm <$> symbol AnonCaretEqual <*> (Expression.BXOr var <$> expression))) emptyStatement :: Assignment -emptyStatement = makeTerm <$> symbol EmptyStatement <*> children (Syntax.Identifier <$> source) +emptyStatement = makeTerm <$> symbol EmptyStatement <*> (Syntax.Empty <$> (Just <$> source)) + -- - - makeTerm :: (f :< fs, HasCallStack) => a -> f (Term.Term (Union fs) a) -> Term.Term (Union fs) a makeTerm a f = cofree $ a :< inj f emptyTerm :: Assignment -emptyTerm = makeTerm <$> location <*> pure Syntax.Empty +emptyTerm = makeTerm <$> location <*> pure (Syntax.Empty Nothing) invert :: (Expression.Boolean :< fs, HasCallStack) => Assignment.Assignment ast grammar (Term.Term (Union fs) (Record Location)) -> Assignment.Assignment ast grammar (Term.Term (Union fs) (Record Location)) invert term = makeTerm <$> location <*> fmap Expression.Not term