-- Copyright (c) 2016-present, Facebook, Inc.
-- All rights reserved.
--
-- This source code is licensed under the BSD-style license found in the
-- LICENSE file in the root directory of this source tree.


{-# LANGUAGE GADTs #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Email.FR.Rules
  ( rules ) where

import Data.String
import qualified Data.Text as Text
import Prelude

import Duckling.Dimensions.Types
import Duckling.Email.Types (EmailData (..))
import qualified Duckling.Email.Types as TEmail
import Duckling.Regex.Types
import Duckling.Types

ruleEmailSpelledOut :: Rule
ruleEmailSpelledOut :: Rule
ruleEmailSpelledOut = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"email spelled out"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"([\\w\\._+-]+) arobase ([\\w_-]+(\\.[\\w_-]+)+)"
    ]
  , prod :: Production
prod = \[Token]
xs -> case [Token]
xs of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[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] -> Text
Text.concat [Text
m1, Text
"@", Text
m2]}
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleEmailSpelledOut
  ]