3 ms·
I can't find a reference to what parser python uses internally, but if it does at least one token lookahead, wouldn't you be able to disambiguate special syntax
by andreareina 8y ago
I can't find a reference to what parser python uses internally, but if it does at least one token lookahead, wouldn't you be able to disambiguate special syntax from any standard expression since the former allows tokens separated by only a space and the latter doesn't? e.g. afaik `match some_call():` is a syntax error, so you don't need to worry about match being a legal identifier.
I daresay another issue is going to be the syntax -- the naïve way of implementing it nests two blocks: one for the pattern-matched block as a whole, and and another for the actual cases, which means that now you've got a double indent. IIRC this was a reason he gave against implementing case statements way back when.
There is one construct that's almost like a block but doesn't indent code, decorators. It's rich enough to implement multiple dispatch in functions, including pattern-matching on values and not just on types. Unfortunately it won't get you the sort of things you could do with actual blocks, e.g. access to other variables.