Beispiel #1
0
 /**
  * @param string $tplName
  * @param string $source
  * @return string target codes 
  */
 public function compile($tplName, $source)
 {
     $lexer = new Lexer();
     $tokenStream = $lexer->lex($source, $tplName);
     $parser = new Parser\Parser();
     $nodeTree = $parser->parse($tokenStream);
     return $nodeTree->compile();
 }
Beispiel #2
0
 /**
  * @param string $config content
  * @return mixed TODO
  */
 public function parse($config)
 {
     $tokens = $this->lexer->lex($config);
     return $this->parser->parse($tokens);
 }
Beispiel #3
0
 /**
  * Creates the document
  *
  * If the stream has no tokens, I'll clear the document's root.
  *
  * @param  Jstewmc\Chunker\Chunker  $chunker  the document's file or text chunker
  * @return  bool
  */
 protected function create(\Jstewmc\Chunker\Chunker $chunker)
 {
     // create the document's stream
     $stream = new \Jstewmc\Stream\Stream($chunker);
     // lex the string into tokens
     $lexer = new Lexer();
     $tokens = $lexer->lex($stream);
     // if tokens exist
     if (!empty($tokens)) {
         // parse the tokens into the parse tree's root group
         $parser = new Parser();
         $group = $parser->parse($tokens);
         // if a root exists
         if ($group !== null) {
             // render the parse tree's root into the document root
             $renderer = new Renderer();
             $this->root = $renderer->render($group);
         } else {
             $this->root = null;
         }
     } else {
         $this->root = null;
     }
     return (bool) $this->root;
 }
Beispiel #4
0
 function testException()
 {
     $m = ['d' => '[1-9][0-9]*', 'sp' => '(\\s+)', '+' => '\\+'];
     $lexer = new Lexer();
     $lexer->init($m);
     //$this->setExpectedException('phpcc\\');
     try {
         $lexer->lex('-', function ($name, $value, $line, $offset) {
         });
         $this->fail();
     } catch (LexException $e) {
         $this->assertEquals('-', $e->getChar());
         $this->assertEquals(1, $e->getCharLine());
         $this->assertEquals(0, $e->getCharOffset());
     }
     try {
         $lexer->lex('12-12', function ($name, $value, $line, $offset) {
         });
         $this->fail();
     } catch (LexException $e) {
         $this->assertEquals('-', $e->getChar());
         $this->assertEquals(1, $e->getCharLine());
         $this->assertEquals(2, $e->getCharOffset());
     }
 }