{-# LANGUAGE BlockArguments      #-}
{-# LANGUAGE ImportQualifiedPost #-}
{-# LANGUAGE OverloadedStrings   #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications    #-}
{-# LANGUAGE ViewPatterns        #-}

module Dovetail.Core.Data.String.Regex where
  
import Data.Foldable (fold)
import Data.Text (Text)
import Data.Vector (Vector)
import Dovetail
import Dovetail.Evaluate (builtIn)

env :: forall ctx. Env ctx
env :: Env ctx
env = do
  let notImplemented :: Text -> Eval ctx a
      notImplemented :: Text -> Eval ctx a
notImplemented Text
name = EvaluationErrorType ctx -> Eval ctx a
forall x (m :: * -> *) a.
(MonadError (EvaluationError x) m,
 MonadReader (EvaluationContext x) m) =>
EvaluationErrorType x -> m a
throwErrorWithContext (Text -> EvaluationErrorType ctx
forall ctx. Text -> EvaluationErrorType ctx
OtherError (Text
name Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
" is not implemented"))
  
      _ModuleName :: ModuleName
_ModuleName = Text -> ModuleName
ModuleName Text
"Data.String.Regex"
  
  [Env ctx] -> Env ctx
forall (t :: * -> *) m. (Foldable t, Monoid m) => t m -> m
fold
    [ -- showRegexImpl :: Regex -> String
      ModuleName -> Text -> (Value ctx -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Value ctx -> Eval ctx Text)
        ModuleName
_ModuleName Text
"showRegexImpl" 
        \Value ctx
_r -> 
          Text -> Eval ctx Text
forall a. Text -> Eval ctx a
notImplemented Text
"showRegexImpl"
      -- regexImpl
      --   :: (String -> Either String Regex)
      --   -> (Regex -> Either String Regex)
      --   -> String
      --   -> String
      --   -> Either String Regex
    , ModuleName
-> Text
-> ((Value ctx -> Eval ctx (Value ctx))
    -> Text -> Value ctx -> Text -> Eval ctx (Value ctx))
-> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @((Value ctx -> Eval ctx (Value ctx)) -> Text -> Value ctx -> Text -> Eval ctx (Value ctx))
        ModuleName
_ModuleName Text
"regexImpl" 
        \Value ctx -> Eval ctx (Value ctx)
_just Text
_nothing Value ctx
_str Text
_flags ->
          Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"regexImpl"
      -- source :: Regex -> String
    , ModuleName -> Text -> (Value ctx -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Value ctx -> Eval ctx Text)
        ModuleName
_ModuleName Text
"source" 
        \Value ctx
_r -> 
          Text -> Eval ctx Text
forall a. Text -> Eval ctx a
notImplemented Text
"source"
      -- flagsImpl :: Regex -> RegexFlagsRec
    , ModuleName
-> Text -> (Value ctx -> Eval ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Value ctx -> Eval ctx (Value ctx))
        ModuleName
_ModuleName Text
"flagsImpl" 
        \Value ctx
_r -> 
          Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"flagsImpl"
      -- test :: Regex -> String -> Boolean
    , ModuleName
-> Text -> (Value ctx -> Eval ctx (Value ctx)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Value ctx -> Eval ctx (Value ctx))
        ModuleName
_ModuleName Text
"test"
        \Value ctx
_r -> 
          Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"test"
      -- _match
      --   :: (forall r. r -> Maybe r)
      --   -> (forall r. Maybe r)
      --   -> Regex
      --   -> String
      --   -> Maybe (NonEmptyArray (Maybe String))
    , ModuleName
-> Text
-> ((Value ctx -> Eval ctx (Value ctx))
    -> Value ctx -> Value ctx -> Text -> Eval ctx (Value ctx))
-> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @((Value ctx -> Eval ctx (Value ctx)) -> Value ctx -> Value ctx -> Text -> Eval ctx (Value ctx))
        ModuleName
_ModuleName Text
"_match" 
        \Value ctx -> Eval ctx (Value ctx)
_just Value ctx
_nothing Value ctx
_r Text
_str -> 
          Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"_match"
      -- replace :: Regex -> String -> String -> String
    , ModuleName
-> Text -> (Value ctx -> Text -> Text -> Eval ctx Text) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Value ctx -> Text -> Text -> Eval ctx Text)
        ModuleName
_ModuleName Text
"replace" 
        \Value ctx
_r Text
_repl Text
_str ->
          Text -> Eval ctx Text
forall a. Text -> Eval ctx a
notImplemented Text
"replace"
      -- _replaceBy
      --   :: (forall r. r -> Maybe r)
      --   -> (forall r. Maybe r)
      --   -> Regex
      --   -> (String -> Array (Maybe String) -> String)
      --   -> String
      --   -> String
    , ModuleName
-> Text
-> ((Value ctx -> Eval ctx (Value ctx))
    -> Value ctx
    -> Value ctx
    -> (Text -> Vector (Value ctx) -> Eval ctx Text)
    -> Text
    -> Eval ctx Text)
-> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @((Value ctx -> Eval ctx (Value ctx)) -> Value ctx -> Value ctx -> (Text -> Vector (Value ctx) -> Eval ctx Text) -> Text -> Eval ctx Text)
        ModuleName
_ModuleName Text
"_replaceBy" 
        \Value ctx -> Eval ctx (Value ctx)
_just Value ctx
_nothing Value ctx
_r Text -> Vector (Value ctx) -> Eval ctx Text
_f Text
_str ->
          Text -> Eval ctx Text
forall a. Text -> Eval ctx a
notImplemented Text
"_replaceBy"
      -- _search
      --   :: (forall r. r -> Maybe r)
      --   -> (forall r. Maybe r)
      --   -> Regex
      --   -> String
      --   -> Maybe Int
    , ModuleName
-> Text
-> ((Value ctx -> Eval ctx (Value ctx))
    -> Value ctx -> Value ctx -> Text -> Eval ctx (Value ctx))
-> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @((Value ctx -> Eval ctx (Value ctx)) -> Value ctx -> Value ctx -> Text -> Eval ctx (Value ctx))
        ModuleName
_ModuleName Text
"_search" 
        \Value ctx -> Eval ctx (Value ctx)
_just Value ctx
_nothing Value ctx
_r Text
_str ->
          Text -> Eval ctx (Value ctx)
forall a. Text -> Eval ctx a
notImplemented Text
"_search"
      -- split :: Regex -> String -> Array String
    , ModuleName
-> Text -> (Value ctx -> Text -> Eval ctx (Vector Text)) -> Env ctx
forall ctx a. ToValue ctx a => ModuleName -> Text -> a -> Env ctx
builtIn @ctx @(Value ctx -> Text -> Eval ctx (Vector Text))
        ModuleName
_ModuleName Text
"split" 
        \Value ctx
_r Text
_str -> 
          Text -> Eval ctx (Vector Text)
forall a. Text -> Eval ctx a
notImplemented Text
"split"
    ]