<commit_before>module Data.String.Regex (
  Regex(..),
  RegexFlags(..),
  regex,
  source,
  flags,
  renderFlags,
  parseFlags,
  test,
  match,
  replace,
  replace',
  search
  ) where

import Data.String (indexOf)

foreign import data Regex :: *

foreign import showRegex'
  "function showRegex$prime(r){\
  \  return '' + r;\
  \}" :: Regex -> String

instance showRegex :: Show Regex where
  show = showRegex'

type RegexFlags =
  { global :: Boolean
  , ignoreCase :: Boolean
  , multiline :: Boolean
  , sticky :: Boolean
  , unicode :: Boolean
  }

foreign import regex'
  "function regex$prime(s1) {\
  \  return function(s2) {\
  \    return new RegExp(s1, s2);\
  \  };\
  \}" :: String -> String -> Regex

regex :: String -> RegexFlags -> Regex
regex source flags = regex' source $ renderFlags flags

foreign import source
  "function source(r) {\
  \  return r.source;\
  \}" :: Regex -> String

foreign import flags
  "function source(r) {\
  \  return {\
  \    multiline: r.multiline,\
  \    ignoreCase: r.ignoreCase,\
  \    global: r.global,\
  \    sticky: !!r.sticky,\
  \    unicode: !!r.unicode\
  \  };\
  \}" :: Regex -> RegexFlags<commit_msg>Fix typo in FFI definition for flags<commit_after>module Data.String.Regex (
  Regex(..),
  RegexFlags(..),
  regex,
  source,
  flags,
  renderFlags,
  parseFlags,
  test,
  match,
  replace,
  replace',
  search
  ) where

import Data.String (indexOf)

foreign import data Regex :: *

foreign import showRegex'
  "function showRegex$prime(r){\
  \  return '' + r;\
  \}" :: Regex -> String

instance showRegex :: Show Regex where
  show = showRegex'

type RegexFlags =
  { global :: Boolean
  , ignoreCase :: Boolean
  , multiline :: Boolean
  , sticky :: Boolean
  , unicode :: Boolean
  }

foreign import regex'
  "function regex$prime(s1) {\
  \  return function(s2) {\
  \    return new RegExp(s1, s2);\
  \  };\
  \}" :: String -> String -> Regex

regex :: String -> RegexFlags -> Regex
regex source flags = regex' source $ renderFlags flags

foreign import source
  "function source(r) {\
  \  return r.source;\
  \}" :: Regex -> String

foreign import flags
  "function flags(r) {\
  \  return {\
  \    multiline: r.multiline,\
  \    ignoreCase: r.ignoreCase,\
  \    global: r.global,\
  \    sticky: !!r.sticky,\
  \    unicode: !!r.unicode\
  \  };\
  \}" :: Regex -> RegexFlags
{'fraction_non_alphanumeric': 0.14987298899237933, 'fraction_numerical': 0.003386960203217612, 'mean_word_length': 2.6186830015313936, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2981936', 'n_tokens_mistral': 835, 'n_tokens_neox': 800, 'n_words': 209}