Beispiel #1
0
 function testPutBack()
 {
     $m = ['d' => '[1-9][0-9]*', 'sp' => '(\\s+)', '+'];
     $lexer = new Lexer();
     $lexer->init($m);
     $s = $lexer->getTokenStream('1+2');
     $tok = $s->fetch();
     $this->assertEquals('d', $tok[0]);
     $tok = $s->fetch();
     $this->assertEquals('+', $tok[0]);
     $s->putBack($tok);
     $tok = $s->fetch();
     $this->assertEquals('+', $tok[0]);
     $tok = $s->fetch();
     $this->assertEquals('d', $tok[0]);
     $s->putBack($tok);
     $tok = $s->fetch();
     $this->assertEquals('d', $tok[0]);
     $tok = $s->fetch();
     $this->assertNull($tok);
 }