Skip to content

Commit

Permalink
Revert types from #13552 (#13645)
Browse files Browse the repository at this point in the history
  • Loading branch information
sabiwara authored Jun 6, 2024
1 parent cabd7d8 commit 8ca99ab
Showing 1 changed file with 8 additions and 33 deletions.
41 changes: 8 additions & 33 deletions lib/elixir/lib/regex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,27 +186,7 @@ defmodule Regex do

defstruct re_pattern: nil, source: "", opts: [], re_version: ""

@type re_option ::
:unicode
| :caseless
| :dotall
| :multiline
| :extended
| :firstline
| :ungreedy
| :anchored
| :dollar_endonly
| :no_auto_capture
| :newline

@type t :: %__MODULE__{re_pattern: term, source: binary, opts: binary | [re_option()]}

@type capture_option ::
:all | :first | :all_but_first | :none | :all_names | [binary() | atom()]
@type run_option ::
{:return, :binary | :index}
| {:capture, capture_option()}
| {:offset, non_neg_integer()}
@type t :: %__MODULE__{re_pattern: term, source: binary, opts: binary | [term]}

defmodule CompileError do
@moduledoc """
Expand Down Expand Up @@ -242,7 +222,7 @@ defmodule Regex do
{:ok, Regex.compile!("foo", [:caseless])}
"""
@spec compile(binary, binary | [re_option()]) :: {:ok, t} | {:error, any}
@spec compile(binary, binary | [term]) :: {:ok, t} | {:error, any}
def compile(source, opts \\ "") when is_binary(source) do
compile(source, opts, version())
end
Expand Down Expand Up @@ -270,7 +250,7 @@ defmodule Regex do
@doc """
Compiles the regular expression and raises `Regex.CompileError` in case of errors.
"""
@spec compile!(binary, binary | [re_option()]) :: t
@spec compile!(binary, binary | [term]) :: t
def compile!(source, options \\ "") when is_binary(source) do
case compile(source, options) do
{:ok, regex} -> regex
Expand Down Expand Up @@ -377,7 +357,7 @@ defmodule Regex do
["d", ""]
"""
@spec run(t, binary, [run_option()]) :: nil | [binary] | [{integer, integer}]
@spec run(t, binary, [term]) :: nil | [binary] | [{integer, integer}]
def run(regex, string, options \\ [])

def run(%Regex{} = regex, string, options) when is_binary(string) do
Expand Down Expand Up @@ -412,7 +392,7 @@ defmodule Regex do
nil
"""
@spec named_captures(t, String.t(), [{:return, :binary | :index}]) :: map | nil
@spec named_captures(t, String.t(), [term]) :: map | nil
def named_captures(regex, string, options \\ []) when is_binary(string) do
names = names(regex)
options = Keyword.put(options, :capture, names)
Expand Down Expand Up @@ -456,7 +436,7 @@ defmodule Regex do
[:caseless]
"""
@spec opts(t) :: [re_option()]
@spec opts(t) :: [term]
def opts(%Regex{opts: opts}) do
opts
end
Expand Down Expand Up @@ -528,7 +508,7 @@ defmodule Regex do
[["cd"], ["ce"]]
"""
@spec scan(t(), String.t(), [run_option()]) :: [[String.t()]] | [[{integer(), integer()}]]
@spec scan(t(), String.t(), [term()]) :: [[String.t()]] | [[{integer(), integer()}]]
def scan(regex, string, options \\ [])

def scan(%Regex{} = regex, string, options) when is_binary(string) do
Expand Down Expand Up @@ -615,12 +595,7 @@ defmodule Regex do
["a", "b", "c"]
"""
@spec split(t, String.t(),
parts: pos_integer() | :infinity,
trim: boolean(),
on: capture_option(),
include_captures: boolean()
) :: [String.t()]
@spec split(t, String.t(), [term]) :: [String.t()]
def split(regex, string, options \\ [])

def split(%Regex{}, "", opts) do
Expand Down

0 comments on commit 8ca99ab

Please sign in to comment.