Exemplo n.º 1
0
 private function getParser($file)
 {
     $code = $this->getRawContent($file);
     $parser = new Parser();
     $parser->parse($code);
     return $parser;
 }
Exemplo n.º 2
0
 public function __construct(Parser $parser)
 {
     $this->parser = $parser;
     $this->matcher = $parser->getMatcher();
     $this->blockStack = new Stack();
     $this->groupStack = new Stack();
     $this->contextStack = new Stack();
     $this->dispatcher = new EventDispatcher();
 }
Exemplo n.º 3
0
 public function format($code)
 {
     $parser = new Parser();
     $parser->parse($code);
     // formatting
     $delegate = new DelegateFormatter($parser, $this->config);
     $delegate->format();
     // post processing
     return $delegate->getCode();
 }
 public function visitToken(Token $token)
 {
     $this->parser->getTracker()->visitToken($token);
     // visit all rules
     $this->commentsFormatter->visitToken($token);
     $this->indentationFormatter->visitToken($token);
     $this->newlineFormatter->visitToken($token);
     $this->whitespaceFormatter->visitToken($token);
     $this->blanksFormatter->visitToken($token);
     $this->defaultFormatter->visitToken($token);
 }
Exemplo n.º 5
0
 public function testGroupStack()
 {
     $log = new ArrayList();
     $listener = function (GroupEvent $event) use($log) {
         $log->add($event->getName() . ' ' . $event->getGroup()->type);
     };
     $parser = new Parser();
     $parser->getContext()->addListener(Context::EVENT_GROUP_ENTER, $listener);
     $parser->getContext()->addListener(Context::EVENT_GROUP_LEAVE, $listener);
     $parser->parse($this->getCode());
     $this->assertEquals(['context.group_enter block', 'context.group_leave block', 'context.group_enter block', 'context.group_leave block', 'context.group_enter call', 'context.group_leave call', 'context.group_enter block', 'context.group_leave block', 'context.group_enter block', 'context.group_enter group', 'context.group_leave group', 'context.group_leave block'], $log->toArray());
 }
 public function testTokenizer()
 {
     $parser = new Parser();
     $parser->parse($this->getRawContent('sample1'));
     $tokens = $parser->getTokens();
     $tracker = $parser->getTracker();
     $firstIf = $tokens->get(1);
     $firstIfOpen = $tokens->get(2);
     $this->assertEquals('if', $firstIf->contents);
     $this->assertEquals('(', $firstIfOpen->contents);
     $tracker->visitToken($firstIfOpen);
     $this->assertEquals($firstIf, $tracker->getPrevToken());
     $tracker->visitToken($firstIf);
     $this->assertEquals($firstIfOpen, $tracker->getNextToken());
 }
Exemplo n.º 7
0
 private function finish(Token $token)
 {
     if ($this->parser->getTracker()->isLastToken($token)) {
         $this->dumpCurrentUnit();
     }
 }
Exemplo n.º 8
0
 public function visitToken(Token $token)
 {
     $this->nextToken = $this->parser->getTracker()->getNextToken();
     $this->prevToken = $this->parser->getTracker()->getPrevToken();
     $this->doVisitToken($token);
 }