BuckleScript

BuckleScript

  • Docs
  • Try
  • API
  • Community
  • Blog
  • Languages iconEnglish
    • 日本語
    • Español
    • Français
    • 한국어
    • Português (Brasil)
    • Русский
    • 中文
    • 繁體中文
    • Help Translate
  • GitHub

›Build System

Intro

  • What & Why
  • Installation
  • New Project
  • Try
  • Concepts Overview
  • Upgrade Guide to v7

Interop

  • Overview
  • Cheatsheet
  • Embed Raw JavaScript
  • Common Data Types
  • Intro to External
  • Bind to Global Values
  • Null, Undefined & Option
  • Object
  • Object 2
  • Class
  • Function
  • Property access
  • Return value wrapping
  • Import & Export
  • Regular Expression
  • Exceptions
  • JSON
  • Pipe First
  • Generate Converters & Helpers
  • Better Data Structures Printing (Debug Mode)
  • NodeJS Special Variables
  • Miscellaneous
  • Browser Support & Polyfills

Build System

  • Overview
  • Configuration
  • Automatic Interface Generation
  • Interop with Other Build System
  • Performance
  • Advanced

Standard Library

  • Overview

Advanced

  • Conditional Compilation
  • Extended Compiler Options
  • Use Existing OCaml Libraries
  • Difference from Native OCaml
  • Compiler Architecture & Principles
  • Comparison to Js_of_ocaml
Edit

Advanced

Customize Rules (Generators Support)

You might use some pre-processor to generate boilerplate code during development.

Note: pre-processors can be classified as two categories:

  • System-dependent, which should be delayed until running on user machines.
  • System-independent: lex, yacc, m4, re2c, etc, which can be executed any time.

BS has built in support for conditional compilation, which satisfies the first point. This section is about the second point.

An example, where bsb uses ocamlyacc:

{
  "generators" : [
    {
      "name" : "ocamlyacc",
      "command": "ocamlyacc $in"
    }
  ],
  "sources" : {
    "dir" : "src",
    "generators" : [
      {
        "name" : "ocamlyacc",
        "edge" : ["test.ml", "test.mli", ":", "test.mly"]
      }
    ]
  }
}

ocamlyacc will generate the artifacts test.ml and test.mli in the same directory than test.mly.

Note: we highly recommend you to check in the generated files, since this cuts out dependencies like ocamlyacc for the end-users.

When developing a project, bsb will track the dependencies between test.ml and test.mly properly. When released as a package, bsb will cut such dependency, so that users will only need the generated test.ml. To help test such behavior in development mode, users could set it manually:

{
  "cut-generators" : true
}

This prevents bsb from regenerating test.ml whenever test.mly changes.

Last updated on 4/13/2020
← PerformanceOverview →
  • Customize Rules (Generators Support)