title: Scala parsing mutually recursive functions for SML
body: <p>I'm trying to write a parser in Scala for SML with Tokens. It almost works the way I want it to work, except for the fact that this currently parses</p>
  
  <p>let fun f x = r and fun g y in r end;</p>
  
  <p>instead of </p>
  
  <p>let fun f x = r and g y in r end;</p>
  
  <p>How do I change my code so that it recognizes that it doesn't need a FunToken for the second function?</p>
  
  <pre><code>def parseDef:Def = {
    currentToken match {
    case ValToken =&gt; {
      eat(ValToken);
  
      val nme:String = currentToken match {
        case IdToken(x) =&gt; {advance; x}
        case _ =&gt; error("Expected a name after VAL.")
      }
  
      eat(EqualToken);      
      VAL(nme,parseExp)
      }
  
    case FunToken =&gt; {
  
      eat(FunToken);
  
      val fnme:String = currentToken match {
        case IdToken(x) =&gt; {advance; x}
        case _ =&gt; error("Expected a name after VAL.")
      }
  
      val xnme:String = currentToken match {
        case IdToken(x) =&gt; {advance; x}
        case _ =&gt; error("Expected a name after VAL.")
      }
  
      def parseAnd:Def = currentToken match {
        case AndToken =&gt; {eat(AndToken); FUN(fnme,xnme,parseExp,parseAnd)}
        case _ =&gt; NOFUN
      }
  
  
      FUN(fnme,xnme,parseExp,parseAnd)
      }
      case _ =&gt; error("Expected VAL or FUN.");
    }
  }
  </code></pre>