-- 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 NoRebindableSyntax #-}
{-# LANGUAGE OverloadedStrings #-}

module Duckling.Time.PT.Rules
  ( rules
  ) where

import Data.Text (Text)
import Prelude
import qualified Data.Text as Text

import Duckling.Dimensions.Types
import Duckling.Duration.Helpers (isGrain)
import Duckling.Numeral.Helpers (parseInt)
import Duckling.Ordinal.Types (OrdinalData(..))
import Duckling.Regex.Types
import Duckling.Time.Helpers
import Duckling.Time.Types (TimeData(..))
import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal
import qualified Duckling.Time.Types as TTime
import qualified Duckling.TimeGrain.Types as TG

ruleSHourmintimeofday :: Rule
ruleSHourmintimeofday :: Rule
ruleSHourmintimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"às <hour-min>(time-of-day)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(à|a)s?"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"horas?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
x:[Token]
_) -> Token -> Maybe Token
forall a. a -> Maybe a
Just Token
x
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTheDayAfterTomorrow :: Rule
ruleTheDayAfterTomorrow :: Rule
ruleTheDayAfterTomorrow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the day after tomorrow"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"depois de amanh(ã|a)"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
2
  }

ruleNatal :: Rule
ruleNatal :: Rule
ruleNatal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"natal"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"natal"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
12 Int
25
  }

ruleNaoDate :: Rule
ruleNaoDate :: Rule
ruleNaoDate = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n[ao] <date>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"n[ao]"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrainOfTime Grain
TG.Day
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntersectByDaOrDe :: Rule
ruleIntersectByDaOrDe :: Rule
ruleIntersectByDaOrDe = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"intersect by `da` or `de`"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"d[ae]"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rulePassadosNCycle :: Rule
rulePassadosNCycle :: Rule
rulePassadosNCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"passados n <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(passad|[úu]ltim)[ao]s?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain (-Int
v)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLastTime :: Rule
ruleLastTime :: Rule
ruleLastTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"last <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"[úu]ltim[ao]s?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth (-Int
1) Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDatetimeDatetimeInterval :: Rule
ruleDatetimeDatetimeInterval :: Rule
ruleDatetimeDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<datetime> - <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"\\-|até( ao?)?|ao?"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDeDatetimeDatetimeInterval :: Rule
ruleDeDatetimeDatetimeInterval :: Rule
ruleDeDatetimeDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"de <datetime> - <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"de?"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"\\-|até( ao?)?|ao?"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEvening :: Rule
ruleEvening :: Rule
ruleEvening = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"evening"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"noite"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
18
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
0
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleDayOfMonthSt :: Rule
ruleDayOfMonthSt :: Rule
ruleDayOfMonthSt = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"day of month (1st)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"primeiro|um|1o"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
1
  }

ruleNow :: Rule
ruleNow :: Rule
ruleNow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"now"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(hoje)|(neste|nesse) momento"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
today
  }

ruleDimTimeDaMadrugada :: Rule
ruleDimTimeDaMadrugada :: Rule
ruleDimTimeDaMadrugada = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<dim time> da madrugada"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"(da|na|pela) madruga(da)?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> do
        TimeData
td2 <- TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> TimeData) -> Maybe TimeData -> Maybe TimeData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
1) (Bool -> Int -> TimeData
hour Bool
False Int
4)
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHhhmmTimeofday :: Rule
ruleHhhmmTimeofday :: Rule
ruleHhhmmTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hh(:|.|h)mm (time-of-day)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((?:[01]?\\d)|(?:2[0-3]))[:h\\.]([0-5]\\d)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) -> do
        Int
h <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
True Int
h Int
m
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleProximoCycle :: Rule
ruleProximoCycle :: Rule
ruleProximoCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"proximo <cycle> "
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pr(ó|o)xim(o|a)s?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleCycleAntesDeTime :: Rule
ruleCycleAntesDeTime :: Rule
ruleCycleAntesDeTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<cycle> antes de <time>"
  , pattern :: Pattern
pattern =
    [ Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"antes d[eo]"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain (-Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEsteCycle :: Rule
ruleEsteCycle :: Rule
ruleEsteCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"este <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(n?es[st](es?|as?))"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleCycleActual :: Rule
ruleCycleActual :: Rule
ruleCycleActual = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<cycle> actual"
  , pattern :: Pattern
pattern =
    [ Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"ac?tual"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleSHourminTimeofday :: Rule
ruleSHourminTimeofday :: Rule
ruleSHourminTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"às <hour-min> <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"[àa]s"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"da"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleSeason4 :: Rule
ruleSeason4 :: Rule
ruleSeason4 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"season"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"primavera"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Int -> Int -> TimeData
monthDay Int
3 Int
20
          to :: TimeData
to = Int -> Int -> TimeData
monthDay Int
6 Int
21
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleYearLatent2 :: Rule
ruleYearLatent2 :: Rule
ruleYearLatent2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year (latent)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2101 Int
10000
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDiaDayofmonthDeNamedmonth :: Rule
ruleDiaDayofmonthDeNamedmonth :: Rule
ruleDiaDayofmonthDeNamedmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dia <day-of-month> de <named-month>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dia"
    , Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    , String -> PatternItem
regex String
"de|\\/"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNoon :: Rule
ruleNoon :: Rule
ruleNoon = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"noon"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"meio[\\s\\-]?dia"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
12
  }

ruleProximasNCycle :: Rule
ruleProximasNCycle :: Rule
ruleProximasNCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"proximas n <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"pr(ó|o)xim(o|a)s?"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThisnextDayofweek :: Rule
ruleThisnextDayofweek :: Rule
ruleThisnextDayofweek = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this|next <day-of-week>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"es[ts][ae]|pr(ó|o)xim[ao]"
    , Predicate -> PatternItem
Predicate Predicate
isADayOfWeek
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTheDayBeforeYesterday :: Rule
ruleTheDayBeforeYesterday :: Rule
ruleTheDayBeforeYesterday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"the day before yesterday"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"anteontem|antes de ontem"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth Grain
TG.Day (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
2
  }

ruleHourofdayIntegerAsRelativeMinutes :: Rule
ruleHourofdayIntegerAsRelativeMinutes :: Rule
ruleHourofdayIntegerAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> <integer> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isNotLatent, Predicate
isAnHourOfDay]
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleHourofdayAndRelativeMinutes :: Rule
ruleHourofdayAndRelativeMinutes :: Rule
ruleHourofdayAndRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and <relative minutes>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"e"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
_:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleIntegerParaAsHourofdayAsRelativeMinutes :: Rule
ruleIntegerParaAsHourofdayAsRelativeMinutes :: Rule
ruleIntegerParaAsHourofdayAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<integer> para as <hour-of-day> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"para ((o|a|à)s?)?"
    , Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
Time a
td:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
n a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayIntegerAsRelativeMinutes2 :: Rule
ruleHourofdayIntegerAsRelativeMinutes2 :: Rule
ruleHourofdayIntegerAsRelativeMinutes2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> <integer> (as relative minutes) minutos"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ [Bool] -> Bool
forall (t :: * -> *). Foldable t => t Bool -> Bool
and ([Bool] -> Bool) -> (Token -> [Bool]) -> Predicate
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [Predicate] -> Token -> [Bool]
forall (t :: * -> *) (m :: * -> *) a.
(Traversable t, Monad m) =>
t (m a) -> m (t a)
sequence [Predicate
isNotLatent, Predicate
isAnHourOfDay]
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"min\\.?(uto)?s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleHourofdayAndRelativeMinutes2 :: Rule
ruleHourofdayAndRelativeMinutes2 :: Rule
ruleHourofdayAndRelativeMinutes2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and <relative minutes> minutos"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"e"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"min\\.?(uto)?s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       Token
_:
       Token
token:
       [Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleIntegerParaAsHourofdayAsRelativeMinutes2 :: Rule
ruleIntegerParaAsHourofdayAsRelativeMinutes2 :: Rule
ruleIntegerParaAsHourofdayAsRelativeMinutes2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<integer> minutos para as <hour-of-day> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1 Int
59
    , String -> PatternItem
regex String
"min\\.?(uto)?s?"
    , String -> PatternItem
regex String
"para ((o|a|à)s?)?"
    , Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token
_:Token Dimension a
Time a
td:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
n a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayQuarter :: Rule
ruleHourofdayQuarter :: Rule
ruleHourofdayQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> quarter (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"quinze"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
15
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleHourofdayAndQuarter :: Rule
ruleHourofdayAndQuarter :: Rule
ruleHourofdayAndQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and quinze"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"e quinze"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
15
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleQuarterParaAsHourofdayAsRelativeMinutes :: Rule
ruleQuarterParaAsHourofdayAsRelativeMinutes :: Rule
ruleQuarterParaAsHourofdayAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"quinze para as <hour-of-day> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"quinze para ((o|a|à)s?)?"
    , Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
15 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayHalf :: Rule
ruleHourofdayHalf :: Rule
ruleHourofdayHalf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> half (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"meia|trinta"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
30
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleHourofdayAndHalf :: Rule
ruleHourofdayAndHalf :: Rule
ruleHourofdayAndHalf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and half"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"e (meia|trinta)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
30
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleHalfParaAsHourofdayAsRelativeMinutes :: Rule
ruleHalfParaAsHourofdayAsRelativeMinutes :: Rule
ruleHalfParaAsHourofdayAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"half para as <hour-of-day> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(meia|trinta) para ((o|a|à)s?)?"
    , Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
30 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHourofdayThreeQuarter :: Rule
ruleHourofdayThreeQuarter :: Rule
ruleHourofdayThreeQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> 3/4 (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"quarenta e cinco"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
45
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleHourofdayAndThreeQuarter :: Rule
ruleHourofdayAndThreeQuarter :: Rule
ruleHourofdayAndThreeQuarter = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<hour-of-day> and 3/4"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    , String -> PatternItem
regex String
"e quarenta e cinco"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time TimeData {TTime.form = Just (TTime.TimeOfDay (Just hours) is12H)}:
       [Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
is12H Int
hours Int
45
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }
ruleThreeQuarterParaAsHourofdayAsRelativeMinutes :: Rule
ruleThreeQuarterParaAsHourofdayAsRelativeMinutes :: Rule
ruleThreeQuarterParaAsHourofdayAsRelativeMinutes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"3/4 para as <hour-of-day> (as relative minutes)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"quarenta e cinco para ((o|a|à)s?)?"
    , Predicate -> PatternItem
Predicate Predicate
isAnHourOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Int -> TimeData -> Maybe TimeData
minutesBefore Int
45 a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTiradentes :: Rule
ruleTiradentes :: Rule
ruleTiradentes = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Tiradentes"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"tiradentes"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
4 Int
21
  }

ruleInThePartofday :: Rule
ruleInThePartofday :: Rule
ruleInThePartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"in the <part-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(de|pela)"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rulePartofdayDessaSemana :: Rule
rulePartofdayDessaSemana :: Rule
rulePartofdayDessaSemana = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<part-of-day> dessa semana"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"(d?es[ts]a semana)|agora"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
today a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDepoisDasTimeofday :: Rule
ruleDepoisDasTimeofday :: Rule
ruleDepoisDasTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"depois das <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(depois|ap(ó|o)s) d?((a|á|à)[so]?|os?)"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ IntervalDirection -> TimeData -> TimeData
withDirection IntervalDirection
TTime.After a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDdmm :: Rule
ruleDdmm :: Rule
ruleDdmm = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd[/-]mm"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])[\\/\\-](0?[1-9]|1[0-2])"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (dd:mm:_)):[Token]
_) -> do
        Int
m <- Text -> Maybe Int
parseInt Text
mm
        Int
d <- Text -> Maybe Int
parseInt Text
dd
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEmDuration :: Rule
ruleEmDuration :: Rule
ruleEmDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"em <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"em"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
inDuration a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAfternoon :: Rule
ruleAfternoon :: Rule
ruleAfternoon = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"afternoon"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"tarde"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
12
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
19
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleDimTimeDaManha :: Rule
ruleDimTimeDaManha :: Rule
ruleDimTimeDaManha = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<dim time> da manha"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrainFinerThan Grain
TG.Year
    , String -> PatternItem
regex String
"(da|na|pela) manh(ã|a)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> do
        TimeData
td2 <- TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> TimeData) -> Maybe TimeData -> Maybe TimeData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
4) (Bool -> Int -> TimeData
hour Bool
False Int
12)
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNCycleProximoqueVem :: Rule
ruleNCycleProximoqueVem :: Rule
ruleNCycleProximoqueVem = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n <cycle> (proximo|que vem)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"(pr(ó|o)xim(o|a)s?|que vem?|seguintes?)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMidnight :: Rule
ruleMidnight :: Rule
ruleMidnight = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"midnight"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"meia[\\s\\-]?noite"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
False Int
0
  }

ruleDdddMonthinterval :: Rule
ruleDdddMonthinterval :: Rule
ruleDdddMonthinterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd-dd <month>(interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])"
    , String -> PatternItem
regex String
"\\-|a"
    , String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])"
    , String -> PatternItem
regex String
"de"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:_)):
       Token
_:
       Token Dimension a
RegexMatch (GroupMatch (m2:_)):
       Token
_:
       Token Dimension a
Time a
td:
       [Token]
_) -> do
        Int
d1 <- Text -> Maybe Int
parseInt Text
m1
        Int
d2 <- Text -> Maybe Int
parseInt Text
m2
        TimeData
from <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
d1) a
TimeData
td
        TimeData
to <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
d2) a
TimeData
td
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
from TimeData
to
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayLatent :: Rule
ruleTimeofdayLatent :: Rule
ruleTimeofdayLatent = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"time-of-day (latent)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
0 Int
23
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> TimeData
hour Bool
True Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleUltimoTime :: Rule
ruleUltimoTime :: Rule
ruleUltimoTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"ultimo <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(u|ú)ltimo"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth (-Int
1) Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNamedmonthnameddayPast :: Rule
ruleNamedmonthnameddayPast :: Rule
ruleNamedmonthnameddayPast = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<named-month|named-day> past"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"(da semana)? passad(o|a)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth (-Int
1) Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleSeason3 :: Rule
ruleSeason3 :: Rule
ruleSeason3 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"season"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"inverno"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Int -> Int -> TimeData
monthDay Int
12 Int
21
          to :: TimeData
to = Int -> Int -> TimeData
monthDay Int
3 Int
20
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleSeason :: Rule
ruleSeason :: Rule
ruleSeason = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"season"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ver(ã|a)o"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Int -> Int -> TimeData
monthDay Int
6 Int
21
          to :: TimeData
to = Int -> Int -> TimeData
monthDay Int
9 Int
23
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleRightNow :: Rule
ruleRightNow :: Rule
ruleRightNow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"right now"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"agora|j(á|a)|(nesse|neste) instante"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
now
  }

ruleFazemDuration :: Rule
ruleFazemDuration :: Rule
ruleFazemDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"fazem <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"faz(em)?"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ DurationData -> TimeData
durationAgo a
DurationData
dd
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAmanhPelaPartofday :: Rule
ruleAmanhPelaPartofday :: Rule
ruleAmanhPelaPartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"amanhã pela <part-of-day>"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"(da|na|pela|a)"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleHhmmMilitaryTimeofday :: Rule
ruleHhmmMilitaryTimeofday :: Rule
ruleHhmmMilitaryTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"hhmm (military time-of-day)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"((?:[01]?\\d)|(?:2[0-3]))([0-5]\\d)"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:_)):[Token]
_) -> do
        Int
h <- Text -> Maybe Int
parseInt Text
m1
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Int -> Int -> TimeData
hourMinute Bool
False Int
h Int
m
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNamedmonthnameddayNext :: Rule
ruleNamedmonthnameddayNext :: Rule
ruleNamedmonthnameddayNext = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<named-month|named-day> next"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"(da pr(o|ó)xima semana)|(da semana)? que vem"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
1 Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntersect :: Rule
ruleIntersect :: Rule
ruleIntersect = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"intersect"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayPartofday :: Rule
ruleTimeofdayPartofday :: Rule
ruleTimeofdayPartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> <part-of-day>"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"(da|na|pela)"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDentroDeDuration :: Rule
ruleDentroDeDuration :: Rule
ruleDentroDeDuration = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dentro de <duration>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(dentro de)|em"
    , Dimension DurationData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension DurationData
Duration
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Duration a
dd:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
now (DurationData -> TimeData
inDuration a
DurationData
dd)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleSTimeofday :: Rule
ruleSTimeofday :: Rule
ruleSTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"às <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(à|a)s?"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDimTimeDaTarde :: Rule
ruleDimTimeDaTarde :: Rule
ruleDimTimeDaTarde = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<dim time> da tarde"
  , pattern :: Pattern
pattern =
    [ Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"(da|na|pela) tarde"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) -> do
        TimeData
td2 <- TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> TimeData) -> Maybe TimeData -> Maybe TimeData
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
          TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open (Bool -> Int -> TimeData
hour Bool
False Int
12) (Bool -> Int -> TimeData
hour Bool
False Int
18)
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleWeekend :: Rule
ruleWeekend :: Rule
ruleWeekend = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"week-end"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"final de semana|fim de semana|fds"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt TimeData
weekend
  }

ruleDayofweekSHourmin :: Rule
ruleDayofweekSHourmin :: Rule
ruleDayofweekSHourmin = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-week> às <hour-min>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"(à|a)s"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
"da|pela"
    , Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:Token
_:Token Dimension a
Time a
td3:[Token]
_) -> do
        TimeData
td <- TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
td a
TimeData
td3
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleCycleQueVem :: Rule
ruleCycleQueVem :: Rule
ruleCycleQueVem = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<cycle> (que vem)"
  , pattern :: Pattern
pattern =
    [ Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"que vem|seguintes?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth a
Grain
grain Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAnoNovo :: Rule
ruleAnoNovo :: Rule
ruleAnoNovo = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"ano novo"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ano novo|reveillon"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
1 Int
1
  }

ruleNextTime :: Rule
ruleNextTime :: Rule
ruleNextTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"next <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(d[ao]) pr(ó|o)xim[ao]s?|que vem"
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
True a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDeYear :: Rule
ruleDeYear :: Rule
ruleDeYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"de <year>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"de|do ano"
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1000 Int
2100
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleVesperaDeAnoNovo :: Rule
ruleVesperaDeAnoNovo :: Rule
ruleVesperaDeAnoNovo = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"vespera de ano novo"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"v(é|e)spera d[eo] ano[\\s\\-]novo"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
12 Int
31
  }

ruleNPassadosCycle :: Rule
ruleNPassadosCycle :: Rule
ruleNPassadosCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n passados <cycle>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , String -> PatternItem
regex String
"(passad|[úu]ltim)[ao]s?|anterior(es)?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain (- Int
v)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNCyclePassados :: Rule
ruleNCyclePassados :: Rule
ruleNCyclePassados = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n <cycle> passados"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"(passad|[úu]ltim)[ao]s?|anterior(es)?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token: Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain (- Int
v)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDiaDayofmonthNonOrdinal :: Rule
ruleDiaDayofmonthNonOrdinal :: Rule
ruleDiaDayofmonthNonOrdinal = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dia <day-of-month> (non ordinal)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dia"
    , Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
dayOfMonth Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYyyymmdd :: Rule
ruleYyyymmdd :: Rule
ruleYyyymmdd = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"yyyy-mm-dd"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(\\d{2,4})-(0?[1-9]|1[0-2])-(3[01]|[12]\\d|0?[1-9])"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (yy:mm:dd:_)):[Token]
_) -> do
        Int
y <- Text -> Maybe Int
parseInt Text
yy
        Int
m <- Text -> Maybe Int
parseInt Text
mm
        Int
d <- Text -> Maybe Int
parseInt Text
dd
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> TimeData
yearMonthDay Int
y Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayHoras :: Rule
ruleTimeofdayHoras :: Rule
ruleTimeofdayHoras = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> horas"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"h\\.?(ora)?s?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ TimeData -> TimeData
notLatent a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTwoTimeTokensSeparatedBy :: Rule
ruleTwoTimeTokensSeparatedBy :: Rule
ruleTwoTimeTokensSeparatedBy = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"two time tokens separated by \",\""
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
","
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTwoTimeTokensSeparatedBy2 :: Rule
ruleTwoTimeTokensSeparatedBy2 :: Rule
ruleTwoTimeTokensSeparatedBy2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"two time tokens separated by \",\"2"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isNotLatent
    , String -> PatternItem
regex String
","
    , Predicate -> PatternItem
Predicate Predicate
isNotLatent
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect a
TimeData
td2 a
TimeData
td1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleMorning :: Rule
ruleMorning :: Rule
ruleMorning = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"morning"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"manh(ã|a)"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Bool -> Int -> TimeData
hour Bool
False Int
4
          to :: TimeData
to = Bool -> Int -> TimeData
hour Bool
False Int
12
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> TimeData)
-> (TimeData -> TimeData) -> TimeData -> TimeData
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$>
           TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleThisPartofday :: Rule
ruleThisPartofday :: Rule
ruleThisPartofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <part-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"es[ts]a"
    , Predicate -> PatternItem
Predicate Predicate
isAPartOfDay
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> (TimeData -> TimeData) -> TimeData -> Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
partOfDay (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> TimeData -> Maybe TimeData
intersect TimeData
today a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleThisTime :: Rule
ruleThisTime :: Rule
ruleThisTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"this <time>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"es[ts][ae]"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Bool -> TimeData -> TimeData
predNth Int
0 Bool
False a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleProclamaoDaRepblica :: Rule
ruleProclamaoDaRepblica :: Rule
ruleProclamaoDaRepblica = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Proclamação da República"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"proclama(c|ç)(a|ã)o da rep(ú|u)blica"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
11 Int
15
  }

ruleYearLatent :: Rule
ruleYearLatent :: Rule
ruleYearLatent = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year (latent)"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween (- Int
10000) Int
999
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. TimeData -> TimeData
mkLatent (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleYesterday :: Rule
ruleYesterday :: Rule
ruleYesterday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"yesterday"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"ontem"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth Grain
TG.Day (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
  }

ruleSeason2 :: Rule
ruleSeason2 :: Rule
ruleSeason2 = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"season"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"outono"
    ]
  , prod :: Production
prod = \[Token]
_ ->
      let from :: TimeData
from = Int -> Int -> TimeData
monthDay Int
9 Int
23
          to :: TimeData
to = Int -> Int -> TimeData
monthDay Int
12 Int
21
      in Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Open TimeData
from TimeData
to
  }

ruleDiaDoTrabalhador :: Rule
ruleDiaDoTrabalhador :: Rule
ruleDiaDoTrabalhador = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Dia do trabalhador"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"dia do trabalh(o|ador)"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
5 Int
1
  }

ruleNCycleAtras :: Rule
ruleNCycleAtras :: Rule
ruleNCycleAtras = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n <cycle> atras"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"atr(a|á)s"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain (- Int
v)
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTimeofdayAmpm :: Rule
ruleTimeofdayAmpm :: Rule
ruleTimeofdayAmpm = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time-of-day> am|pm"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"([ap])\\.?m?\\.?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:Token Dimension a
RegexMatch (GroupMatch (ap:_)):[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> TimeData -> TimeData
timeOfDayAMPM (Text -> Text
Text.toLower Text
ap Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== Text
"a") a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDayofmonthDeNamedmonth :: Rule
ruleDayofmonthDeNamedmonth :: Rule
ruleDayofmonthDeNamedmonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<day-of-month> de <named-month>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isDOMInteger
    , String -> PatternItem
regex String
"de|\\/"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
Time a
td:[Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEntreDatetimeEDatetimeInterval :: Rule
ruleEntreDatetimeEDatetimeInterval :: Rule
ruleEntreDatetimeEDatetimeInterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"entre <datetime> e <datetime> (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"entre( [ao])?|desde|(a partir )?d[eo]"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    , String -> PatternItem
regex String
"e|\\-|até( ao?)?|ao?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td1:Token
_:Token Dimension a
Time a
td2:[Token]
_) ->
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed a
TimeData
td1 a
TimeData
td2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleEntreDdEtDdMonthinterval :: Rule
ruleEntreDdEtDdMonthinterval :: Rule
ruleEntreDdEtDdMonthinterval = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"entre dd et dd <month>(interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"entre"
    , String -> PatternItem
regex String
"(0?[1-9]|[12]\\d|3[01])"
    , String -> PatternItem
regex String
"e?"
    , String -> PatternItem
regex String
"(0?[1-9]|[12]\\d|3[01])"
    , String -> PatternItem
regex String
"de"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:
       Token Dimension a
RegexMatch (GroupMatch (d1:_)):
       Token
_:
       Token Dimension a
RegexMatch (GroupMatch (d2:_)):
       Token
_:
       Token Dimension a
Time a
td:
       [Token]
_) -> do
        Int
dd1 <- Text -> Maybe Int
parseInt Text
d1
        Int
dd2 <- Text -> Maybe Int
parseInt Text
d2
        TimeData
dom1 <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
dd1) a
TimeData
td
        TimeData
dom2 <- TimeData -> TimeData -> Maybe TimeData
intersect (Int -> TimeData
dayOfMonth Int
dd2) a
TimeData
td
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
dom1 TimeData
dom2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleCyclePassado :: Rule
ruleCyclePassado :: Rule
ruleCyclePassado = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<cycle> passado"
  , pattern :: Pattern
pattern =
    [ Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    , String -> PatternItem
regex String
"passad[ao]s?|anterior(es)?"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth a
Grain
grain (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

rulePassadoCycle :: Rule
rulePassadoCycle :: Rule
rulePassadoCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"passado <cycle>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(passad|[úu]ltim)[ao]s?|anterior(es)?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (Int -> TimeData) -> Int -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Grain -> Int -> TimeData
cycleNth a
Grain
grain (Int -> Maybe Token) -> Int -> Maybe Token
forall a b. (a -> b) -> a -> b
$ - Int
1
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNossaSenhoraAparecida :: Rule
ruleNossaSenhoraAparecida :: Rule
ruleNossaSenhoraAparecida = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Nossa Senhora Aparecida"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"nossa senhora( aparecida)?"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
10 Int
12
  }

ruleFinados :: Rule
ruleFinados :: Rule
ruleFinados = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Finados"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"finados|dia dos mortos"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
11 Int
2
  }

ruleYear :: Rule
ruleYear :: Rule
ruleYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"year"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
1000 Int
2100
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> TimeData
year Int
n
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleAntesDasTimeofday :: Rule
ruleAntesDasTimeofday :: Rule
ruleAntesDasTimeofday = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"antes das <time-of-day>"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(antes|at(e|é)|n(a|ã)o mais que) (d?(o|a|à)s?)?"
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token Dimension a
Time a
td:[Token]
_) ->
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ IntervalDirection -> TimeData -> TimeData
withDirection IntervalDirection
TTime.Before a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleNProximasCycle :: Rule
ruleNProximasCycle :: Rule
ruleNProximasCycle = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"n proximas <cycle>"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Predicate
isIntegerBetween Int
2 Int
9999
    , String -> PatternItem
regex String
"pr(ó|o)xim(o|a)s?"
    , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
TimeGrain a
grain:[Token]
_) -> do
        Int
v <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData
cycleN Bool
True a
Grain
grain Int
v
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleDdmmyyyy :: Rule
ruleDdmmyyyy :: Rule
ruleDdmmyyyy = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"dd[/-.]mm[/-.]yyyy"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"(3[01]|[12]\\d|0?[1-9])[\\.\\/\\-](0?[1-9]|1[0-2])[\\.\\/\\-](\\d{2,4})"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
RegexMatch (GroupMatch (m1:m2:m3:_)):[Token]
_) -> do
        Int
y <- Text -> Maybe Int
parseInt Text
m3
        Int
m <- Text -> Maybe Int
parseInt Text
m2
        Int
d <- Text -> Maybe Int
parseInt Text
m1
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> Int -> TimeData
yearMonthDay Int
y Int
m Int
d
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIndependecia :: Rule
ruleIndependecia :: Rule
ruleIndependecia = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"Independecia"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"independ(ê|e)ncia"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Int -> Int -> TimeData
monthDay Int
9 Int
7
  }

ruleTomorrow :: Rule
ruleTomorrow :: Rule
ruleTomorrow = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"tomorrow"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"amanh(ã|a)"
    ]
  , prod :: Production
prod = \[Token]
_ -> TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> Int -> TimeData
cycleNth Grain
TG.Day Int
1
  }

ruleTimezone :: Rule
ruleTimezone :: Rule
ruleTimezone = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<time> timezone"
  , pattern :: Pattern
pattern =
    [ Predicate -> PatternItem
Predicate Predicate
isATimeOfDay
    , String -> PatternItem
regex String
"\\b(YEKT|YEKST|YAKT|YAKST|WITA|WIT|WIB|WGT|WGST|WFT|WET|WEST|WAT|WAST|VUT|VLAT|VLAST|VET|UZT|UYT|UYST|UTC|ULAT|TVT|TMT|TLT|TKT|TJT|TFT|TAHT|SST|SRT|SGT|SCT|SBT|SAST|SAMT|RET|PYT|PYST|PWT|PST|PONT|PMST|PMDT|PKT|PHT|PHOT|PGT|PETT|PETST|PET|PDT|OMST|OMSST|NZST|NZDT|NUT|NST|NPT|NOVT|NOVST|NFT|NDT|NCT|MYT|MVT|MUT|MST|MSK|MSD|MMT|MHT|MDT|MAWT|MART|MAGT|MAGST|LINT|LHST|LHDT|KUYT|KST|KRAT|KRAST|KGT|JST|IST|IRST|IRKT|IRKST|IRDT|IOT|IDT|ICT|HOVT|HKT|GYT|GST|GMT|GILT|GFT|GET|GAMT|GALT|FNT|FKT|FKST|FJT|FJST|EST|EGT|EGST|EET|EEST|EDT|ECT|EAT|EAST|EASST|DAVT|ChST|CXT|CVT|CST|COT|CLT|CLST|CKT|CHAST|CHADT|CET|CEST|CDT|CCT|CAT|CAST|BTT|BST|BRT|BRST|BOT|BNT|AZT|AZST|AZOT|AZOST|AWST|AWDT|AST|ART|AQTT|ANAT|ANAST|AMT|AMST|ALMT|AKST|AKDT|AFT|AEST|AEDT|ADT|ACST|ACDT)\\b"
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token Dimension a
Time a
td:
       Token Dimension a
RegexMatch (GroupMatch (tz:_)):
       [Token]
_) -> Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> Text -> TimeData -> Maybe TimeData
inTimezone (Text -> Text
Text.toUpper Text
tz) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleCycleOrdinalOfTime :: Rule
ruleCycleOrdinalOfTime :: Rule
ruleCycleOrdinalOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"<ordinal> <cycle> de <time>"
    , pattern :: Pattern
pattern =
      [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , String -> PatternItem
regex String
"d[eo]|em"
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
token:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) -> do
          Int
n <- Token -> Maybe Int
getIntValue Token
token
          TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True a
Grain
grain (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleCycleOrdinalTime :: Rule
ruleCycleOrdinalTime :: Rule
ruleCycleOrdinalTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"<ordinal> <cycle> <time>"
    , pattern :: Pattern
pattern =
      [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
token:Token Dimension a
TimeGrain a
grain: Token Dimension a
Time a
td:[Token]
_) -> do
          Int
n <- Token -> Maybe Int
getIntValue Token
token
          TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True a
Grain
grain (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleCycleTheOrdinalOfTime :: Rule
ruleCycleTheOrdinalOfTime :: Rule
ruleCycleTheOrdinalOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"o <ordinal> <cycle> de <time>"
    , pattern :: Pattern
pattern =
      [ String -> PatternItem
regex String
"o|a"
      , Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , String -> PatternItem
regex String
"d[eo]|em"
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
_:Token
token:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) -> do
          Int
n <- Token -> Maybe Int
getIntValue Token
token
          TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True a
Grain
grain (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleOrdinalTrimestre :: Rule
ruleOrdinalTrimestre :: Rule
ruleOrdinalTrimestre = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> trimestre"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Quarter
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True Grain
TG.Quarter (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$
          Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleTheOrdinalTrimestre :: Rule
ruleTheOrdinalTrimestre :: Rule
ruleTheOrdinalTrimestre = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"o <ordinal> trimestre"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"o|a"
    , Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Quarter
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:Token
token:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token)
-> (TimeData -> TimeData) -> TimeData -> Maybe Token
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
True Grain
TG.Quarter (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$
          Grain -> Int -> TimeData
cycleNth Grain
TG.Year Int
0
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleOrdinalTrimestreYear :: Rule
ruleOrdinalTrimestreYear :: Rule
ruleOrdinalTrimestreYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"<ordinal> trimestre <year>"
  , pattern :: Pattern
pattern =
    [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
    , Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ Grain -> Predicate
isGrain Grain
TG.Quarter
    , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
token:Token
_:Token Dimension a
Time a
td:[Token]
_) -> do
        Int
n <- Token -> Maybe Int
getIntValue Token
token
        TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False Grain
TG.Quarter (Int
n Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleLastCycleOfTime :: Rule
ruleLastCycleOfTime :: Rule
ruleLastCycleOfTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"último <cycle> de <time>"
    , pattern :: Pattern
pattern =
      [ String -> PatternItem
regex String
"[úu]ltim[ao]s?"
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , String -> PatternItem
regex String
"d[eo]|em"
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
_:Token Dimension a
TimeGrain a
grain:Token
_:Token Dimension a
Time a
td:[Token]
_) ->
          TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> TimeData -> TimeData
cycleLastOf a
Grain
grain a
TimeData
td
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleLastCycleTime :: Rule
ruleLastCycleTime :: Rule
ruleLastCycleTime = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"último <cycle> <time>"
    , pattern :: Pattern
pattern =
      [ String -> PatternItem
regex String
"[úu]ltim[ao]s?"
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
_:Token Dimension a
TimeGrain a
grain: Token Dimension a
Time a
td:[Token]
_) ->
          TimeData -> Maybe Token
tt (TimeData -> Maybe Token) -> TimeData -> Maybe Token
forall a b. (a -> b) -> a -> b
$ Grain -> TimeData -> TimeData
cycleLastOf a
Grain
grain a
TimeData
td
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleIntervalFromMonthDDDDOf :: Rule
ruleIntervalFromMonthDDDDOf :: Rule
ruleIntervalFromMonthDDDDOf = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"desde <month> dd-dd de (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"desde|a partir d[eo]"
    , Predicate -> PatternItem
Predicate Predicate
isDOMValue
    , String -> PatternItem
regex String
"até( ao?)?|ao?"
    , Predicate -> PatternItem
Predicate Predicate
isDOMValue
    , String -> PatternItem
regex String
"d[eo]|em"
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:
       Token
token1:
       Token
_:
       Token
token2:
       Token
_:
       Token Dimension a
Time a
td:
       [Token]
_) -> do
        TimeData
dom1 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token1
        TimeData
dom2 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token2
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
dom1 TimeData
dom2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntervalDDDDMonthOf :: Rule
ruleIntervalDDDDMonthOf :: Rule
ruleIntervalDDDDMonthOf = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"dd-dd <month> de (interval)"
    , pattern :: Pattern
pattern =
      [ Predicate -> PatternItem
Predicate Predicate
isDOMValue
      , String -> PatternItem
regex String
"\\-|a(té)?"
      , Predicate -> PatternItem
Predicate Predicate
isDOMValue
      , String -> PatternItem
regex String
"d[eo]|em"
      , Predicate -> PatternItem
Predicate Predicate
isAMonth
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
token1:
         Token
_:
         Token
token2:
         Token
_:
         Token Dimension a
Time a
td:
         [Token]
_) -> do
          TimeData
dom1 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token1
          TimeData
dom2 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token2
          Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
dom1 TimeData
dom2
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleIntervalFromMonthDDDD :: Rule
ruleIntervalFromMonthDDDD :: Rule
ruleIntervalFromMonthDDDD = Rule :: Text -> Pattern -> Production -> Rule
Rule
  { name :: Text
name = Text
"desde <month> dd-dd (interval)"
  , pattern :: Pattern
pattern =
    [ String -> PatternItem
regex String
"desde|a partir d[eo]"
    , Predicate -> PatternItem
Predicate Predicate
isDOMValue
    , String -> PatternItem
regex String
"até( ao?)?|ao?"
    , Predicate -> PatternItem
Predicate Predicate
isDOMValue
    , Predicate -> PatternItem
Predicate Predicate
isAMonth
    ]
  , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
      (Token
_:
       Token
token1:
       Token
_:
       Token
token2:
       Token Dimension a
Time a
td:
       [Token]
_) -> do
        TimeData
dom1 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token1
        TimeData
dom2 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token2
        Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
dom1 TimeData
dom2
      [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
  }

ruleIntervalDDDDMonth :: Rule
ruleIntervalDDDDMonth :: Rule
ruleIntervalDDDDMonth = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"dd-dd <month> (interval)"
    , pattern :: Pattern
pattern =
      [ Predicate -> PatternItem
Predicate Predicate
isDOMValue
      , String -> PatternItem
regex String
"\\-|a(té)?"
      , Predicate -> PatternItem
Predicate Predicate
isDOMValue
      , Predicate -> PatternItem
Predicate Predicate
isAMonth
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
token1:
         Token
_:
         Token
token2:
         Token Dimension a
Time a
td:
         [Token]
_) -> do
          TimeData
dom1 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token1
          TimeData
dom2 <- TimeData -> Token -> Maybe TimeData
intersectDOM a
TimeData
td Token
token2
          Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
dom1 TimeData
dom2
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleOrdinalCycleOfYearOrdinalCycleOfYear :: Rule
ruleOrdinalCycleOfYearOrdinalCycleOfYear :: Rule
ruleOrdinalCycleOfYearOrdinalCycleOfYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"<ordinal> <cycle> de <year> - <ordinal> <cycle> de <year>"
    , pattern :: Pattern
pattern =
      [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , String -> PatternItem
regex String
"d[eo]|em"
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      , String -> PatternItem
regex String
"\\-|até( ao?)?|ao?"
      , Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , String -> PatternItem
regex String
"d[eo]|em"
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
token1:
         Token Dimension a
TimeGrain a
grain1:
         Token
_:
         Token Dimension a
Time a
td1:
         Token
_:
         Token
token2:
         Token Dimension a
TimeGrain a
grain2:
         Token
_:
         Token Dimension a
Time a
td2:
         [Token]
_) -> do
          Int
n1 <- Token -> Maybe Int
getIntValue Token
token1
          Int
n2 <- Token -> Maybe Int
getIntValue Token
token2
          let from :: TimeData
from = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain1 (Int
n1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td1
              to :: TimeData
to = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain2 (Int
n2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td2
          Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
from TimeData
to
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

ruleOrdinalCycleYearOrdinalCycleYear :: Rule
ruleOrdinalCycleYearOrdinalCycleYear :: Rule
ruleOrdinalCycleYearOrdinalCycleYear = Rule :: Text -> Pattern -> Production -> Rule
Rule
    { name :: Text
name = Text
"<ordinal> <cycle> <year> - <ordinal> <cycle> <year>"
    , pattern :: Pattern
pattern =
      [ Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      , String -> PatternItem
regex String
"\\-|até( ao?)?|ao?"
      , Dimension OrdinalData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension OrdinalData
Ordinal
      , Dimension Grain -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension Grain
TimeGrain
      , Dimension TimeData -> PatternItem
forall a. Typeable a => Dimension a -> PatternItem
dimension Dimension TimeData
Time
      ]
    , prod :: Production
prod = \[Token]
tokens -> case [Token]
tokens of
        (Token
token1:
         Token Dimension a
TimeGrain a
grain1:
         Token Dimension a
Time a
td1:
         Token
_:
         Token
token2:
         Token Dimension a
TimeGrain a
grain2:
         Token Dimension a
Time a
td2:
         [Token]
_) -> do
          Int
n1 <- Token -> Maybe Int
getIntValue Token
token1
          Int
n2 <- Token -> Maybe Int
getIntValue Token
token2
          let from :: TimeData
from = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter Bool
False a
Grain
grain1 (Int
n1 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td1
              to :: TimeData
to = Bool -> Grain -> Int -> TimeData -> TimeData
cycleNthAfter  Bool
False a
Grain
grain2 (Int
n2 Int -> Int -> Int
forall a. Num a => a -> a -> a
- Int
1) a
TimeData
td2
          Dimension TimeData -> TimeData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension TimeData
Time (TimeData -> Token) -> Maybe TimeData -> Maybe Token
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
<$> TimeIntervalType -> TimeData -> TimeData -> Maybe TimeData
interval TimeIntervalType
TTime.Closed TimeData
from TimeData
to
        [Token]
_ -> Maybe Token
forall a. Maybe a
Nothing
    }

daysOfWeek :: [(Text, String)]
daysOfWeek :: [(Text, String)]
daysOfWeek =
  [ ( Text
"Segunda-feira", String
"segunda((\\s|\\-)feira)?|seg\\.?" )
  , ( Text
"Terça-feira", String
"ter(ç|c)a((\\s|\\-)feira)?|ter\\."  )
  , ( Text
"Quart-feira", String
"quarta((\\s|\\-)feira)?|qua\\.?"    )
  , ( Text
"Quinta-feira", String
"quinta((\\s|\\-)feira)?|qui\\.?"   )
  , ( Text
"Sexta-feira", String
"sexta((\\s|\\-)feira)?|sex\\.?"     )
  , ( Text
"Sábada", String
"s(á|a)bado|s(á|a)b\\.?"                  )
  , ( Text
"Domingo", String
"domingo|dom\\.?"                        )
  ]

ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek :: [Rule]
ruleDaysOfWeek = [(Text, String)] -> [Rule]
mkRuleDaysOfWeek [(Text, String)]
daysOfWeek

months :: [(Text, String)]
months :: [(Text, String)]
months =
  [ ( Text
"Janeiro"   , String
"janeiro|jan\\.?"   )
  , ( Text
"Fevereiro" , String
"fevereiro|fev\\.?" )
  , ( Text
"Março"     , String
"mar(ç|c)o|mar\\.?" )
  , ( Text
"Abril"     , String
"abril|abr\\.?"     )
  , ( Text
"Maio"      , String
"maio|mai\\.?"      )
  , ( Text
"Junho"     , String
"junho|jun\\.?"     )
  , ( Text
"Julho"     , String
"julho|jul\\.?"     )
  , ( Text
"Agosto"    , String
"agosto|ago\\.?"    )
  , ( Text
"Setembro"  , String
"setembro|set\\.?"  )
  , ( Text
"Outubro"   , String
"outubro|out\\.?"   )
  , ( Text
"Novembro"  , String
"novembro|nov\\.?"  )
  , ( Text
"Dezembro"  , String
"dezembro|dez\\.?"  )
  ]

ruleMonths :: [Rule]
ruleMonths :: [Rule]
ruleMonths = [(Text, String)] -> [Rule]
mkRuleMonths [(Text, String)]
months

rules :: [Rule]
rules :: [Rule]
rules =
  [ Rule
ruleAfternoon
  , Rule
ruleAmanhPelaPartofday
  , Rule
ruleAnoNovo
  , Rule
ruleAntesDasTimeofday
  , Rule
ruleDatetimeDatetimeInterval
  , Rule
ruleDayOfMonthSt
  , Rule
ruleDayofmonthDeNamedmonth
  , Rule
ruleDayofweekSHourmin
  , Rule
ruleDdddMonthinterval
  , Rule
ruleDdmm
  , Rule
ruleDdmmyyyy
  , Rule
ruleDeDatetimeDatetimeInterval
  , Rule
ruleDeYear
  , Rule
ruleDentroDeDuration
  , Rule
ruleDepoisDasTimeofday
  , Rule
ruleDiaDayofmonthDeNamedmonth
  , Rule
ruleDiaDayofmonthNonOrdinal
  , Rule
ruleDiaDoTrabalhador
  , Rule
ruleDimTimeDaMadrugada
  , Rule
ruleDimTimeDaManha
  , Rule
ruleDimTimeDaTarde
  , Rule
ruleEmDuration
  , Rule
ruleEntreDatetimeEDatetimeInterval
  , Rule
ruleEntreDdEtDdMonthinterval
  , Rule
ruleEsteCycle
  , Rule
ruleCycleActual
  , Rule
ruleEvening
  , Rule
ruleFazemDuration
  , Rule
ruleFinados
  , Rule
ruleHhhmmTimeofday
  , Rule
ruleHhmmMilitaryTimeofday
  , Rule
ruleHourofdayAndRelativeMinutes
  , Rule
ruleHourofdayAndRelativeMinutes2
  , Rule
ruleHourofdayAndQuarter
  , Rule
ruleHourofdayAndThreeQuarter
  , Rule
ruleHourofdayAndHalf
  , Rule
ruleHourofdayIntegerAsRelativeMinutes
  , Rule
ruleHourofdayIntegerAsRelativeMinutes2
  , Rule
ruleHourofdayQuarter
  , Rule
ruleHourofdayHalf
  , Rule
ruleHourofdayThreeQuarter
  , Rule
ruleInThePartofday
  , Rule
ruleIndependecia
  , Rule
ruleIntegerParaAsHourofdayAsRelativeMinutes
  , Rule
ruleIntegerParaAsHourofdayAsRelativeMinutes2
  , Rule
ruleHalfParaAsHourofdayAsRelativeMinutes
  , Rule
ruleQuarterParaAsHourofdayAsRelativeMinutes
  , Rule
ruleThreeQuarterParaAsHourofdayAsRelativeMinutes
  , Rule
ruleIntersect
  , Rule
ruleIntersectByDaOrDe
  , Rule
ruleLastTime
  , Rule
ruleMidnight
  , Rule
ruleMorning
  , Rule
ruleNCycleAtras
  , Rule
ruleNCycleProximoqueVem
  , Rule
ruleNPassadosCycle
  , Rule
ruleNProximasCycle
  , Rule
ruleNamedmonthnameddayNext
  , Rule
ruleNamedmonthnameddayPast
  , Rule
ruleNaoDate
  , Rule
ruleNatal
  , Rule
ruleNextTime
  , Rule
ruleCycleQueVem
  , Rule
ruleProximoCycle
  , Rule
ruleNoon
  , Rule
ruleNossaSenhoraAparecida
  , Rule
ruleNow
  , Rule
ruleCycleAntesDeTime
  , Rule
ruleCyclePassado
  , Rule
rulePassadoCycle
  , Rule
rulePartofdayDessaSemana
  , Rule
rulePassadosNCycle
  , Rule
ruleNCyclePassados
  , Rule
ruleProclamaoDaRepblica
  , Rule
ruleProximasNCycle
  , Rule
ruleRightNow
  , Rule
ruleSHourminTimeofday
  , Rule
ruleSHourmintimeofday
  , Rule
ruleSTimeofday
  , Rule
ruleSeason
  , Rule
ruleSeason2
  , Rule
ruleSeason3
  , Rule
ruleSeason4
  , Rule
ruleTheDayAfterTomorrow
  , Rule
ruleTheDayBeforeYesterday
  , Rule
ruleThisPartofday
  , Rule
ruleThisTime
  , Rule
ruleThisnextDayofweek
  , Rule
ruleTimeofdayAmpm
  , Rule
ruleTimeofdayHoras
  , Rule
ruleTimeofdayLatent
  , Rule
ruleTimeofdayPartofday
  , Rule
ruleTiradentes
  , Rule
ruleTomorrow
  , Rule
ruleTwoTimeTokensSeparatedBy
  , Rule
ruleTwoTimeTokensSeparatedBy2
  , Rule
ruleUltimoTime
  , Rule
ruleVesperaDeAnoNovo
  , Rule
ruleWeekend
  , Rule
ruleYear
  , Rule
ruleYearLatent
  , Rule
ruleYearLatent2
  , Rule
ruleYesterday
  , Rule
ruleYyyymmdd
  , Rule
ruleTimezone
  , Rule
ruleCycleOrdinalOfTime
  , Rule
ruleCycleOrdinalTime
  , Rule
ruleCycleTheOrdinalOfTime
  , Rule
ruleOrdinalTrimestre
  , Rule
ruleTheOrdinalTrimestre
  , Rule
ruleOrdinalTrimestreYear
  , Rule
ruleLastCycleOfTime
  , Rule
ruleLastCycleTime
  , Rule
ruleIntervalFromMonthDDDDOf
  , Rule
ruleIntervalDDDDMonthOf
  , Rule
ruleIntervalFromMonthDDDD
  , Rule
ruleIntervalDDDDMonth
  , Rule
ruleOrdinalCycleOfYearOrdinalCycleOfYear
  , Rule
ruleOrdinalCycleYearOrdinalCycleYear
  ]
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleMonths
  [Rule] -> [Rule] -> [Rule]
forall a. [a] -> [a] -> [a]
++ [Rule]
ruleDaysOfWeek