{-# LANGUAGE OverloadedStrings #-} -- | Ketiv/Qere — the dual reading. -- -- Architecture §3.1: -- "A specification position that holds two authoritative values." -- Ketiv = what is written (stored form). -- Qere = what is read (executed form). -- -- At no point in the processing chain should a dual reading -- collapse to a single value. Both readings are preserved. module Shoresh.KetivQere ( DualReading(..) , SpecValue(..) , bothReadings , isDual , hasDualReadings ) where import Shoresh.Types (Reference) import Data.Text (Text) -- | A position in the specification that holds two authoritative values. data DualReading = DualReading { ketiv :: !Text -- ^ What is written (stored form) , qere :: !Text -- ^ What is read (executed form) , drRef :: !Reference -- ^ Where in Torah this occurs } deriving (Eq, Show) -- | A specification value: either single or dual. data SpecValue = Single !Text | DualVal !DualReading deriving (Show) -- | Retrieve both readings without collapsing. -- Single values return the same text for both. -- Dual values return (ketiv, qere). bothReadings :: SpecValue -> (Text, Text) bothReadings (Single t) = (t, t) bothReadings (DualVal dr) = (ketiv dr, qere dr) -- | Check if a SpecValue is a dual reading. isDual :: SpecValue -> Bool isDual (Single _) = False isDual (DualVal _) = True -- | Check if a list of spec values contains any dual readings. hasDualReadings :: [SpecValue] -> Bool hasDualReadings = any isDual