{-# LANGUAGE Safe #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
module Cryptol.Utils.Fixity
( Assoc(..)
, Fixity(..)
, defaultFixity
, FixityCmp(..)
, compareFixity
) where
import GHC.Generics (Generic)
import Control.DeepSeq
data Assoc = LeftAssoc | RightAssoc | NonAssoc
deriving (Show, Eq, Generic, NFData)
data Fixity = Fixity { fAssoc :: !Assoc, fLevel :: !Int }
deriving (Eq, Generic, NFData, Show)
data FixityCmp = FCError
| FCLeft
| FCRight
deriving (Show, Eq)
compareFixity :: Fixity -> Fixity -> FixityCmp
compareFixity (Fixity a1 p1) (Fixity a2 p2) =
case compare p1 p2 of
GT -> FCLeft
LT -> FCRight
EQ -> case (a1, a2) of
(LeftAssoc, LeftAssoc) -> FCLeft
(RightAssoc, RightAssoc) -> FCRight
_ -> FCError
defaultFixity :: Fixity
defaultFixity = Fixity LeftAssoc 100