From b2cb74cabf4ab359bc3ab525049ff0239c7e0a8e Mon Sep 17 00:00:00 2001 From: Josh Watzman Date: Wed, 6 Aug 2014 15:39:10 -0700 Subject: [PATCH 1/3] Add detection for Hack files with ".hh" file extension Hack is Facebook's dialect of PHP: http://hacklang.org/. This adds support for detecting it via the ".hh" file extension; although that extension techincally conflicts with C++ headers, the files look different enough that the existing classifier based on sample code has no trouble distinguising them. This diff deliberately does not deal with detecting ".php" as another valid extension for Hack code. That's much trickier since the code looks basically identical to PHP to the classifier, and needs a different approach. --- lib/linguist/languages.yml | 7 ++ samples/C++/bar.hh | 10 +++ samples/Hack/Assert.hh | 55 ++++++++++++++ samples/Hack/AssertRecipe.hh | 52 +++++++++++++ samples/Hack/Controller.hh | 39 ++++++++++ samples/Hack/DBResultRecipe.hh | 52 +++++++++++++ samples/Hack/Documentation.hh | 22 ++++++ samples/Hack/FakeDB.hh | 65 ++++++++++++++++ samples/Hack/GetAndPostRecipe.hh | 72 ++++++++++++++++++ samples/Hack/GetController.hh | 30 ++++++++ samples/Hack/HomeController.hh | 38 ++++++++++ samples/Hack/MySecureRequest.hh | 13 ++++ samples/Hack/Nav.hh | 104 ++++++++++++++++++++++++++ samples/Hack/NonStrictFile.hh | 27 +++++++ samples/Hack/Recipe.hh | 93 +++++++++++++++++++++++ samples/Hack/RecipeWithDemo.hh | 16 ++++ samples/Hack/Request.hh | 15 ++++ samples/Hack/StandardPage.hh | 81 ++++++++++++++++++++ samples/Hack/StrictFile.hh | 46 ++++++++++++ samples/Hack/UnescapedString.hh | 16 ++++ samples/Hack/UnescapedStringRecipe.hh | 59 +++++++++++++++ samples/Hack/UserID.hh | 33 ++++++++ samples/Hack/UserIDRecipe.hh | 54 +++++++++++++ samples/Hack/UsingUserID.hh | 22 ++++++ samples/Hack/error.hh | 43 +++++++++++ samples/Hack/funs.hh | 32 ++++++++ samples/Hack/index.hh | 14 ++++ samples/Hack/phpfile.hh | 31 ++++++++ samples/Hack/startup.hh | 14 ++++ 29 files changed, 1155 insertions(+) create mode 100644 samples/C++/bar.hh create mode 100644 samples/Hack/Assert.hh create mode 100644 samples/Hack/AssertRecipe.hh create mode 100644 samples/Hack/Controller.hh create mode 100644 samples/Hack/DBResultRecipe.hh create mode 100644 samples/Hack/Documentation.hh create mode 100644 samples/Hack/FakeDB.hh create mode 100644 samples/Hack/GetAndPostRecipe.hh create mode 100644 samples/Hack/GetController.hh create mode 100644 samples/Hack/HomeController.hh create mode 100644 samples/Hack/MySecureRequest.hh create mode 100644 samples/Hack/Nav.hh create mode 100644 samples/Hack/NonStrictFile.hh create mode 100644 samples/Hack/Recipe.hh create mode 100644 samples/Hack/RecipeWithDemo.hh create mode 100644 samples/Hack/Request.hh create mode 100644 samples/Hack/StandardPage.hh create mode 100644 samples/Hack/StrictFile.hh create mode 100644 samples/Hack/UnescapedString.hh create mode 100644 samples/Hack/UnescapedStringRecipe.hh create mode 100644 samples/Hack/UserID.hh create mode 100644 samples/Hack/UserIDRecipe.hh create mode 100644 samples/Hack/UsingUserID.hh create mode 100644 samples/Hack/error.hh create mode 100644 samples/Hack/funs.hh create mode 100644 samples/Hack/index.hh create mode 100644 samples/Hack/phpfile.hh create mode 100644 samples/Hack/startup.hh diff --git a/lib/linguist/languages.yml b/lib/linguist/languages.yml index 56032ebb..11f372c4 100644 --- a/lib/linguist/languages.yml +++ b/lib/linguist/languages.yml @@ -980,6 +980,13 @@ HTTP: extensions: - .http +Hack: + type: programming + lexer: PHP + ace_mode: php + extensions: + - .hh + Haml: group: HTML type: markup diff --git a/samples/C++/bar.hh b/samples/C++/bar.hh new file mode 100644 index 00000000..a87343c2 --- /dev/null +++ b/samples/C++/bar.hh @@ -0,0 +1,10 @@ +class Bar +{ + protected: + + char *name; + + public: + + void hello(); +} diff --git a/samples/Hack/Assert.hh b/samples/Hack/Assert.hh new file mode 100644 index 00000000..c80fc87a --- /dev/null +++ b/samples/Hack/Assert.hh @@ -0,0 +1,55 @@ +( + (function(mixed): T) $fn, + mixed $x, + ): array { + if (is_array($x)) { + return array_map($fn, $x); + } + throw new AssertException('Expected an array'); + } +} diff --git a/samples/Hack/AssertRecipe.hh b/samples/Hack/AssertRecipe.hh new file mode 100644 index 00000000..e2f9eabd --- /dev/null +++ b/samples/Hack/AssertRecipe.hh @@ -0,0 +1,52 @@ +> + protected function getDescription(): ?string { + return 'When you have values with unknown types, it is useful to make '. + 'some runtime assertions and have the type checker understand. This '. + 'recipe demonstrates one approach.'; + } + + protected function getFilenames(): Vector { + return Vector { + 'Assert.php', + }; + } + + protected function getDocs(): Vector<(string, string)> { + return Vector{ + tuple ('Mixed Types', 'hack.annotations.mixedtypes'), + tuple ('Type Inference', 'hack.otherrulesandfeatures.typeinference'), + }; + } + + public function getDemoFilename(): string { + return 'demo.php'; + } + + public function getDemoResult(): string { + return assert_main(); + } + + public function getDemoXHP(): ?:xhp { + return null; + } +} diff --git a/samples/Hack/Controller.hh b/samples/Hack/Controller.hh new file mode 100644 index 00000000..a21aacb2 --- /dev/null +++ b/samples/Hack/Controller.hh @@ -0,0 +1,39 @@ +; + abstract protected function getJS(): Set; + abstract protected function getTitle(): string; + abstract protected function render(): :xhp; + + final protected function getHead(): :xhp { + $css = $this->getCSS()->toVector()->map( + ($css) ==> + ); + $js = $this->getJS()->toVector()->map( + ($js) ==>