-
Notifications
You must be signed in to change notification settings - Fork 20
Add basic code point parsers #88
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
Conversation
cp <- anyCodePoint | ||
case toChar cp of | ||
Just chr -> pure chr | ||
Nothing -> fail $ "Code point " <> show cp <> " is not a character" | ||
where | ||
toChar = fromCharCode <<< fromEnum |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Watch out for this bug in fromCharCode
https://github.com/purescript-contrib/purescript-parsing/blob/33cbb663651f28062a2ffc0016033142b24bfed2/src/Text/Parsing/Parser/String.purs#L88-L90
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed and uncommented the test I added for that earlier :)
-- | Match any code point. | ||
anyCodePoint :: Parser CodePoint | ||
anyCodePoint = Parser \{ substring, position } -> | ||
case SCP.codePointAt 0 substring of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fine but you could use uncons
like so https://github.com/purescript-contrib/purescript-parsing/blob/33cbb663651f28062a2ffc0016033142b24bfed2/src/Text/Parsing/Parser/String.purs#L102
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's better indeed
Fix #85
Checklist: