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

Configure how regex_syntax treats ., case-sensitivity, etc #172

Closed
nikomatsakis opened this issue Feb 21, 2016 · 3 comments
Closed

Configure how regex_syntax treats ., case-sensitivity, etc #172

nikomatsakis opened this issue Feb 21, 2016 · 3 comments

Comments

@nikomatsakis
Copy link

Currently it seems that . is translated to AnyCharNoNL, but for my use case I would prefer AnyChar. I imagine I could probably achieve this by tweaking the input string to something like (?s:...), but it seems like something that ought to be configurable in a more "first-class" way (among other things, that will mess up the indices in my error messages, unless of course I account for it). Another similar example is being able to control if the regex is case sensitive or not.

BurntSushi added a commit that referenced this issue Feb 21, 2016
@BurntSushi
Copy link
Member

. matching "anything except for new line" is pretty ubiquitous in regex land, which is why it's the default. I think what you're asking for is the ability to change the default values of flags? That seems reasonable. Users could still revert to the "normal" behavior by doing (?-s:.), which would disable the s flag by default.

Technically, there is a work around that you should be able to use now: simply prepend your default flag settings to the regex string given to the parser. So for example, given any regex re, the regex (?i)re would change the default value of the case insensitive flag to true.

With all that said, perhaps there should be an ExprBuilder or an ExprFlags that would enable one to set the default flag values that the parser uses in a more structured way.

Does this help solve your problem or am I way off track?

@nikomatsakis
Copy link
Author

. matching "anything except for new line" is pretty ubiquitous in regex land, which is why it's the default

Well I'll be. I was going to say that this is not the case for lexical generations, except I looked up what flex does and it says . matches "any character (byte) except newline"

I think what you're asking for is the ability to change the default values of flags?

Yes, this is precisely what I want.

That seems reasonable.

...and I agree that although I should change how . behaves to match the current default, this still seems like a pretty useful thing to have.

Technically, there is a work around that you should be able to use now: simply prepend your default flag settings to the regex string given to the parser. So for example, given any regex re, the regex (?i)re would change the default value of the case insensitive flag to true.

Yeah, I mentioned this potential workaround in my bug report. It seems fine except that then the error messages don't match up as well.

@BurntSushi
Copy link
Member

I agree this would be nice. Good point about the error messages!

Yeah, I mentioned this potential workaround in my bug report.

Whoops! Missed that. :-)

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

No branches or pull requests

2 participants