module HIndent.Ast.Declaration.Signature.Fixity.Associativity
  ( Associativity
  , mkAssociativity
  ) where

import qualified GHC.Types.Fixity as GHC
import HIndent.Ast.NodeComments
import {-# SOURCE #-} HIndent.Pretty
import HIndent.Pretty.Combinators
import HIndent.Pretty.NodeComments

data Associativity
  = LeftAssoc
  | RightAssoc
  | None

instance CommentExtraction Associativity where
  nodeComments :: Associativity -> NodeComments
nodeComments Associativity
LeftAssoc = [LEpaComment] -> [LEpaComment] -> [LEpaComment] -> NodeComments
NodeComments [] [] []
  nodeComments Associativity
RightAssoc = [LEpaComment] -> [LEpaComment] -> [LEpaComment] -> NodeComments
NodeComments [] [] []
  nodeComments Associativity
None = [LEpaComment] -> [LEpaComment] -> [LEpaComment] -> NodeComments
NodeComments [] [] []

instance Pretty Associativity where
  pretty' :: Associativity -> Printer ()
pretty' Associativity
LeftAssoc = HasCallStack => String -> Printer ()
String -> Printer ()
string String
"infixl"
  pretty' Associativity
RightAssoc = HasCallStack => String -> Printer ()
String -> Printer ()
string String
"infixr"
  pretty' Associativity
None = HasCallStack => String -> Printer ()
String -> Printer ()
string String
"infix"

mkAssociativity :: GHC.FixityDirection -> Associativity
mkAssociativity :: FixityDirection -> Associativity
mkAssociativity FixityDirection
GHC.InfixL = Associativity
LeftAssoc
mkAssociativity FixityDirection
GHC.InfixR = Associativity
RightAssoc
mkAssociativity FixityDirection
GHC.InfixN = Associativity
None