You could write code like the following:
sub A' B by A X;
This matches the glyph named A when followed by the glyph named B and replaces the A by the glyphs A and X. Since there is no single quote after the B, it is left unchanged. And since the A appears in the match and the replacement pattern, it is also left unchanged. Only the X is added, yielding a glyph sequence of A X B.
You can, of course, use any glyph names that you need instead.
For this to work in Adobe’s apps, you need to enabled the World-Ready Composer, see here for details: