예제 #1
0
 /**
  * @dataProvider dataCompile
  * @param $template
  * @param $compiled
  * @throws \Azera\Fry\Exception\Exception
  * @throws \Azera\Fry\Exception\LexerException
  */
 public function testCompiles($template, $compiled)
 {
     $env = $this->getEnvironment()->addExtension(new Core());
     $lexer = new Lexer(new Reader($template), $env);
     $parser = new Parser($lexer->tokenize()->getStream(), $env);
     $bodyNode = $parser->parse()->getBody();
     $compiler = new Compiler($this->getEnvironment());
     $output = $compiler->compile($bodyNode);
     $this->assertEquals(trim($compiled), trim($output));
 }
예제 #2
0
 /**
  * @dataProvider    contexts
  * @param $context
  * @param $tokensType
  */
 public function testContext($context, $tokensType)
 {
     $lexer = new Lexer(new Reader($context), $this->getEnvironment());
     $tokens = $lexer->tokenize();
     $expected = [];
     $actual = [];
     foreach ($tokensType as $item) {
         $expected[] = $lexer->getTokenName($item[0]) . " (" . $item[1] . ")";
     }
     foreach ($tokens->getTokens() as $token) {
         if ($token->getType() == TokenTypes::T_EOF) {
             continue;
         }
         $actual[] = $lexer->getTokenName($token->getType()) . " (" . $token->getName() . ")";
     }
     $this->assertEquals($expected, $actual);
     //
     //        $tokensCount = count( $tokensType );
     //        if ( $tokensCount != $tokens->count() ) {
     //            $this->assertEquals( $tokensType , $tokens->getTokens());
     //        }
     //
     //        foreach ( $tokensType as $i => $token ) {
     //            $this->assertEquals(
     //                $token[0],
     //                $tokens[$i]->getType(),
     //                sprintf(
     //                    'Invalid token `%s` at token offset %d, it must be `%s`' ,
     //                    $lexer->getTokenName( $tokens[$i]->getType() ) ,
     //                    $i,
     //                    $lexer->getTokenName( $token[0] )
     //                )
     //            );
     //            $this->assertEquals(
     //                $token[1],
     //                $tokens[$i]->getName(),
     //                sprintf(
     //                    'Invalid token name `%s` at token offset %d, it must be `%s`',
     //                    $tokens[$i]->getName(),
     //                    $i,
     //                    $token[1]
     //                )
     //            );
     //        }
 }
예제 #3
0
 public function compileSource($source, $fileName)
 {
     $lexer = new Lexer(new Reader($source, $fileName), $this);
     $parser = new Parser($lexer->tokenize()->getStream(), $this);
     $compiler = new Compiler($this);
     $compiled = $compiler->compile($parser->parse());
     return $compiled;
 }