Skip to content

Commit

Permalink
re: Rework option types
Browse files Browse the repository at this point in the history
  • Loading branch information
garazdawi committed Jan 23, 2024
1 parent 7445e4e commit eb4a9c1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 14 deletions.
8 changes: 8 additions & 0 deletions lib/stdlib/doc/src/re.xml
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,14 @@
<name name="nl_spec"/>
</datatype>
<datatype>
<name name="compile_options"/>
<name name="compile_option"/>
</datatype>
<datatype>
<name name="options"/>
<name name="option"/>
<name name="capture"/>
</datatype>
<datatype>
<name name="replace_fun"/>
</datatype>
Expand Down Expand Up @@ -454,6 +460,8 @@ re:replace("abcd", ".(.)", fun(Whole, [&lt;&lt;C&gt;&gt;]) -> &lt;&lt;$#, Whole/
subpatterns.</fsummary>
<type_desc variable="CompileOpt">See <seeerl marker="#compile_options">
<c>compile/2</c></seeerl>.</type_desc>
<type name="option"/>
<type name="capture"/>
<desc>
<p>Executes a regular expression matching, and returns
<c>match/{match, <anno>Captured</anno>}</c> or <c>nomatch</c>. The
Expand Down
31 changes: 17 additions & 14 deletions lib/stdlib/src/re.erl
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,33 @@
-module(re).
-export([grun/3,urun/3,ucompile/2,replace/3,replace/4,split/2,split/3]).

-export_type([mp/0, compile_options/0, options/0]).

-type mp() :: {re_pattern, _, _, _, _}.

-type nl_spec() :: cr | crlf | lf | anycrlf | any.

-type compile_options() :: [compile_option()].
-type compile_option() :: unicode | anchored | caseless | dollar_endonly
| dotall | extended | firstline | multiline
| no_auto_capture | dupnames | ungreedy
| {newline, nl_spec()}
| bsr_anycrlf | bsr_unicode
| no_start_optimize | ucp | never_utf.

-type options() :: [option()].
-type option() :: anchored | global | notbol | noteol | notempty |
notempty_atstart | report_errors |
{offset, non_neg_integer()} |
{match_limit, non_neg_integer()} |
{match_limit_recursion, non_neg_integer()} |
{newline, NLSpec :: nl_spec()} |
bsr_anycrlf | bsr_unicode | {capture, ValueSpec :: capture()} |
{capture, ValueSpec :: capture(), Type :: index | list | binary} |
compile_option().
-type capture() :: all | all_but_first | all_names | first | none |
ValueList :: [integer() | string() | atom()].

-type replace_fun() :: fun((binary(), [binary()]) -> iodata() | unicode:charlist()).

%%% BIFs
Expand Down Expand Up @@ -81,20 +97,7 @@ run(_, _) ->
{error, ErrType} when
Subject :: iodata() | unicode:charlist(),
RE :: mp() | iodata() | unicode:charlist(),
Options :: [Option],
Option :: anchored | global | notbol | noteol | notempty
| notempty_atstart | report_errors
| {offset, non_neg_integer()} |
{match_limit, non_neg_integer()} |
{match_limit_recursion, non_neg_integer()} |
{newline, NLSpec :: nl_spec()} |
bsr_anycrlf | bsr_unicode | {capture, ValueSpec} |
{capture, ValueSpec, Type} | CompileOpt,
Type :: index | list | binary,
ValueSpec :: all | all_but_first | all_names | first | none | ValueList,
ValueList :: [ValueID],
ValueID :: integer() | string() | atom(),
CompileOpt :: compile_option(),
Options :: options(),
Captured :: [CaptureData] | [[CaptureData]],
CaptureData :: {integer(), integer()}
| ListConversionData
Expand Down

0 comments on commit eb4a9c1

Please sign in to comment.