Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.
Sign upChange regex to return Result #380
Conversation
eeue56
added some commits
Aug 30, 2015
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rtfeldman
Jan 2, 2016
Member
The more I think about it, the more I like this idea. You can use it to implement the current behavior by using Debug.crash to handle the Err case, which could be offered as a convenience function like regexOrCrash
|
The more I think about it, the more I like this idea. You can use it to implement the current behavior by using |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Yeah, that's true. I like the |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Has any more thought been given to making this change? |
tmcw
reviewed
Jul 11, 2016
| try | ||
| { | ||
| compiledRegex = new RegExp(raw, 'g'); |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tmcw
Jul 11, 2016
minor nitpick that you could express this more succinctly as
return Result.Ok(new RegExp(raw, 'g'));Here, and avoid using the temporary variable - the code would have the same behavior since new RegExp(raw, 'g') is evaluated first, would throw, and not instantiate a Result.Ok
tmcw
Jul 11, 2016
minor nitpick that you could express this more succinctly as
return Result.Ok(new RegExp(raw, 'g'));Here, and avoid using the temporary variable - the code would have the same behavior since new RegExp(raw, 'g') is evaluated first, would throw, and not instantiate a Result.Ok
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tmcw
Jul 11, 2016
Yep, as I posted on the other ticket, I 2nd this approach as flexible and lower-impact than a syntax extension.
tmcw
commented
Jul 11, 2016
•
|
Yep, as I posted on the other ticket, I 2nd this approach as flexible and lower-impact than a syntax extension. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
seanhess
Sep 10, 2016
This would be very helpful to me for the project I am currently working on. Right now we are blocked without it.
seanhess
commented
Sep 10, 2016
|
This would be very helpful to me for the project I am currently working on. Right now we are blocked without it. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
eeue56
Sep 10, 2016
Contributor
@seanhess here's how to unblock you:
- Create a function that looks like this:
var isValidRegex = function(regex, modifiers){
try {
new RegExp(regex, modifiers);
} catch (e) {
return [regex, false];
}
return [regex, true];
}- Make a port that looks like
validateRegex : Cmd String - Make a port that looks like
isValidRegex : Sub (String, Bool)
If you really want, it's trivial to introduce this as a native function into your project. Don't let yourself get blocked on this! it's a trivial issue to solve :)
|
@seanhess here's how to unblock you:
var isValidRegex = function(regex, modifiers){
try {
new RegExp(regex, modifiers);
} catch (e) {
return [regex, false];
}
return [regex, true];
}
If you really want, it's trivial to introduce this as a native function into your project. Don't let yourself get blocked on this! it's a trivial issue to solve :) |
jvoigtlaender
referenced this pull request
Sep 16, 2016
Closed
Catch runtime error when creating a Regex from an invalid expression #713
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
seanhess
Sep 19, 2016
@eeue56 ssh, you're removing the imperative to get this merged ;D
Thanks though, that's a great workaround! I forget that native modules are an option for end applications since they can't be published.
seanhess
commented
Sep 19, 2016
|
@eeue56 ssh, you're removing the imperative to get this merged ;D Thanks though, that's a great workaround! I forget that native modules are an option for end applications since they can't be published. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Sep 22, 2016
Member
Tracking in #722. These changes are quite easy, so I don't think a PR is needed. Just need to figure out the appropriate time to actually make a change like this.
|
Tracking in #722. These changes are quite easy, so I don't think a PR is needed. Just need to figure out the appropriate time to actually make a change like this. |
eeue56 commentedAug 30, 2015
Changed the
Regex.regexfunction to return aResultas per #378 and updated and added tests to this effect. I haven't changed any of the documentation for any other function in Regex.elm, as I feel that rtfeldman's comment on providing a built-in regex syntax needs to be discussed further - certainly it makes code more bulky and there is no way to create aRegexwithout theregexfunction.