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

implement Node.__bool__? #184

Open
smason opened this issue Dec 15, 2021 · 0 comments
Open

implement Node.__bool__? #184

smason opened this issue Dec 15, 2021 · 0 comments

Comments

@smason
Copy link

smason commented Dec 15, 2021

I've just been using your library for parsing some text and it's been very useful. One feature I missed was being able to handle missing values in my NodeVisitor nicely (e.g. from a ? or * pattern that doesn't match). Being able to do:

if not node:
  vals = []

would be a convenient idiom to use when the pattern didn't match. It could also be used to do the right thing if visited_children was used as well.

I think bool(node) would just be:

def __bool__(self):
  """Returns True when one or more characters were matched.

  Returns False for ? and * Patterns that fail to match."""
  return self.start != self.end

I'm happy to turn this into a (trivial) pull request, posting as an issue in case I'm missing something!

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