Contextual alternates (not init, medi, fina or isol)

Hello,

Is there a way to write/control the OpenType features in a way that each character’s design responds to the length of a word? I’m thinking about a typeface that, for instance, has the middle characters of a word bolder than the extremes that could be lighter in a sort of gradient.

Thank you so much.