Those two cases are not hard, because in those scenarios the parser knows it is expecting a type specification. The real problem is this syntax for typed literals: typename 'string' which occurs in ordinary expressions. So when you see "name(" you aren't real sure if you're seeing the start of a function call or the start of a typed-literal construct. And it's very hard to postpone that decision until you see what comes after the right paren.
Just disallow that particular case for custom types :P
Will this work: 'string'::typename
Chris
---------------------------(end of broadcast)--------------------------- TIP 9: the planner will ignore your desire to choose an index scan if your joining column's datatypes do not match