{-# language DeriveFunctor, DeriveFoldable, DeriveTraversable, DeriveGeneric #-}
{-# language InstanceSigs, ScopedTypeVariables, TypeApplications #-}
{-# language LambdaCase #-}
module Language.Python.Syntax.Operator.Unary where
import Control.Lens.Lens (Lens', lens)
import Data.Generics.Product.Typed (typed)
import GHC.Generics (Generic)
import Language.Python.Syntax.Ann
import Language.Python.Syntax.Whitespace
data UnOp a
= Negate (Ann a) [Whitespace]
| Positive (Ann a) [Whitespace]
| Complement (Ann a) [Whitespace]
deriving (Eq, Show, Functor, Foldable, Traversable, Generic)
instance HasAnn UnOp where
annot :: forall a. Lens' (UnOp a) (Ann a)
annot = typed @(Ann a)
instance HasTrailingWhitespace (UnOp a) where
trailingWhitespace =
lens
(\case
Negate _ a -> a
Positive _ a -> a
Complement _ a -> a)
(\op ws ->
case op of
Negate a _ -> Negate a ws
Positive a _ -> Positive a ws
Complement a _ -> Complement a ws)