We don't have a guide for how to build your own generator for a new language.
All generators inherit from
Blockly.Generator. The entry point for code generation is
workspaceToCode. The basic generator class handles walking the tree of blocks and calling blockToCode on all blocks. You will want to read this class to understand the code. There are five generators that we provide that inherit from Blockly.Generator. They are in the generators folder.
Here are the basic steps to build your own generator:
- Copy one of the existing generators: generators/lua.js, javascript.js, python.js, dart.js, or php.js.
- I'll use
lua.js for example links below.
- Make sure all references to the old language name are replaced with the new language name.
- Call Blockly.YourLanguageName.addReservedWords with a list of all reserved words in your language (
example)
- Set up order of operation enums (
example)
- See the
operator precedence page for more information.
- Implement the basic set of functions:
- init
- finish
- scrubNakedValue
- scrub_
- Add your generator to the playground and hook up a button so that you can test generating your language
- Define and include generators for a very basic set of blocks (e.g. numbers or strings) and test that they generate correctly, then build from there.
Hope that helps,
Rachel