1{-# OPTIONS_GHC -Wall #-} 2module AST.Utils.Binop 3 ( Precedence(..) 4 , Associativity(..) 5 ) 6 where 7 8 9import Prelude hiding (Either(..)) 10import Control.Monad (liftM) 11import Data.Binary 12 13 14 15-- BINOP STUFF 16 17 18newtype Precedence = Precedence Int 19 deriving (Eq, Ord) 20 21 22data Associativity 23 = Left 24 | Non 25 | Right 26 deriving (Eq) 27 28 29 30-- BINARY 31 32 33instance Binary Precedence where 34 get = 35 liftM Precedence get 36 37 put (Precedence n) = 38 put n 39 40 41instance Binary Associativity where 42 get = 43 do n <- getWord8 44 case n of 45 0 -> return Left 46 1 -> return Non 47 2 -> return Right 48 _ -> fail "Error reading valid associativity from serialized string" 49 50 put assoc = 51 putWord8 $ 52 case assoc of 53 Left -> 0 54 Non -> 1 55 Right -> 2 56