Reputation: 1500
In my parser I have multiple occurrences of
expression = quotedString(pattern) | Word(pattern)
and I was wondering if there is some built-in class I've missed for that or if I have define it myself. In case of the second, what would the best option?
Upvotes: 1
Views: 240
Reputation: 11
Old thread I know, but you can reuse your expressions in other expressions.
optionalQuotedString = QuotedString(pattern) | Word(pattern)
expression1 = optionalQuotedString
expression2 = Literal('>') + optionalQuotedString
Might be a little neater than a function, but does the same thing.
Upvotes: 1
Reputation: 414865
Do you mean something like this:
def quotedStringOrWord(pattern):
return quotedString(pattern) | Word(pattern)
Upvotes: 2