Lexer: Simplify rule codes

Extract lexer rule codes into functions to simplify switching to the
"monad" wrapper.

Signed-off-by: Pekka Enberg <penberg@iki.fi>