Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Regex t:compile_option/0 to reflect :re #13643

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 23 additions & 10 deletions lib/elixir/lib/regex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -186,23 +186,36 @@ defmodule Regex do

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

@type re_option ::
@typedoc since: "1.17.0"
@type nl_spec() :: :cr | :crlf | :lf | :anycrlf | :any

@typedoc since: "1.17.0"
@type compile_option ::
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also renamed since it's been introduced in 1.17, and I think it's clearer + matches :re's.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If it was introduced in 1.17.0, maybe we should remove them for now. Erlang said they will change the RE engine for OTP 28, so any of those options may no longer be supported in a year. So perhaps we should remove those for now and backport?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh, do you think they'll break backwards compatibility?
This is a shame, these specs really help figuring out what the types are.

How about:

  • keeping compile_option :: term and run_option :: term just to make the intent and distinction clear
  • perhaps add a link to erlang's doc for options in typedoc

:unicode
| :anchored
| :caseless
| :dollar_endonly
| :dotall
| :multiline
| :extended
| :firstline
| :ungreedy
| :anchored
| :dollar_endonly
| :multiline
| :no_auto_capture
| :newline
| :dupnames
| :ungreedy
| {:newline, nl_spec()}
| :bsr_anycrlf
| :bsr_unicode
| :no_start_optimize
| :ucp
| :never_utf

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

@typedoc since: "1.17.0"
@type capture_option ::
:all | :first | :all_but_first | :none | :all_names | [binary() | atom()]

@typedoc since: "1.17.0"
@type run_option ::
{:return, :binary | :index}
| {:capture, capture_option()}
Expand Down Expand Up @@ -242,7 +255,7 @@ defmodule Regex do
{:ok, Regex.compile!("foo", [:caseless])}

"""
@spec compile(binary, binary | [re_option()]) :: {:ok, t} | {:error, any}
@spec compile(binary, binary | [compile_option()]) :: {:ok, t} | {:error, any}
def compile(source, opts \\ "") when is_binary(source) do
compile(source, opts, version())
end
Expand Down Expand Up @@ -270,7 +283,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 | [compile_option()]) :: t
def compile!(source, options \\ "") when is_binary(source) do
case compile(source, options) do
{:ok, regex} -> regex
Expand Down Expand Up @@ -456,7 +469,7 @@ defmodule Regex do
[:caseless]

"""
@spec opts(t) :: [re_option()]
@spec opts(t) :: [compile_option()]
def opts(%Regex{opts: opts}) do
opts
end
Expand Down