static State lexWhitespace(Lexer l) { switch (getType(l.read())) { case CharType.Whitespace: l.discard(); return lexWhitespace; case CharType.OpenParanthesis: l.next(); l.emit(Token.OpenParanthesis); l.reset(); return lexWhitespace; case CharType.CloseParanthesis: l.next(); l.emit(Token.CloseParanthesis); l.reset(); return lexWhitespace; case CharType.Number: l.reset(); return lexNumber; case CharType.Operator: l.reset(); return lexOperator; case CharType.Letter: l.reset(); return lexWord; case CharType.EOF: return null; default: throw new Exception("Invalid input."); } }