Skip to content

CodePoint versions of oneOf and noneOf #127

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

Merged
merged 4 commits into from
Jan 6, 2022

Conversation

fsoikin
Copy link
Contributor

@fsoikin fsoikin commented Jan 5, 2022

Description of the change

  • In Unicode correctness #119 the anyChar primitive was modified such that it no longer always succeeds, but succeeds only on BMP characters, and a new anyCodePoint was added with the former semantics of anyChar. A corresponding version of satisfy, - satisfyCodePoint, - was added as well.
  • This PR goes a bit further in the same direction, adding CodePoint versions of oneOf and noneOf - oneOfCodePoints and noneOfCodePoints respectively.

Checklist:

  • Added the change to the changelog's "Unreleased" section with a link to this PR and your username
  • Linked any existing issues or proposals that this pull request should close
  • Updated or added relevant documentation in the README and/or documentation directory
  • Added a test for the contribution (if applicable)

@@ -121,6 +125,14 @@ oneOf ss = satisfy (flip elem ss) <?> ("one of " <> show ss)
noneOf :: forall m. Monad m => Array Char -> ParserT String m Char
noneOf ss = satisfy (flip notElem ss) <?> ("none of " <> show ss)

-- | Match one of the Unicode characters in the array.
oneOfCodePoints :: forall m. Monad m => Array CodePoint -> ParserT String m CodePoint
oneOfCodePoints ss = satisfyCodePoint (flip elem ss) <|> defer \_ -> fail $ "Expected one of " <> show (singleton <$> ss)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose to make error messages deferred to avoid the cost of generating the error messages until they're needed. Feels like a small thing, but the waste just bothers me too much.

Let me know if this is undesirable for some reason, I'll change it back to <?>

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I think this is a great idea, and from the tests you added it clearly works. We should probably do this everywhere. I opened #128

@jamesdbrock
Copy link
Member

Thanks for the PR @fsoikin ! Checking...

@jamesdbrock jamesdbrock mentioned this pull request Jan 6, 2022
@jamesdbrock jamesdbrock merged commit 5505ea9 into purescript-contrib:main Jan 6, 2022
@fsoikin fsoikin deleted the noneOfCodePoints branch January 6, 2022 01:53
@jamesdbrock
Copy link
Member

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants