-- 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 #-}

module Duckling.Ordinal.Helpers
  ( ordinal
  , oneOf
  ) where

import Prelude

import Duckling.Dimensions.Types
import Duckling.Ordinal.Types (OrdinalData (..))
import Duckling.Types
import qualified Duckling.Ordinal.Types as TOrdinal

-- -----------------------------------------------------------------
-- Patterns

oneOf :: [Int] -> PatternItem
oneOf :: [Int] -> PatternItem
oneOf [Int]
vs = Predicate -> PatternItem
Predicate (Predicate -> PatternItem) -> Predicate -> PatternItem
forall a b. (a -> b) -> a -> b
$ \Token
x ->
  case Token
x of
    (Token Dimension a
Ordinal OrdinalData {TOrdinal.value = v}) -> Int -> [Int] -> Bool
forall (t :: * -> *) a. (Foldable t, Eq a) => a -> t a -> Bool
elem Int
v [Int]
vs
    Token
_ -> Bool
False

-- -----------------------------------------------------------------
-- Production

ordinal :: Int -> Token
ordinal :: Int -> Token
ordinal Int
x = Dimension OrdinalData -> OrdinalData -> Token
forall a.
(Resolve a, Eq a, Hashable a, Show a, NFData a) =>
Dimension a -> a -> Token
Token Dimension OrdinalData
Ordinal OrdinalData :: Int -> OrdinalData
OrdinalData {value :: Int
TOrdinal.value = Int
x}