Files
linguist/samples/Hack/UserID.hh
Josh Watzman b2cb74cabf 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.
2014-10-21 15:35:57 -07:00

34 lines
946 B
C++

<?hh // strict
/**
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
require_once $_SERVER['DOCUMENT_ROOT'].'/core/funs/init.php';
// Outside of this file, no one knows that these types are ints. They do know
// that USER_ID is an ID and COW_ID is an ID
newtype ID = int;
newtype USER_ID as ID = ID;
newtype COW_ID as ID = ID;
function assert_user_id(int $x): USER_ID {
// Everyone knows all user ids are odd
invariant($x % 2, sprintf('Invalid user ID: %d', $x));
return $x;
}
function assert_cow_id(int $x): COW_ID {
// Everyone knows all cow ids are even
invariant($x % 2 === 0, sprintf('Invalid cow ID: %d', $x));
return $x;
}
function id_to_int(ID $id): int {
return $id;
}