/** * Creates a new, blank PHP source file. * * @param string|NULL $ns * If provided, the new document will have this namespace added to it. * * @return static */ public static function create($ns = NULL) { $node = new RootNode(); $node->addChild(Token::openTag()); if (is_string($ns) && $ns) { NamespaceNode::create($ns)->appendTo($node)->after(Token::newline()); } return $node; }
/** * Build a syntax tree from the token iterator. * @param TokenIterator $iterator * @return RootNode Root node of the tree */ public function buildTree(TokenIterator $iterator) { $this->skipped = []; $this->skipParent = NULL; $this->docComment = NULL; $this->skippedDocComment = []; $this->iterator = $iterator; $this->current = $this->iterator->current(); $this->currentType = $this->current ? $this->current->getType() : NULL; $top = new RootNode(); $this->top = $top; if ($this->currentType && $this->currentType !== T_OPEN_TAG) { $node = new TemplateNode(); // Parse any template statements that proceed the opening PHP tag. $this->templateStatementList($node); $top->addChild($node); } if ($this->tryMatch(T_OPEN_TAG, $top, NULL, TRUE, TRUE)) { $this->topStatementList($top); } return $top; }