module Hasql.TH.Syntax.Validator where
import Hasql.TH.Prelude hiding (expression)
import qualified Data.HashSet as HashSet
import qualified Data.Text as Text
import qualified Hasql.TH.Syntax.HashSet as HashSet
import qualified Hasql.TH.Syntax.Predicate as Predicate
op :: Text -> Maybe Text
op a =
if Text.null a
then Just ("Operator is empty")
else if Text.isInfixOf "--" a
then Just ("Operator contains a prohibited \"--\" sequence: " <> a)
else if Text.isInfixOf "/*" a
then Just ("Operator contains a prohibited \"/*\" sequence: " <> a)
else if Predicate.inSet HashSet.nonOp a
then Just ("Operator is not generic: " <> a)
else if Text.find Predicate.prohibitionLiftingOpChar a & isJust
then Nothing
else if Predicate.prohibitedOpChar (Text.last a)
then Just ("Operator ends with a prohibited char: " <> a)
else Nothing