title: How do you write a lexer parser where identifiers may begin with keywords?
body: <p>Suppose you have a language where identifiers might begin with keywords.  For example, suppose "case" is a keyword, but "caser" is a valid identifier.  Suppose also that the lexer rules can only handle regular expressions.  Then it seems that I can't place keyword rules ahead of the identifier rule in the lexer, because this would parse "caser" as "case" followed by "r". I also can't place keyword lexing rules after the identifier rule, since the identifier rule would match the keywords, and the keyword rules would never trigger.</p>
  
  <p>So, instead, I could make a keyword_or_identifier rule in the lexer, and have the parser determine if a keyword_or_identifier is a keyword or an identifier.  Is this what is normally done?</p>
  
  <p>I realize that "use a different lexer that has lookahead" is an answer (kind of), but I'm also interested in how this is done in a traditional DFA-based lexer, since my current lexer seems to work that way.</p>