Using functional idioms to simulate branching logic in scanner