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 upRegex, runtime error #378
Comments
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
eeue56
Aug 29, 2015
Contributor
I think it makes sense for regex to be regex : String -> Result String Regex here, so that the error message is captured.
If it's okay, I'll make a pull request for this so that it can be merged if it's approved.
|
I think it makes sense for regex to be |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Aug 29, 2015
Contributor
Yeah, it's either that or keep the runtime error. Most regexes won't be generated dynamically (in signals or functions), so there's a case for keeping the runtime error since it will be easier to work with the absence of a Result or Maybe. (We seem to be getting useful error messages, so I support a Result in the API.)
|
Yeah, it's either that or keep the runtime error. Most regexes won't be generated dynamically (in signals or functions), so there's a case for keeping the runtime error since it will be easier to work with the absence of a Result or Maybe. (We seem to be getting useful error messages, so I support a Result in the API.) |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
rtfeldman
Aug 30, 2015
Member
In the spirit of these guidelines I've made a gist for a potentially interesting solution to this. Any discussion of that idea is welcome over on the gist itself, but let's not derail this issue with that stuff.
|
In the spirit of these guidelines I've made a gist for a potentially interesting solution to this. Any discussion of that idea is welcome over on the gist itself, but let's not derail this issue with that stuff. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
jvoigtlaender
Aug 30, 2015
Contributor
Is this "the same" as https://github.com/elm-lang/core/issues/157? Should we close that other issue, then?
|
Is this "the same" as https://github.com/elm-lang/core/issues/157? Should we close that other issue, then? |
rtfeldman
referenced this issue
Aug 30, 2015
Closed
Crash when using an invalid regular expression #157
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
eeue56
Aug 30, 2015
Contributor
I've created #380 that will change regex to return a Result instead, but I think it needs further discussion before merging. Having to use case..of everywhere doesn't quite fit right.
Perhaps leaving regex as it's own function and introducing safeRegex : String -> Result String Regex might be a better solution, with regex intended for static expressions and safeRegex for dynamic ones.
This would remove the need to introduce a new syntax as per rtfeldman's gist, though leave a runtime error possible.
|
I've created #380 that will change Perhaps leaving This would remove the need to introduce a new syntax as per rtfeldman's gist, though leave a runtime error possible. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
DemiMarie
Dec 19, 2015
Regex literals might be a solution. That way invalid regexps are a compile time error
DemiMarie
commented
Dec 19, 2015
|
Regex literals might be a solution. That way invalid regexps are a compile time error |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
mgold
Dec 20, 2015
Contributor
That's been brought up before, and I agree would be a good solution. But it involves a compiler change, and you'd have to validate JS regexes in Haskell.
|
That's been brought up before, and I agree would be a good solution. But it involves a compiler change, and you'd have to validate JS regexes in Haskell. |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
tmcw
Jul 10, 2016
For my (admittedly rare) usecase, I'm creating regular expressions based on user input, in order to filter a list and extract results with matching groups - so unfortunately a literal syntax only would make that usecase more difficult - right now I'm porting from a JavaScript version which uses new RegExp(variable) in order to create regular expressions on the fly.
Returning a Maybe Regex would fit my usage perfectly, though I understand if that's not the most common way people interact with regular expressions.
tmcw
commented
Jul 10, 2016
|
For my (admittedly rare) usecase, I'm creating regular expressions based on user input, in order to filter a list and extract results with matching groups - so unfortunately a literal syntax only would make that usecase more difficult - right now I'm porting from a JavaScript version which uses Returning a |
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
|
Consolidated regex stuff in #722. Follow along there! |
evancz
closed this
Sep 22, 2016
This comment has been minimized.
Show comment
Hide comment
This comment has been minimized.
evancz
Jul 8, 2017
Member
The plan is to move regular expressions to elm-lang/regexp or something, and it will have something like this:
fromString : String -> Result String RegExpAs seen here: https://github.com/evancz/regexp/blob/master/src/RegExp.elm#L44
|
The plan is to move regular expressions to fromString : String -> Result String RegExpAs seen here: https://github.com/evancz/regexp/blob/master/src/RegExp.elm#L44 |
gunpinyo commentedAug 29, 2015
In core package, module Regex
This function can produce runtime error if string contain invalid pattern.
Here is an example form elm-repl
It would be better if we change regex to be
it will return
Nothingif string contains invalid pattern.