Ejemplo n.º 1
0
 public function testTokens()
 {
     $input = new ParseInput(array(array('int', 5), array('op', '+'), array('int', 2)));
     $this->assertTrue($input->acceptToken('int', $token));
     $this->assertEquals(5, $token[1]);
     $this->assertFalse($input->acceptToken('int'));
     $this->assertThrows('Jivoo\\Parse\\ParseException', function () use($input) {
         $input->expectToken('int');
     });
     $token = $input->expectToken('op');
     $this->assertEquals('op', $token[0]);
     $this->assertEquals('+', $token[1]);
 }
Ejemplo n.º 2
0
 public static function parseColumn(ParseInput $input)
 {
     if ($input->acceptToken('model', $mToken)) {
         $input->expectToken('dot');
         if (!$input->acceptToken('field', $fToken)) {
             $fToken = $input->expectToken('name');
             return new FieldAccess($fToken[1], false, $mToken[1]);
         }
         return new FieldAccess($fToken[1], true, $mToken[1]);
     }
     if ($input->acceptToken('field', $field)) {
         return new FieldAccess($field[1]);
     }
     $first = $input->expectToken('name');
     if ($input->acceptToken('dot')) {
         if (!$input->acceptToken('field', $fToken)) {
             $fToken = $input->expectToken('name');
             return new FieldAccess($fToken[1], false, $first[1], false);
         }
         return new FieldAccess($fToken[1], true, $first[1], false);
     }
     return new FieldAccess($first[1], false);
 }