You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
(I imagine that this fix would likely be made in elm/core, but I thought it would be more appropriate here. Feel free to move the issue)
Problem
I was just in the middle of debugging why a string didn't match a regex, and I tried Debug.logging the regex, which gave me {}, which I found to be very unhelpful.
Creating a regex inside the Elm REPL gives the same behavior:
I expected to see some kind of information in the log message to see what the regex is. The Node.js REPL gives the following feedback, which I believe is more helpful:
> /hello/
/hello/
> new RegExp("hello", "ig")
/hello/gi
Suggested solution
I suggest that elm/core's _Debug_toAnsiString function adds a special-case for regexes to print the regex in a useful way.
I feel like the format of the stringified version aims to be somewhat copy-pastable into Elm code (seeing examples like Dict.fromList), which makes this format a tiny bit tricky. Ideally, the format of the regex should probably be the "JavaScript regex format" (/hello/gi), but that wouldn't be valid Elm code.
A second option would be to print the code needed to create the Regex from Elm code (Regex.fromString "hello") but that would have 2 drawbacks:
The code would not be copy-pastable, because there is no function that directly creates a regex without wrapping it in a Maybe.
You'd need to add backslashes (/"hello"/ -> Regex.fromString "\"hello\""), which makes the regex harder to read, which might be counterproductive when the intent of the Debug.logging was to make it clearer what the regex is.
The text was updated successfully, but these errors were encountered:
(I imagine that this fix would likely be made in
elm/core
, but I thought it would be more appropriate here. Feel free to move the issue)Problem
I was just in the middle of debugging why a string didn't match a regex, and I tried
Debug.log
ging the regex, which gave me{}
, which I found to be very unhelpful.Creating a regex inside the Elm REPL gives the same behavior:
Expectation
I expected to see some kind of information in the log message to see what the regex is. The Node.js REPL gives the following feedback, which I believe is more helpful:
Suggested solution
I suggest that
elm/core
's_Debug_toAnsiString
function adds a special-case for regexes to print the regex in a useful way.I feel like the format of the stringified version aims to be somewhat copy-pastable into Elm code (seeing examples like
Dict.fromList
), which makes this format a tiny bit tricky. Ideally, the format of the regex should probably be the "JavaScript regex format" (/hello/gi
), but that wouldn't be valid Elm code.A second option would be to print the code needed to create the Regex from Elm code (
Regex.fromString "hello"
) but that would have 2 drawbacks:Maybe
./"hello"/
->Regex.fromString "\"hello\""
), which makes the regex harder to read, which might be counterproductive when the intent of theDebug.log
ging was to make it clearer what the regex is.The text was updated successfully, but these errors were encountered: