{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}
module Duckling.Email.Rules
( rules ) where
import Prelude
import Data.String
import Duckling.Dimensions.Types
import Duckling.Email.Types (EmailData (..))
import qualified Duckling.Email.Types as TEmail
import Duckling.Regex.Types
import Duckling.Types
ruleEmail :: Rule
ruleEmail :: Rule
ruleEmail = Rule :: Text -> Pattern -> Production -> Rule
Rule
{ name :: Text
name = Text
"email"
, pattern :: Pattern
pattern =
[ String -> PatternItem
regex String
"([\\w\\._+-]+@[\\w_-]+(\\.[\\w_-]+)+)"
]
, prod :: Production
prod = \[Token]
xs -> case [Token]
xs of
(Token Dimension a
RegexMatch (GroupMatch (x:_)):[Token]
_) ->
Token -> Maybe Token
forall a. a -> Maybe a
Just (Token -> Maybe Token) -> Token -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Dimension EmailData -> EmailData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension EmailData
Email EmailData :: Text -> EmailData
EmailData {value :: Text
TEmail.value = Text
x}
[Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
}
rules :: [Rule]
rules :: [Rule]
rules =
[ Rule
ruleEmail
]