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

match default (_) doesn't capture anything #51

Open
pmetzger opened this issue Oct 9, 2017 · 3 comments
Open

match default (_) doesn't capture anything #51

pmetzger opened this issue Oct 9, 2017 · 3 comments

Comments

@pmetzger
Copy link
Member

pmetzger commented Oct 9, 2017

I'm not sure if it is intentional (in which case it should be documented) or not, but if you match _, the lexeme you get is empty (that is, ""). This means you can't, for example, use the default as a way to catch bad characters and report what they were, you need to match "any" for that.

This seems like a slightly odd choice to me, but again, it probably should be either documented (and explained) or changed.

@smolkaj
Copy link
Collaborator

smolkaj commented Jan 29, 2018

I think this is consistent with the semantics of formal languages. The largest language includes the empty word "". One would expect a wildcard (i.e., _) to match on anything, including the empty word.

The thing that may be a bit subtle is that _ matches lazily, rather than greedily. That is, _ will match the smallest possible word in the "full language", which is always "".

@pmetzger
Copy link
Member Author

I'm not sure I love the behavior, but it should at least be documented I think.

@pmetzger
Copy link
Member Author

(I don't love = matching empty means that you need to do something unusual to match unexpected characters, and that "_" isn't very useful.)

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

2 participants