[parser]: Add legality checking for transitions to the state class.