Ejemplo n.º 1
0
 protected function doScan(Scanner $scan)
 {
     $start = $scan->getState();
     $int = $scan->token();
     $scan->next();
     if ($scan->token() !== '.') {
         $scan->setState($start);
         $res = is_null($this->number) || $this->number == $int;
         if ($res) {
             $scan->getContext()->push($int);
             // echo "$int | Parsed. Next token is not a point\n";
             // } else {
             // echo "$int | Next token is not a point. Doesn't match {$this->number}\n";
         }
         return $res;
     }
     if (!$scan->next() || $scan->type() !== Scanner::NUMBER) {
         $scan->setState($start);
         // echo "$int | Fail: not number after /\d+\./ \n";
         return false;
     }
     $frac = $scan->token();
     if (!is_null($this->number)) {
         if ("{$int}.{$frac}" != $this->number) {
             $scan->setState($start);
             // echo "$int.$frac | Parsed float doesn't match {$this->number}\n";
             return false;
         }
     }
     $scan->getContext()->push("{$int}.{$frac}");
     // echo "$int.$frac | Parsed\n";
     return true;
 }
Ejemplo n.º 2
0
 protected function doScan(Scanner $scan)
 {
     $state = $scan->getState();
     foreach ($this->parsers as $p) {
         if (!$p->trigger($scan) || !$p->scan($scan)) {
             $scan->setState($state);
             return false;
         }
     }
     return true;
 }
Ejemplo n.º 3
0
 public function testState()
 {
     $scan = new I\Scanner(new I\StringReader("1+2"), $ctx = new I\Context());
     $start = $scan->getState();
     $scan->next()->next()->next()->next();
     $this->assertSame(I\Scanner::EOF, $scan->type());
     $scan->setState($start);
     $this->assertSame('1', $scan->next()->token());
     $this->assertEquals(array(I\Scanner::CHAR, '+'), $scan->peek());
     $this->assertEquals(array(I\Scanner::CHAR, '+'), $scan->peek());
 }
Ejemplo n.º 4
0
 protected function doScan(Scanner $scan)
 {
     $start = $scan->getState();
     $count = 0;
     while (true) {
         if ($this->max > 0 && $count >= $this->max) {
             break;
         }
         if (!$this->parser->trigger($scan) || !$this->parser->scan($scan)) {
             if ($this->min == 0 || $count >= $this->min) {
                 break;
             } else {
                 //
                 $scan->setState($start);
                 return false;
             }
         }
         $count++;
     }
     return true;
 }