在宏扩展中无法获得此循环的语义

时间:2015-03-14 13:07:23

标签: scala

我正在尝试使用Scala FastParsers库,我正在研究以下代码的宏扩展:

val trueValue = "true".toCharArray
val falseValue = "false".toCharArray

object KParser1 {
  import fastparsers.framework.implementations.FastParsersCharArray._

  val kparser = FastParsersCharArray {
    def func1: Parser[Any] = func1 | falseValue
  }
}

整个展开是there但是那里的一段代码真的困扰我

while$2() {
  if (inputpos$macro$2.$less(inputsize$macro$3).$amp$amp(input$macro$1(inputpos$macro$2).$eq$eq(' ').$bar$bar(input$macro$1(inputpos$macro$2).$eq$eq('\t')).$bar$bar(input$macro$1(inputpos$macro$2).$eq$eq('\n')).$bar$bar(input$macro$1(inputpos$macro$2).$eq$eq('\r'))))
  {
     inputpos$macro$2 = inputpos$macro$2.$plus(1);
     while$2()
  }
  else
     ()
}; 

它看起来像是从输入流中跳过空白的代码,但我无法推断究竟是什么while$2:它是在Unit => Unit声明并自动调用,还是类型预定义的函数Unit => Any => Any

1 个答案:

答案 0 :(得分:0)

它只是一个循环。比较:

scala> while (!done) println("working")
[[syntax trees at end of                     typer]] // <console>
package $line5 {
  object $read extends scala.AnyRef {
    def <init>(): $line5.$read.type = {
      $read.super.<init>();
      ()
    };
    object $iw extends scala.AnyRef {
      def <init>(): type = {
        $iw.super.<init>();
        ()
      };
      import $line4.$read.$iw.$iw.done;
      object $iw extends scala.AnyRef {
        def <init>(): type = {
          $iw.super.<init>();
          ()
        };
        private[this] val res0: Unit = while$1(){
          if ($line4.$read.$iw.$iw.done.unary_!)
            {
              scala.this.Predef.println("working");
              while$1()
            }
          else
            ()
        };
        <stable> <accessor> def res0: Unit = $iw.this.res0
      }
    }
  }
}