Remove duplicated generators.

This commit is contained in:
Neil Fraser
2015-07-23 13:11:51 -07:00
parent ce6ad13fbb
commit bafb3016fd
14 changed files with 116 additions and 157 deletions

View File

@@ -28,22 +28,17 @@ goog.provide('Blockly.Python.loops');
goog.require('Blockly.Python');
Blockly.Python['controls_repeat'] = function(block) {
// Repeat n times (internal number).
var repeats = parseInt(block.getFieldValue('TIMES'), 10);
var branch = Blockly.Python.statementToCode(block, 'DO');
branch = Blockly.Python.addLoopTrap(branch, block.id) ||
Blockly.Python.PASS;
var loopVar = Blockly.Python.variableDB_.getDistinctName(
'count', Blockly.Variables.NAME_TYPE);
var code = 'for ' + loopVar + ' in range(' + repeats + '):\n' + branch;
return code;
};
Blockly.Python['controls_repeat_ext'] = function(block) {
// Repeat n times (external number).
var repeats = Blockly.Python.valueToCode(block, 'TIMES',
Blockly.Python.ORDER_NONE) || '0';
// Repeat n times.
if (block.getField('TIMES')) {
// Internal number.
var repeats = parseInt(block.getFieldValue('TIMES'), 10);
} else {
// External number.
var repeats = Blockly.Python.valueToCode(block, 'TIMES',
Blockly.Python.ORDER_NONE) || '0';
}
if (Blockly.isNumber(repeats)) {
repeats = parseInt(repeats, 10);
} else {
@@ -58,6 +53,8 @@ Blockly.Python['controls_repeat_ext'] = function(block) {
return code;
};
Blockly.Python['controls_repeat'] = Blockly.Python['controls_repeat_ext'];
Blockly.Python['controls_whileUntil'] = function(block) {
// Do while/until loop.
var until = block.getFieldValue('MODE') == 'UNTIL';