3 ms·
For your example, a regular expression with named capture groups would be all you'd need, e.g.: https://pythex.org/?regex=%5E(%3FP%3Cuser%3E.%2B%3F)%20(likes%7
by ttd 9y ago
For your example, a regular expression with named capture groups would be all you'd need, e.g.:
https://pythex.org/?regex=%5E(%3FP%3Cuser%3E.%2B%3F)%20(likes%7Cprefers)%20(%3FP%3Cfruit%3E.%2B%3F)%24&test_string=Joanna%20likes%20apples&ignorecase=0&multiline=0&dotall=0&verbose=0 https://pythex.org/?regex=%5E(%3FP%3Cuser%3E.%2B%3F)%20(like...
If you start to need more complex features in your grammar such as recursive nonterminals, there are many parser generators out there that support input in EBNF, which (in my opinion) is quite human-readable.