diff --git a/resources/sql/autopatches/20151108.xhpast.stderr.sql b/resources/sql/autopatches/20151108.xhpast.stderr.sql new file mode 100644 index 0000000000..1721505658 --- /dev/null +++ b/resources/sql/autopatches/20151108.xhpast.stderr.sql @@ -0,0 +1,5 @@ +ALTER TABLE {$NAMESPACE}_xhpastview.xhpastview_parsetree + ADD returnCode INT NOT NULL AFTER input; + +ALTER TABLE {$NAMESPACE}_xhpastview.xhpastview_parsetree + ADD stderr longtext NOT NULL AFTER stdout; diff --git a/src/applications/phpast/controller/PhabricatorXHPASTViewController.php b/src/applications/phpast/controller/PhabricatorXHPASTViewController.php index 7d3ccf8187..2ef34fb36f 100644 --- a/src/applications/phpast/controller/PhabricatorXHPASTViewController.php +++ b/src/applications/phpast/controller/PhabricatorXHPASTViewController.php @@ -1,19 +1,18 @@ buildStandardPageView(); $page->setApplicationName('XHPASTView'); $page->setBaseURI('/xhpast/'); $page->setTitle(idx($data, 'title')); $page->setGlyph("\xE2\x96\xA0"); $page->appendChild($view); $response = new AphrontWebpageResponse(); return $response->setContent($page->render()); } } diff --git a/src/applications/phpast/controller/PhabricatorXHPASTViewFrameController.php b/src/applications/phpast/controller/PhabricatorXHPASTViewFrameController.php index 2c5a43687c..89f5b8fd7d 100644 --- a/src/applications/phpast/controller/PhabricatorXHPASTViewFrameController.php +++ b/src/applications/phpast/controller/PhabricatorXHPASTViewFrameController.php @@ -1,26 +1,26 @@ getURIData('id'); return $this->buildStandardPageResponse( phutil_tag( 'iframe', array( - 'src' => '/xhpast/frameset/'.$id.'/', + 'src' => "/xhpast/frameset/{$id}/", 'frameborder' => '0', 'style' => 'width: 100%; height: 800px;', '', )), array( 'title' => pht('XHPAST View'), )); } } diff --git a/src/applications/phpast/controller/PhabricatorXHPASTViewFramesetController.php b/src/applications/phpast/controller/PhabricatorXHPASTViewFramesetController.php index de446b5e44..6f186fb3f8 100644 --- a/src/applications/phpast/controller/PhabricatorXHPASTViewFramesetController.php +++ b/src/applications/phpast/controller/PhabricatorXHPASTViewFramesetController.php @@ -1,26 +1,24 @@ getURIData('id'); - $response = new AphrontWebpageResponse(); - $response->setFrameable(true); - $response->setContent(phutil_tag( - 'frameset', - array('cols' => '33%, 34%, 33%'), - array( - phutil_tag('frame', array('src' => "/xhpast/input/{$id}/")), - phutil_tag('frame', array('src' => "/xhpast/tree/{$id}/")), - phutil_tag('frame', array('src' => "/xhpast/stream/{$id}/")), - ))); - - return $response; + return id(new AphrontWebpageResponse()) + ->setFrameable(true) + ->setContent(phutil_tag( + 'frameset', + array('cols' => '33%, 34%, 33%'), + array( + phutil_tag('frame', array('src' => "/xhpast/input/{$id}/")), + phutil_tag('frame', array('src' => "/xhpast/tree/{$id}/")), + phutil_tag('frame', array('src' => "/xhpast/stream/{$id}/")), + ))); } } diff --git a/src/applications/phpast/controller/PhabricatorXHPASTViewPanelController.php b/src/applications/phpast/controller/PhabricatorXHPASTViewPanelController.php index 8f824dc03f..7238b36381 100644 --- a/src/applications/phpast/controller/PhabricatorXHPASTViewPanelController.php +++ b/src/applications/phpast/controller/PhabricatorXHPASTViewPanelController.php @@ -1,74 +1,74 @@ id = $data['id']; $this->storageTree = id(new PhabricatorXHPASTViewParseTree()) ->load($this->id); + if (!$this->storageTree) { throw new Exception(pht('No such AST!')); } } protected function getStorageTree() { return $this->storageTree; } protected function buildXHPASTViewPanelResponse($content) { $content = hsprintf( ''. ''. '
'. ''. ''. '%s'. '', $content); - $response = new AphrontWebpageResponse(); - $response->setFrameable(true); - $response->setContent($content); - return $response; + return id(new AphrontWebpageResponse()) + ->setFrameable(true) + ->setContent($content); } } diff --git a/src/applications/phpast/controller/PhabricatorXHPASTViewRunController.php b/src/applications/phpast/controller/PhabricatorXHPASTViewRunController.php index dd9cf85433..dc2224d291 100644 --- a/src/applications/phpast/controller/PhabricatorXHPASTViewRunController.php +++ b/src/applications/phpast/controller/PhabricatorXHPASTViewRunController.php @@ -1,55 +1,59 @@ getViewer(); if ($request->isFormPost()) { $source = $request->getStr('source'); $future = PhutilXHPASTBinary::getParserFuture($source); $resolved = $future->resolve(); // This is just to let it throw exceptions if stuff is broken. - $parse_tree = XHPASTTree::newFromDataAndResolvedExecFuture( - $source, - $resolved); + try { + XHPASTTree::newFromDataAndResolvedExecFuture($source, $resolved); + } catch (XHPASTSyntaxErrorException $ex) { + // This is possibly expected. + } list($err, $stdout, $stderr) = $resolved; - $storage_tree = new PhabricatorXHPASTViewParseTree(); - $storage_tree->setInput($source); - $storage_tree->setStdout($stdout); - $storage_tree->setAuthorPHID($viewer->getPHID()); - $storage_tree->save(); + $storage_tree = id(new PhabricatorXHPASTViewParseTree()) + ->setInput($source) + ->setReturnCode($err) + ->setStdout($stdout) + ->setStderr($stderr) + ->setAuthorPHID($viewer->getPHID()) + ->save(); return id(new AphrontRedirectResponse()) ->setURI('/xhpast/view/'.$storage_tree->getID().'/'); } $form = id(new AphrontFormView()) ->setUser($viewer) ->appendChild( id(new AphrontFormTextAreaControl()) ->setLabel(pht('Source')) ->setName('source') ->setValue("setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL)) ->appendChild( id(new AphrontFormSubmitControl()) ->setValue(pht('Parse'))); $form_box = id(new PHUIObjectBoxView()) ->setHeaderText(pht('Generate XHP AST')) ->setForm($form); return $this->buildApplicationPage( $form_box, array( 'title' => pht('XHPAST View'), )); } } diff --git a/src/applications/phpast/controller/PhabricatorXHPASTViewStreamController.php b/src/applications/phpast/controller/PhabricatorXHPASTViewStreamController.php index 3fe1046f10..f5cedf225a 100644 --- a/src/applications/phpast/controller/PhabricatorXHPASTViewStreamController.php +++ b/src/applications/phpast/controller/PhabricatorXHPASTViewStreamController.php @@ -1,33 +1,39 @@ getStorageTree(); $input = $storage->getInput(); + $err = $storage->getReturnCode(); $stdout = $storage->getStdout(); + $stderr = $storage->getStderr(); - $tree = XHPASTTree::newFromDataAndResolvedExecFuture( - $input, - array(0, $stdout, '')); + try { + $tree = XHPASTTree::newFromDataAndResolvedExecFuture( + $input, + array($err, $stdout, $stderr)); + } catch (XHPASTSyntaxErrorException $ex) { + return $this->buildXHPASTViewPanelResponse($ex->getMessage()); + } $tokens = array(); foreach ($tree->getRawTokenStream() as $id => $token) { $seq = $id; $name = $token->getTypeName(); $title = pht('Token %s: %s', $seq, $name); $tokens[] = phutil_tag( 'span', array( 'title' => $title, 'class' => 'token', ), $token->getValue()); } return $this->buildXHPASTViewPanelResponse( phutil_implode_html('', $tokens)); } } diff --git a/src/applications/phpast/controller/PhabricatorXHPASTViewTreeController.php b/src/applications/phpast/controller/PhabricatorXHPASTViewTreeController.php index 1b4eec6441..c15bdc2928 100644 --- a/src/applications/phpast/controller/PhabricatorXHPASTViewTreeController.php +++ b/src/applications/phpast/controller/PhabricatorXHPASTViewTreeController.php @@ -1,49 +1,54 @@ getStorageTree(); $input = $storage->getInput(); + $err = $storage->getReturnCode(); $stdout = $storage->getStdout(); + $stderr = $storage->getStderr(); - $tree = XHPASTTree::newFromDataAndResolvedExecFuture( - $input, - array(0, $stdout, '')); + try { + $tree = XHPASTTree::newFromDataAndResolvedExecFuture( + $input, + array($err, $stdout, $stderr)); + } catch (XHPASTSyntaxErrorException $ex) { + return $this->buildXHPASTViewPanelResponse($ex->getMessage()); + } $tree = phutil_tag('ul', array(), $this->buildTree($tree->getRootNode())); return $this->buildXHPASTViewPanelResponse($tree); } protected function buildTree($root) { - try { $name = $root->getTypeName(); $title = $root->getDescription(); } catch (Exception $ex) { $name = '???'; $title = '???'; } $tree = array(); $tree[] = phutil_tag( 'li', array(), phutil_tag( 'span', array( 'title' => $title, ), $name)); foreach ($root->getChildren() as $child) { $tree[] = phutil_tag('ul', array(), $this->buildTree($child)); } return phutil_implode_html("\n", $tree); } } diff --git a/src/applications/phpast/storage/PhabricatorXHPASTViewParseTree.php b/src/applications/phpast/storage/PhabricatorXHPASTViewParseTree.php index fa9adb62a2..d4432af496 100644 --- a/src/applications/phpast/storage/PhabricatorXHPASTViewParseTree.php +++ b/src/applications/phpast/storage/PhabricatorXHPASTViewParseTree.php @@ -1,19 +1,22 @@ array( 'authorPHID' => 'phid?', 'input' => 'text', + 'returnCode' => 'sint32', 'stdout' => 'text', + 'stderr' => 'text', ), ) + parent::getConfiguration(); } }