title: Parser combinator for enumerated values
body: <p>Is there a cleaner way to map a string to an Enumeration value in a parser combinator?</p>
  
  <pre><code>object Mode extends Enumeration {
    type Mode = Value
    val View, Add, Modify, Delete  = Value
  }
  
  import Mode._
  
  object ModeParser extends JavaTokenParsers {
    def mode: Parser[Mode] = ("^(" + Mode.values.mkString("|") + ")$").r ^^ { 
      Mode.withName(_) 
    }
  }
  </code></pre>