public function testParse()
 {
     $lexer = new Lexer();
     $stream = $lexer->tokenize(" ClassName < BaseClass << Traversable > The Test Class\n" . "> Comment \n" . "+ prop1:integer[set get is bind] > The property 1\n" . "# prop2[set get] > The property 2\n" . "> Comment for prop2\n" . "- prop3:ArrayObject\n" . "\n" . "+ method1(name:string obj:object options:array):boolean > The method 1\n" . "# method2(type:int) > The method 2\n" . "- method3():IteratorAggrigate\n");
     $parser = new TokenParser();
     $nodeStream = $parser->parse($stream);
     $this->assertInstanceOf('KzykHys\\ClassGenerator\\Node\\NodeStream', $nodeStream);
 }
 /**
  * Generate a PHP class from .pcg content
  *
  * @param string $document
  *
  * @return ClassGenerator
  */
 public function generate($document)
 {
     $lexer = new Lexer();
     $tokenStream = $lexer->tokenize($document);
     $tokenParser = new TokenParser();
     $nodeStream = $tokenParser->parse($tokenStream);
     $nodeParser = new NodeParser();
     $this->classBuilder = $nodeParser->parse($nodeStream);
     $compiler = new Compiler($this->options);
     $this->streamWriter = $compiler->compile($this->classBuilder);
     return $this;
 }
Exemplo n.º 3
0
 public function testTokenizeAllTokenType()
 {
     $lexer = new Lexer();
     $stream = $lexer->tokenize("\\Node\\Node < Node\\Node << Node \\Node\\Node\\Node > COMMENT\n" . "> TOKEN INSIDE COMMENT < << : () [] \n" . "+ PUBLIC:TYPE[set get is bind] > COMMENT\n" . "# PROTECTED[set get] > COMMENT\n" . "> COMMENT\n" . "- PRIVATE:TYPE\n" . "\n" . "+ PUBLIC(ARG:TYPE ARG:TYPE):TYPE > COMMENT\n" . "# PROTECTED(ARG:TYPE) > COMMENT\n" . "- PRIVATE():TYPE\n");
     $className = 'KzykHys\\ClassGenerator\\Token\\Token';
     $tokenList = array(1 => array(Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_EXTD, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_IMPL, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_CMNT, Lexer::TOKEN_EOL), 2 => array(Lexer::TOKEN_CMNT, Lexer::TOKEN_EOL), 3 => array(Lexer::TOKEN_PUBL, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_TYPE, Lexer::TOKEN_NODE, Lexer::TOKEN_BRCO, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_BRCC, Lexer::TOKEN_WTSP, Lexer::TOKEN_CMNT, Lexer::TOKEN_EOL), 4 => array(Lexer::TOKEN_PROT, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_BRCO, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_BRCC, Lexer::TOKEN_WTSP, Lexer::TOKEN_CMNT, Lexer::TOKEN_EOL), 5 => array(Lexer::TOKEN_CMNT, Lexer::TOKEN_EOL), 6 => array(Lexer::TOKEN_PRIV, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_TYPE, Lexer::TOKEN_NODE, Lexer::TOKEN_EOL), 7 => array(Lexer::TOKEN_EOL), 8 => array(Lexer::TOKEN_PUBL, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_METO, Lexer::TOKEN_NODE, Lexer::TOKEN_TYPE, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_TYPE, Lexer::TOKEN_NODE, Lexer::TOKEN_METC, Lexer::TOKEN_TYPE, Lexer::TOKEN_NODE, Lexer::TOKEN_WTSP, Lexer::TOKEN_CMNT, Lexer::TOKEN_EOL), 9 => array(Lexer::TOKEN_PROT, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_METO, Lexer::TOKEN_NODE, Lexer::TOKEN_TYPE, Lexer::TOKEN_NODE, Lexer::TOKEN_METC, Lexer::TOKEN_WTSP, Lexer::TOKEN_CMNT, Lexer::TOKEN_EOL), 10 => array(Lexer::TOKEN_PRIV, Lexer::TOKEN_WTSP, Lexer::TOKEN_NODE, Lexer::TOKEN_METO, Lexer::TOKEN_METC, Lexer::TOKEN_TYPE, Lexer::TOKEN_NODE, Lexer::TOKEN_EOL));
     foreach ($tokenList as $line => $tokens) {
         foreach ($tokens as $key => $value) {
             $this->assertInstanceOf($className, $stream->expect($value));
         }
     }
     $this->assertInstanceOf($className, $stream->expect(Lexer::TOKEN_EOL));
     $this->assertTrue($stream->is(Lexer::TOKEN_EOF));
 }