Commit 4da77927 authored by neil.fraser@gmail.com's avatar neil.fraser@gmail.com

Adding statement prefix to generators.

git-svn-id: http://blockly.googlecode.com/svn/trunk@1722 c400ca83-b69d-9dd7-9705-49c6b8615e23
parent 8b852cda
......@@ -45,6 +45,22 @@ Blockly.Generator = function(name) {
*/
Blockly.Generator.NAME_TYPE = 'generated_function';
/**
* Arbitrary code to inject into locations that risk causing infinite loops.
* Any instances of '%1' will be replaced by the block ID that failed.
* E.g. ' checkTimeout(%1);\n'
* @type ?string
*/
Blockly.Generator.prototype.INFINITE_LOOP_TRAP = null;
/**
* Arbitrary code to inject before every statement.
* Any instances of '%1' will be replaced by the block ID of the statement.
* E.g. 'highlight(%1);\n'
* @type ?string
*/
Blockly.Generator.prototype.STATEMENT_PREFIX = null;
/**
* Generate code for all blocks in the workspace to the specified language.
* @return {string} Generated code.
......@@ -142,6 +158,10 @@ Blockly.Generator.prototype.blockToCode = function(block) {
// Value blocks return tuples of code and operator order.
return [this.scrub_(block, code[0]), code[1]];
} else {
if (this.STATEMENT_PREFIX) {
code = this.STATEMENT_PREFIX.replace(/%1/g, '\'' + block.id + '\'') +
code;
}
return this.scrub_(block, code);
}
};
......
......@@ -67,14 +67,6 @@ Blockly.Dart.ORDER_CASCADE = 14; // ..
Blockly.Dart.ORDER_ASSIGNMENT = 15; // = *= /= ~/= %= += -= <<= >>= &= ^= |=
Blockly.Dart.ORDER_NONE = 99; // (...)
/**
* Arbitrary code to inject into locations that risk causing infinite loops.
* Any instances of '%1' will be replaced by the block ID that failed.
* E.g. ' checkTimeout(%1);\n'
* @type ?string
*/
Blockly.Dart.INFINITE_LOOP_TRAP = null;
/**
* Initialise the database of variable names.
*/
......
......@@ -99,14 +99,6 @@ Blockly.JavaScript.ORDER_ASSIGNMENT = 16; // = += -= *= /= %= <<= >>= ...
Blockly.JavaScript.ORDER_COMMA = 17; // ,
Blockly.JavaScript.ORDER_NONE = 99; // (...)
/**
* Arbitrary code to inject into locations that risk causing infinite loops.
* Any instances of '%1' will be replaced by the block ID that failed.
* E.g. ' checkTimeout(%1);\n'
* @type ?string
*/
Blockly.JavaScript.INFINITE_LOOP_TRAP = null;
/**
* Initialise the database of variable names.
*/
......
......@@ -75,14 +75,6 @@ Blockly.Python.ORDER_CONDITIONAL = 15; // if else
Blockly.Python.ORDER_LAMBDA = 16; // lambda
Blockly.Python.ORDER_NONE = 99; // (...)
/**
* Arbitrary code to inject into locations that risk causing infinite loops.
* Any instances of '%1' will be replaced by the block ID that failed.
* E.g. ' checkTimeout(%1)\n'
* @type ?string
*/
Blockly.Python.INFINITE_LOOP_TRAP = null;
/**
* Initialise the database of variable names.
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment