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

Optional Assertion #16

Open
STRd6 opened this issue Feb 24, 2024 · 0 comments
Open

Optional Assertion #16

STRd6 opened this issue Feb 24, 2024 · 0 comments

Comments

@STRd6
Copy link
Collaborator

STRd6 commented Feb 24, 2024

I recently wanted to do something like:

HashThis
  LengthShorthand:id &( ( _+ ( ( Not __ In ) / In ) ) )?:beforeIn ->
    if (beforeIn) ...

but ended up needing to do:

LengthShorthand:id ( &( _+ ( ( Not __ In ) / In ) ) "" )?:beforeIn ->
  if (beforeIn != null) ...

This is because assertions always return undefined since they fail the parse if not met. This causes issue with ? because it returns undefined if the parse wasn't matched so there's not a simple way find out whether the optional assertion matched or not.

It would be nice if optional assertions translated to true/false for whether the assertion passes or fails.

Rule
  A &B?:b ->
    // b is `true` or `false`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant