A Formal Perspective on Byte-Pair Encoding