-
Notifications
You must be signed in to change notification settings - Fork 548
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
Add Regex DSL #1302
Comments
To me this proposition has the advantage of being the most straightforward to use, but I'm wondering whether it's not too implicit and magical as the user would not necessarily understand from the example that their plain strings are being modified. I see 2 cases in which that would lead to unexpected behavior:
The alternatives I can think of have the disadvantage of being more wordy and of requiring the user to know more about the functions we propose. 1. We make them use a function for their literal expressions.So that would look like:
Advantages:
Disadvantages:
2. We make them put the functions and the literal expressions they use in a root function.So, for instance:
Advantages:
Disadvantages:
What do you think? |
For your first example we could turn RegexStr("[a-zA-Z]+") + exactly(3, "abc") This is fine design-wise: the common path is easy but it allows more sophisticated use cases. But this does not solve the issue with |
Why?
Regular expressions are a very compact DSL to generate DFAs, and can be intimidating at first. We cannot expect users to be fluent in this DSL.
How?
We can make this easier by designing a simple Python DSL that compiles into regular expressions. It can be as simple as defining functions that return a regex string:
This is in practice slightly more complex, as some characters need to be escaped in literal expressions (such as
(
), and we cannot expect users who are not familiar with regular expressions to know that. A solution would be to create aRegexStr
object that abstracts this away, for instance:This is however a very rough design, and I am open to alternatives.
The text was updated successfully, but these errors were encountered: