Skip to main content

Build a custom generator

10. Summary

In this codelab you learned:

  • How to build a custom language generator to generate JSON.
  • How to define block generators for built in blocks and for custom blocks.
  • How to use a custom generator in a sample app.
  • How to use the core generator functions: statementToCode, valueToCode, blockToCode, and getFieldValue.
  • How to generate code for stacks of blocks.

JSON is a simple language, and there are many additional features that could be implemented in a custom generator. Blockly's built-in language generators are a good place to learn more about some additional features:

  • Variable definition and use.
  • Function definition and use.
  • Initialization and cleanup.
  • Injecting additional functions and variables.
  • Handling comments.
  • Handling parentheses with operator precedence.

Blockly ships with five language generators: Python, Dart, JavaScript, PHP, and Lua. The language generators and block generators can be found in the generators directory.