Skip to content

Commit

Permalink
Rename Standard.Base.Data.Text.Regex.Mode to Regex_Mode (#3713)
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd authored Sep 16, 2022
1 parent 5ed3889 commit ca950fb
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 75 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from Standard.Base import all

import Standard.Base.Data.Text.Regex
import Standard.Base.Data.Text.Regex.Mode

import Standard.Base.Data.Text.Matching_Mode
import Standard.Base.Data.Text.Case
Expand Down Expand Up @@ -158,9 +157,10 @@ Text.characters self =
- pattern: The pattern to match `self` against. We recommend using _raw text_
to write your patterns.
- mode: This argument specifies how many matches the engine will try and
find. When mode is set to either `Mode.First` or `Mode.Full`, this method
will return either a single `Match` or `Nothing`. If set to an `Integer` or
`Mode.All`, this method will return either a `Vector Match` or `Nothing`.
find. When mode is set to either `Regex_Mode.First` or `Regex_Mode.Full`,
this method will return either a single `Match` or `Nothing`. If set to an
`Integer` or `Regex_Mode.All`, this method will return either
a `Vector Match` or `Nothing`.
- match_ascii: Enables or disables pure-ASCII matching for the regex. If you
know your data only contains ASCII then you can enable this for a
performance boost on some regex engines.
Expand Down Expand Up @@ -206,8 +206,8 @@ Text.characters self =
example_match =
regex = ".+@.+"
"[email protected]".match regex
Text.match : Text | Engine.Pattern -> Mode.Mode -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Match | Vector.Vector Match | Nothing ! Regex.Compile_Error
Text.match self pattern mode=Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] =
Text.match : Text | Engine.Pattern -> (Regex_Mode | Matching_Mode) -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Match | Vector.Vector Match | Nothing ! Regex.Compile_Error
Text.match self pattern mode=Regex_Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] =
compiled_pattern = Regex.compile pattern match_ascii=match_ascii case_insensitive=case_insensitive dot_matches_newline=dot_matches_newline multiline=multiline comments=comments extra_opts=extra_opts
compiled_pattern.match self mode

Expand All @@ -220,9 +220,10 @@ Text.match self pattern mode=Mode.All match_ascii=Nothing case_insensitive=Nothi
- pattern: The pattern to match `self` against. We recommend using _raw text_
to write your patterns.
- mode: This argument specifies how many matches the engine will try and
find. When mode is set to either `Mode.First` or `Mode.Full`, this method
will return either a single `Match` or `Nothing`. If set to an `Integer` or
`Mode.All`, this method will return either a `Vector Match` or `Nothing`.
find. When mode is set to either `Regex_Mode.First` or `Regex_Mode.Full`,
this method will return either a single `Match` or `Nothing`. If set to an
`Integer` or `Regex_Mode.All`, this method will return either
a `Vector Match` or `Nothing`.
- match_ascii: Enables or disables pure-ASCII matching for the regex. If you
know your data only contains ASCII then you can enable this for a
performance boost on some regex engines.
Expand Down Expand Up @@ -282,9 +283,10 @@ Text.matches self pattern match_ascii=Nothing case_insensitive=Nothing dot_match
- pattern: The pattern to match `self` against. We recommend using _raw text_
to write your patterns.
- mode: This argument specifies how many matches the engine will try and
find. When mode is set to either `Mode.First` or `Mode.Full`, this method
will return either a single `Text` or `Nothing`. If set to an `Integer` or
`Mode.All`, this method will return either a `Vector Text` or `Nothing`.
find. When mode is set to either `Regex_Mode.First` or `Regex_Mode.Full`,
this method will return either a single `Text` or `Nothing`. If set to an
`Integer` or `Regex_Mode.All`, this method will return either
a `Vector Text` or `Nothing`.
- match_ascii: Enables or disables pure-ASCII matching for the regex. If you
know your data only contains ASCII then you can enable this for a
performance boost on some regex engines.
Expand Down Expand Up @@ -329,8 +331,8 @@ Text.matches self pattern match_ascii=Nothing case_insensitive=Nothing dot_match
example_find =
text = "Now I know my ABCs"
text.find "\w{1,3}"
Text.find : Text | Engine.Pattern -> Mode.Mode -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Text | Vector.Vector Text | Nothing
Text.find self pattern mode=Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] =
Text.find : Text | Engine.Pattern -> (Regex_Mode | Matching_Mode) -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Boolean | Nothing -> Vector.Vector Option.Option -> Text | Vector.Vector Text | Nothing
Text.find self pattern mode=Regex_Mode.All match_ascii=Nothing case_insensitive=Nothing dot_matches_newline=Nothing multiline=Nothing comments=Nothing extra_opts=[] =
compiled_pattern = Regex.compile pattern match_ascii=match_ascii case_insensitive=case_insensitive dot_matches_newline=dot_matches_newline multiline=multiline comments=comments extra_opts=extra_opts
compiled_pattern.find self mode

Expand Down Expand Up @@ -378,7 +380,7 @@ Text.split self delimiter="," matcher=Text_Matcher_Data = if delimiter.is_empty
Text_Utils.substring self start end
Regex_Matcher_Data _ _ _ _ _ ->
compiled_pattern = matcher.compile delimiter
compiled_pattern.split self mode=Mode.All
compiled_pattern.split self mode=Regex_Mode.All

## ALIAS Replace Text
Replaces the first, last, or all occurrences of term with new_text in the
Expand Down Expand Up @@ -456,30 +458,32 @@ Text.split self delimiter="," matcher=Text_Matcher_Data = if delimiter.is_empty
"aaa aaa".replace "aa" "c" matcher=Regex_Matcher . should_equal "ca ca"
"aaa aaa".replace "aa" "c" mode=Matching_Mode.First matcher=Regex_Matcher . should_equal "ca aaa"
"aaa aaa".replace "aa" "c" mode=Matching_Mode.Last matcher=Regex_Matcher . should_equal "aaa ca"
Text.replace : Text -> Text -> (Matching_Mode.First | Matching_Mode.Last | Mode.All) -> (Text_Matcher | Regex_Matcher) -> Text
Text.replace self term="" new_text="" mode=Mode.All matcher=Text_Matcher_Data = if term.is_empty then self else
Text.replace : Text -> Text -> Matching_Mode | Regex_Mode -> (Text_Matcher | Regex_Matcher) -> Text
Text.replace self term="" new_text="" mode=Regex_Mode.All matcher=Text_Matcher_Data = if term.is_empty then self else
case matcher of
Text_Matcher_Data case_sensitivity ->
array_from_single_result result = case result of
Nothing -> Array.empty
_ -> Array.new_1 result
spans_array = case case_sensitivity of
True -> case mode of
Mode.All ->
Regex_Mode.All ->
Text_Utils.span_of_all self term
Matching_Mode.First ->
array_from_single_result <| Text_Utils.span_of self term
Matching_Mode.Last ->
array_from_single_result <| Text_Utils.last_span_of self term
_ -> Error.throw (Illegal_Argument_Error_Data "Invalid mode.")
Case_Insensitive_Data locale -> case mode of
Mode.All ->
Regex_Mode.All ->
Text_Utils.span_of_all_case_insensitive self term locale.java_locale
Matching_Mode.First ->
array_from_single_result <|
Text_Utils.span_of_case_insensitive self term locale.java_locale False
Matching_Mode.Last ->
array_from_single_result <|
Text_Utils.span_of_case_insensitive self term locale.java_locale True
_ -> Error.throw (Illegal_Argument_Error_Data "Invalid mode.")
Text_Utils.replace_spans self spans_array new_text
Regex_Matcher_Data _ _ _ _ _ ->
compiled_pattern = matcher.compile term
Expand Down Expand Up @@ -903,7 +907,7 @@ Text.starts_with self prefix matcher=Text_Matcher_Data = case matcher of
Regex_Matcher_Data _ _ _ _ _ ->
preprocessed_pattern = "\A(?:" + prefix + ")"
compiled_pattern = matcher.compile preprocessed_pattern
match = compiled_pattern.match self Mode.First
match = compiled_pattern.match self Regex_Mode.First
match.is_nothing.not

## ALIAS Check Suffix
Expand Down Expand Up @@ -940,7 +944,7 @@ Text.ends_with self suffix matcher=Text_Matcher_Data = case matcher of
Regex_Matcher_Data _ _ _ _ _ ->
preprocessed_pattern = "(?:" + suffix + ")\z"
compiled_pattern = matcher.compile preprocessed_pattern
match = compiled_pattern.match self Mode.First
match = compiled_pattern.match self Regex_Mode.First
match.is_nothing.not

## ALIAS Contains
Expand Down Expand Up @@ -1002,7 +1006,7 @@ Text.contains self term="" matcher=Text_Matcher_Data = case matcher of
Text_Utils.contains_case_insensitive self term locale.java_locale
Regex_Matcher_Data _ _ _ _ _ ->
compiled_pattern = matcher.compile term
match = compiled_pattern.match self Mode.First
match = compiled_pattern.match self Regex_Mode.First
match.is_nothing.not

## Text to JSON conversion.
Expand Down Expand Up @@ -1405,11 +1409,11 @@ Text.location_of self term="" mode=Matching_Mode.First matcher=Text_Matcher_Data
Span_Data (Range_Data grapheme_span.grapheme_start grapheme_span.grapheme_end) self
Regex_Matcher_Data _ _ _ _ _ -> case mode of
Matching_Mode.First ->
case matcher.compile term . match self Mode.First of
case matcher.compile term . match self Matching_Mode.First of
Nothing -> Nothing
match -> match.span 0 . to_grapheme_span
Matching_Mode.Last ->
case matcher.compile term . match self Mode.All of
case matcher.compile term . match self Regex_Mode.All of
Nothing -> Nothing
matches -> matches.last.span 0 . to_grapheme_span

Expand Down Expand Up @@ -1496,7 +1500,7 @@ Text.location_of_all self term="" matcher=Text_Matcher_Data = case matcher of
grapheme_spans.map grapheme_span->
Span_Data (Range_Data grapheme_span.grapheme_start grapheme_span.grapheme_end) self
Regex_Matcher_Data _ _ _ _ _ ->
case matcher.compile term . match self Mode.All of
case matcher.compile term . match self Regex_Mode.All of
Nothing -> []
matches -> matches.map m-> m.span 0 . to_grapheme_span

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ from Standard.Base import all
import Standard.Base.Data.Text.Regex
import Standard.Base.Data.Text.Regex.Engine
import Standard.Base.Data.Text.Regex.Engine.Default as Default_Engine
import Standard.Base.Data.Text.Regex.Mode
import Standard.Base.Data.Text.Regex.Option

## Compile the provided `expression` into a regex pattern that can be used for
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ type Pattern

Arguments:
- input: The text to match the pattern described by `self` against.
- mode: The matching mode to use. This must default to `Mode.All`.
- mode: The matching mode to use. This must default to `Regex_Mode.All`.

This method will _always_ return `Nothing` if it fails to match.

Expand All @@ -65,7 +65,7 @@ type Pattern
return type is either a single `Match` object. When asked to match in a
mode that permits multiple matches, it will always return a `Vector`,
even if only a single match is found.
match : Text -> Mode.Mode -> Match | Vector.Vector Match | Nothing
match : Text -> (Regex_Mode | Matching_Mode) -> Match | Vector.Vector Match | Nothing
match self _ _ = Errors.unimplemented "This is an interface only."

## PRIVATE
Expand All @@ -85,7 +85,7 @@ type Pattern

Arguments:
- input: The text to find matches in.
- mode: The matching mode to use. This must default to `Mode.All`
- mode: The matching mode to use. This must default to `Regex_Mode.All`

This method will _always_ return `Nothing` if it fails to find any
matches.
Expand All @@ -95,7 +95,7 @@ type Pattern
return type is either a single `Match` object. When asked to match in a
mode that permits multiple matches, it will always return a `Vector`,
even if only a single match is found.
find : Text -> Mode.Mode -> Text | Vector.Vector Text | Nothing
find : Text -> (Regex_Mode | Matching_Mode) -> Text | Vector.Vector Text | Nothing
find self _ _ = Errors.unimplemented "This is an interface only."

## PRIVATE
Expand All @@ -104,11 +104,11 @@ type Pattern

Arguments:
- input: The text to splut based on the pattern described by `self`.
- mode: The splitting mode to use. This must default to `Mode.All`.
- mode: The splitting mode to use. This must default to `Regex_Mode.All`.

This method will _always_ return a vector. If no splits take place, the
vector will contain a single element.
split : Text -> (Mode.First | Integer | Mode.All) -> Vector.Vector Text
split : Text -> (Regex_Mode.First | Integer | Regex_Mode.All) -> Vector.Vector Text
split self _ _ = Errors.unimplemented "This is an interface only."

## PRIVATE
Expand All @@ -120,11 +120,11 @@ type Pattern
- input: The text in which to perform the replacement(s).
- replacement: The literal text with which to replace any matches.
- mode: The matching mode to use for finding candidates to replace. This
must default to `Mode.All`.
must default to `Regex_Mode.All`.

If this method performs no replacements it will return the `input` text
unchanged.
replace : Text -> Text -> (Mode.First | Integer | Mode.All | Mode.Full) -> Text
replace : Text -> Text -> Regex_Mode | Matching_Mode | Integer -> Text
replace self _ _ _ = Errors.unimplemented "This is an interface only."

## The `Data.Text.Regex.Engine.Match` interface.
Expand Down
Loading

0 comments on commit ca950fb

Please sign in to comment.