{-# LANGUAGE Safe #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DeriveGeneric #-}
module Cryptol.Parser.Fixity
( Fixity(..)
, defaultFixity
, FixityCmp(..)
, compareFixity
) where
import Cryptol.Utils.PP (Assoc(..))
import GHC.Generics (Generic)
import Control.DeepSeq
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