Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong render of the regular expression string in the Basics tutorial #50

Closed
s-and-witch opened this issue May 19, 2023 · 5 comments · Fixed by #51
Closed

Wrong render of the regular expression string in the Basics tutorial #50

s-and-witch opened this issue May 19, 2023 · 5 comments · Fixed by #51
Assignees
Labels
bug Something isn't working documentation Improvements or additions to documentation
Milestone

Comments

@s-and-witch
Copy link

Here https://hackage.haskell.org/package/regex-tdfa-1.3.2/docs/Text-Regex-TDFA.html in Basics section first regular expression rendered by haddock as

>>> let emailRegex = "[a-zA-Z0-9+._-]+\[-a-zA-Z]+\.[a-z]+"

But that's not a valid Haskell string, it should be

let emailRegex = "[a-zA-Z0-9+._-]+\\@[-a-zA-Z]+\\.[a-z]+"

Perhaps you need to add more slashes or something

@andreasabel andreasabel added bug Something isn't working documentation Improvements or additions to documentation labels May 19, 2023
@andreasabel
Copy link
Member

The source gives a correct Haskell string:

>>> let emailRegex = "[a-zA-Z0-9+._-]+\\@[-a-zA-Z]+\\.[a-z]+"

The Haddock documentation contains an example with a escape sequence in a string, and there is no extra escaping: https://haskell-haddock.readthedocs.io/en/latest/markup.html#examples

-- >>> putStrLn "foo\nbar"
-- foo
-- bar

I think this should be considered a haddock bug rather than a bug here, do you agree @s-and-witch ?

@andreasabel
Copy link
Member

andreasabel commented May 19, 2023

Ok, I played a bit with the problem. The crux seems to be the explicit code block annotations @...@:

@
>>> let emailRegex = "[a-zA-Z0-9+._-]+\\@[-a-zA-Z]+\\.[a-z]+"
>>> "my email is [email protected]" =~ emailRegex :: Bool
True
>>> "invalid@mail@com" =~ emailRegex :: Bool
False
>>> "[email protected]" =~ emailRegex :: Bool
False
>>> "#@invalid.com" =~ emailRegex :: Bool
False
/-- non-monadic/
λ> \<to-match-against\> '=~' \<regex\>
/-- monadic, uses 'fail' on lack of match/
λ> \<to-match-against\> '=~~' \<regex\>
@

It seems that removing them would fix the formatting. After all, >>> is already indicating code!

Blame for introducing @...@ goes to e3c15fb, but maybe at that time it was an overall improvement.

@andreasabel
Copy link
Member

@s-and-witch
Copy link
Author

Cool, thanks for such a quick fix!

@andreasabel
Copy link
Member

Ok, then I'll release the fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working documentation Improvements or additions to documentation
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants