Added a SIGABRT handler that will write a stack trace to /tmp/phabricator_backtrace_[PID]

Summary:
Stack traces are useful for debugging things.  This adds a
signal handler that registers SIGABRT and SIGHUP. In both cases, a
backtrace is written to /tmp/phabricator_backtrace_<PID>.  If SIGABRT
is caught, we terminate the process with extreme prejudice.

Note, however, that any php script that wishes to actually use this
functionality must declare(ticks=1) (or some other value) in the main
script; i.e., setting this value in an included script doesn't appear
to impact the main script.

Test Plan:
<?php
declare(ticks=1);
require_once ('__init_script__.php');
posix_kill(posix_getpid(), SIGABRT);
sleep (1000000);
?>

for both SIGABRT and SIGHUP, did the same with kill -ABRT and kill -HUP.
Observed that it worked as intended.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D7797
Allow empty array for `csprintf` when using "%Ls"

See:

  - <https://github.com/facebook/libphutil/issues/31>
  - <https://github.com/facebook/libphutil/pull/32>

Reviewed by: epriestley
Allow `PhutilTypeSpec` to work with classes and subclasses.

Summary: Fixes T4286.

Test Plan: `arc unit -- src/parser/`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T4286

Differential Revision: https://secure.phabricator.com/D7902
Make "unable to create temporary directory" error slightly more clear

Summary: See <https://github.com/facebook/phabricator/issues/479>. When we fail to create a temporary directory, list the parent directory in which we attempted to create it.

Test Plan: Faked an error and saw a message with the parent directory.

Reviewers: btrahan, chad

Reviewed By: chad

CC: aran

Differential Revision: https://secure.phabricator.com/D7917
Fix excessively aggressive capturing of hyperlinks in Remarkup

Summary: Fixes T4319. See that task for examples. The "ungreedy" hyperlink rule is still a bit too greedy.

Test Plan: Added failing tests, made them pass.

Reviewers: btrahan, Firehed

Reviewed By: Firehed

CC: aran

Maniphest Tasks: T4319

Differential Revision: https://secure.phabricator.com/D7974
Remarkup - add underline rule

Summary: ...and a test even!

Test Plan: tests passed

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D7995
underline rule - tweak it a bit

Summary:
basically what you told me to do in D7995, but I also added a "/" to the 'don't capture' clause. In my chosen test code without this check we would end up underlining "and also", and I figured this special case will probably need to handle multiple files in a row with this formatting.

Of course, this means __/something__ also won't be underlined.

Test Plan: plugged the regex into a handy online tool (http://regex101.com/) and played with it a bunch. re-ran unit tests and they passed

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D7999
Make directory fixture script slightly more modern and usable

Summary:
Ref T4327. I made some small changes to this script while developing parser unit tests. Mostly:

  - Add `pht()`.
  - Use `PhutilConsole`.
  - Throw `PhutilArugmentUsageException` for questionable usage.
  - Add a `--read-only` flag to ignore changes on exit.
  - Show the CWD after unpacking the fixture, which makes it easier to `svn checkout file://...` it.
  - Improve some language.

Test Plan: Tested all the features; used these features while working on T4327 to good effect.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4327

Differential Revision: https://secure.phabricator.com/D8021
Add unit test scaffolding for XHPAST/PHPAST

Summary:
Ref T4334. Allows us to build tests against this so we can accomplish goals described in T4334 with greater confidence.

This allows three types of tests to be defined:

  - `pass`: Input is expected to parse into a specific tree.
  - `fail-syntax`: Input is expected to fail with a syntax error.
  - `fail-parse`: Input is expected to parse the wrong tree.

The latter two test types allow us to write passing tests of broken/bad behavior while keeping it clear which tests are passing-and-good and which are passing-but-broken.

Test Plan: Ran unit tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8025
Add PHPAST test cases for most lexer patterns

Summary: Ref T4334. Adds test cases for most of the lexer rules: tags, literals, and comments. Remaining lexer rules are mostly difficult to test in isolation, or have a known issue in the case of HEREDOC.

Test Plan: The JSON dumps aren't very human readable, so I'm verifying that the parser output is sane using the web UI PHPAST tool before committing it to tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8026
Add failing PHPAST test case for binary literals

Summary: Ref T4334. We do not currently support these, but should. Support will turn this into a "pass" test case.

Test Plan: Generated expected output with similar file using a hex literal, ran unit tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8027
Add a PHPAST test case for most of the PHP grammar

Summary: Ref T4334. This test case covers most of the common PHP grammar rules. It's not exhastive and avoids some of the tricky parts, but provides a wide base of rule tests.

Test Plan: Examined parse manually in PHPAST web tool. Ran unit tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8028
Add PHPAST test for empty heredoc

Summary: Ref T4334. Ref T3512. This result is wrong, but cover it with a test before I muck around with the parser itself.

Test Plan: Ran unit tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T3512, T4334

Differential Revision: https://secure.phabricator.com/D8029
Add PHPAST tests for static class expressions, callable, traits, finally and short array syntax

Summary: Ref T4334. These are all failing, but should pass. They pass with `php -l` on modern PHP.

Test Plan: Ran unit tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8030
Add PHPAST test for remaining language features

Summary: Ref T4334. Adds yield, foreach-list, literal-deref tests. All currently fail. Adds a heredoc terminal test.

Test Plan: Ran unit tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8031
Align PHPAST lexer to PHP 5.5.8

Summary:
Ref T4334. This aligns the lexer (but not the parser) with PHP 5.5.8. It also applies the patch on T3512. This has these positive effects:

  - Fixes binary literals.
  - Fixes empty heredoc.
  - Corrects T_BINARY_CAST into T_STRING_CAST (consistent with 5.5.8).
  - Removes T_UNICODE_CAST (not in 5.5.8).
  - Recognizes keywords `trait`, `__trait__`, `yield`, `insteadof`, `callable`.

...these sideways effects:

  - Slightly improves terminal heredocs (previously: parse error; now: bad parse).

...and these negative effects:

  - Breaks the `callable` test, since `callable` is now recognized as a keyword but the parser doesn't yet support it.

Test Plan: Rebuilt xhpast, ran unit tests.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8032
Mostly align parser to PHP 5.5.8

Summary: Ref T4334. Adds support for: traits; yield; short array syntax; callable; finally.

Test Plan:
Unit tests. Attempted to use PHPAST web view to verify I didn't build the trees wrong.

{F103626}

Generally, these changes are difficult to verify by inspection, and errors only become clear once the tree is in use. So probably not everything is quite correct, but it should be relatively close.

Reviewers: btrahan, Firehed

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4334

Differential Revision: https://secure.phabricator.com/D8033
Disable XML entity loader by default in libphutil

Summary:
See <https://www.facebook.com/BugBounty/posts/778897822124446> and <http://www.ubercomp.com/posts/2014-01-16_facebook_remote_code_execution>.

By default, `SimpleXMLElement` will pretty much just run whatever code you want when handed a specially crafted document. We currently load XML only from trusted (S3, EC2, git/svn/hg) or local sources (unit test runners) so there are no concrete vulnerabilities in Phabricator, but this behavior is incredibly dangerous, surprising, and highly undesirable.

Test Plan: There's an example of a document which does bad things on <http://www.php.net/manual/en/function.libxml-disable-entity-loader.php>. I verified that `SimpleXMLElement` reads `/etc/passwd` when handed this document, then applied the fix. It no longer reads arbitrary files off disk.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Differential Revision: https://secure.phabricator.com/D8049
Add WARNING and IMPORTANT to remarkup

Summary:
Ref T3116. This is basically the NOTE: rule except we consume WARNING and IMPORTANT.

Also adds (X) syntax for all three of (NOTE), (WARNING), and (IMPORTANT), which behave like the colon versions, just eating the keywords in html rendering.

Test Plan: played with it in phabricator proper; see next diff. also wrote a unit test

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Maniphest Tasks: T3116

Differential Revision: https://secure.phabricator.com/D8052
Fixed missing symbols

Summary: Some symbols/files that are not defined have crept into the `__phutil_library_map__.php` file. In this revision, I fix this problem by running `arc liberate`, and also add a unit test to prevent this from occuring in the future (the unit test was taken from Phabricator).

Test Plan: `arc unit`

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley

CC: Korvin, epriestley, aran

Differential Revision: https://secure.phabricator.com/D8056