State-machined based text parsing framework