Skip to content

Commit

Permalink
Fix Regex support
Browse files Browse the repository at this point in the history
  • Loading branch information
jdunkerley committed Feb 9, 2022
1 parent 7600a1e commit 6f626cd
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
17 changes: 10 additions & 7 deletions distribution/lib/Standard/Table/0.0.0-dev/src/Data/Matching.enso
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ type Matching_Strategy
A name is matched if its name matches the provided regular expression.
type Regex (case_sensitivity : (True | Case_Insensitive) = True)


## ADVANCED
Compiles the regular expression following the Matching_Strategy rules.
compile : Text -> Regex_Module.Pattern
Expand All @@ -29,8 +28,9 @@ type Matching_Strategy
insensitive = case this.case_sensitivity of
True -> False
Case_Insensitive -> True
Regex_Module.compile criterion case_insensitive=insensitive
_ -> Error.throw "Invalid Matching_Strategy to compile"
re = Regex_Module.compile criterion case_insensitive=insensitive
re
Exact _ -> Error.throw "Invalid Matching_Strategy to compile"


## UNSTABLE
Expand All @@ -44,6 +44,7 @@ type Matching_Strategy
Exact.new : (True | Case_Insensitive) -> Exact
Exact.new (case_sensitivity = True) = Exact case_sensitivity


## UNSTABLE
A temporary workaround to allow the `Regex` constructor to work with default
arguments.
Expand Down Expand Up @@ -182,7 +183,9 @@ match_criteria objects criteria reorder=False name_mapper=(x->x) matching_strate
Matching.match_single_criterion "Foobar" "f.*" (Regex case_sensitivity=Case_Insensitive) == True
match_single_criterion : Text -> Text -> Matching_Strategy -> Boolean
match_single_criterion name criterion matching_strategy = case matching_strategy of
Exact case_sensitivity -> case case_sensitivity of
True -> name == criterion
Case_Insensitive -> name.equals_ignore_case criterion
Regex _ -> matching_strategy.compile . matches name
Exact case_sensitivity ->
case case_sensitivity of
True -> name == criterion
Case_Insensitive -> name.equals_ignore_case criterion
Regex _ ->
matching_strategy.compile criterion . matches name
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ rename_columns internal_columns mapping on_problems warnings =
new_name = case ms of
Matching.Regex _ ->
pattern = ms.compile ((good_names.at index).at 0)
pattern.replace name (good_names.at index).at 1
pattern.replace name ((good_names.at index).at 1)
_ -> (good_names.at index).at 1
unique.make_unique new_name

Expand Down

0 comments on commit 6f626cd

Please sign in to comment.