All Projects → hhvm → Hack Codegen

hhvm / Hack Codegen

Licence: mit
Library to programatically generate Hack code and write it to signed files

Programming Languages

hack
652 projects

Labels

Projects that are alternatives of or similar to Hack Codegen

CreateAPI
Delightful code generator for OpenAPI specs
Stars: ✭ 176 (-45.34%)
Mutual labels:  codegen
codegen-ace
디미고 이과반 입학과제 코드젠 도우미📓
Stars: ✭ 16 (-95.03%)
Mutual labels:  codegen
modelina
Library for generating data models based on inputs such as AsyncAPI, OpenAPI, or JSON Schema documents.
Stars: ✭ 55 (-82.92%)
Mutual labels:  codegen
vtprotobuf
A Protocol Buffers compiler that generates optimized marshaling & unmarshaling Go code for ProtoBuf APIv2
Stars: ✭ 418 (+29.81%)
Mutual labels:  codegen
next-ts-graphql-apollo-starter
An opiniated Next powered starter which include support for Apollo with GraphQL SSR support, codegen, styled component / system, framer motion and Cypress
Stars: ✭ 18 (-94.41%)
Mutual labels:  codegen
dart-sealed
Codegen implementation for using with sealed annotation
Stars: ✭ 22 (-93.17%)
Mutual labels:  codegen
genqlient
a truly type-safe Go GraphQL client
Stars: ✭ 532 (+65.22%)
Mutual labels:  codegen
Interfaces
Code generation tools for Go.
Stars: ✭ 279 (-13.35%)
Mutual labels:  codegen
contentful-typescript-codegen
Generate TypeScript interfaces from a Contentful environment
Stars: ✭ 164 (-49.07%)
Mutual labels:  codegen
lowcode
React Lowcode - prototype, develop and maintain internal apps easier
Stars: ✭ 32 (-90.06%)
Mutual labels:  codegen
hwt
VHDL/Verilog/SystemC code generator, simulator API written in python/c++
Stars: ✭ 145 (-54.97%)
Mutual labels:  codegen
graphql-codegen-vscode
vscode extension which runs graphql-codegen whenever you save a query/mutation
Stars: ✭ 41 (-87.27%)
Mutual labels:  codegen
genna
Model generator for go-pg package
Stars: ✭ 103 (-68.01%)
Mutual labels:  codegen
micronaut-openapi-codegen
OpenAPI codegen for Micronaut
Stars: ✭ 26 (-91.93%)
Mutual labels:  codegen
Openapi Typescript Codegen
NodeJS library that generates Typescript or Javascript clients based on the OpenAPI specification
Stars: ✭ 249 (-22.67%)
Mutual labels:  codegen
easybundler
A code generator for Android Bundles
Stars: ✭ 53 (-83.54%)
Mutual labels:  codegen
idris-codegen-wasm
WebAssembly Code Generation Backend for Idris Compiler
Stars: ✭ 79 (-75.47%)
Mutual labels:  codegen
Prism
Gett's Design System code generator. Use Zeplin Styleguides as your R&D's Single Source of Truth.
Stars: ✭ 308 (-4.35%)
Mutual labels:  codegen
Protein
💊 Protein is an IntelliJ Plugin to generate Kotlin code for Retrofit 2 and RxJava 2 based on a Swagger definition
Stars: ✭ 273 (-15.22%)
Mutual labels:  codegen
prisma-tgql-types-gen
◭ Prisma generator for generating TypeGraphQL class types and enums with allowing to edit the generated output without being overwritten 💪
Stars: ✭ 32 (-90.06%)
Mutual labels:  codegen

Hack Codegen Build Status

Hack Codegen is a library for easily generating Hack code and writing it into signed files that prevent undesired modifications. The idea behind writing code that writes code is to raise the level of abstraction and reduce coupling. You can use your own way of describing a problem and generate the corresponding code. E.g. see examples/dorm. In this example, we use a schema to describe the structure of the data, and we use Hack Codegen to write the matching code.

Examples

The DORM example shows how to use the different aspects of the code generation in a simplified real-life example. The included tests also exemplify the usage of the different components.

Requirements

Hack Codegen requires:

  • HHVM
  • Composer

Installing Hack Codegen

This package can be installed via composer:

composer require facebook/hack-codegen

Usage

Include the autoload file generated by composer and you are ready to start using it. For example:

<?hh
require 'vendor/autoload.php';

use Facebook\HackCodegen\HackCodegenFactory;

$cg = new HackCodegenFactory(new HackCodegenConfig());

echo $cg->codegenFile('HelloWorld.php')
  ->addClass(
    $cg->codegenClass('HelloWorld')
      ->addMethod(
        $cg->codegenMethod('sayHi')
          ->setReturnType('void')
          ->setBody(
            $cg->codegenHackBuilder()
              ->addAssignment(
                '$some_vector',
                Vector { 1, 2, 3 },
                HackBuilderValues::vector(
                  HackBuilderValues::export(),
                ),
              )
              ->addAssignment(
                '$debug_info',
                Map { 'file' => '__FILE__', 'line' => '__LINE__' },
                HackBuilderValues::map(
                  HackBuilderKeys::export(),
                  HackBuilderValues::literal(),
                ),
              )
              ->addAssignment(
                '$some_vector_of_vectors',
                Vector { Vector { 1, 2, 3 }, Vector { 4, 5, 6 } },
                HackBuilderValues::vector(
                  HackBuilderValues::vector(
                    HackBuilderValues::export(),
                  ),
                ),
              )
              ->addLine('echo "hello world\n";')
              ->getCode();
          );
      )
  )->save();

Configuration

You can configure some options such as the maximum line width, spacing and headers by implementing IHackCodegenConfig and passing an instance to HackCodegenFactory's constructor.

License

Hack Codegen is MIT-licensed.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].