module PostgresqlSyntax.Validation where
import qualified Data.Text as Text
import qualified PostgresqlSyntax.KeywordSet as KeywordSet
import qualified PostgresqlSyntax.Predicate as Predicate
import PostgresqlSyntax.Prelude
op :: Text -> Maybe Text
op :: Text -> Maybe Text
op Text
a =
if Text -> Bool
Text.null Text
a
then forall a. a -> Maybe a
Just (Text
"Operator is empty")
else
if Text -> Text -> Bool
Text.isInfixOf Text
"--" Text
a
then forall a. a -> Maybe a
Just (Text
"Operator contains a prohibited \"--\" sequence: " forall a. Semigroup a => a -> a -> a
<> Text
a)
else
if Text -> Text -> Bool
Text.isInfixOf Text
"/*" Text
a
then forall a. a -> Maybe a
Just (Text
"Operator contains a prohibited \"/*\" sequence: " forall a. Semigroup a => a -> a -> a
<> Text
a)
else
if forall a. (Eq a, Hashable a) => HashSet a -> a -> Bool
Predicate.inSet HashSet Text
KeywordSet.nonOp Text
a
then forall a. a -> Maybe a
Just (Text
"Operator is not generic: " forall a. Semigroup a => a -> a -> a
<> Text
a)
else
if (Char -> Bool) -> Text -> Maybe Char
Text.find Char -> Bool
Predicate.prohibitionLiftingOpChar Text
a forall a b. a -> (a -> b) -> b
& forall a. Maybe a -> Bool
isJust
then forall a. Maybe a
Nothing
else
if Char -> Bool
Predicate.prohibitedOpChar (Text -> Char
Text.last Text
a)
then forall a. a -> Maybe a
Just (Text
"Operator ends with a prohibited char: " forall a. Semigroup a => a -> a -> a
<> Text
a)
else forall a. Maybe a
Nothing