mirror of
https://github.com/google/blockly.git
synced 2026-01-04 23:50:12 +01:00
Add method to suppress prefix/suffix from blocks.
This allows generators to have more control over the placement of suffix. Needed for ‘if’ blocks and function calls which require their suffix code to be somewhere other than the end. Also, add loop’s prefix to ‘break’ blocks, since the loop’s suffix will be the next statement hit. Also, reuse procedures_callreturn generator for procedures_callnoreturn.
This commit is contained in:
@@ -33,19 +33,32 @@ Blockly.Python['controls_if'] = function(block) {
|
||||
// If/elseif/else condition.
|
||||
var n = 0;
|
||||
var code = '', branchCode, conditionCode;
|
||||
if (Blockly.Python.STATEMENT_PREFIX) {
|
||||
// Automatic prefix insertion is switched off for this block. Add manually.
|
||||
code += Blockly.Python.injectId(Blockly.Python.STATEMENT_PREFIX, block);
|
||||
}
|
||||
do {
|
||||
conditionCode = Blockly.Python.valueToCode(block, 'IF' + n,
|
||||
Blockly.Python.ORDER_NONE) || 'False';
|
||||
branchCode = Blockly.Python.statementToCode(block, 'DO' + n) ||
|
||||
Blockly.Python.PASS;
|
||||
if (Blockly.Python.STATEMENT_SUFFIX) {
|
||||
branchCode = Blockly.Python.prefixLines(
|
||||
Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX, block),
|
||||
Blockly.Python.INDENT) + branchCode;
|
||||
}
|
||||
code += (n == 0 ? 'if ' : 'elif ' ) + conditionCode + ':\n' + branchCode;
|
||||
|
||||
++n;
|
||||
} while (block.getInput('IF' + n));
|
||||
|
||||
if (block.getInput('ELSE')) {
|
||||
if (block.getInput('ELSE') || Blockly.Python.STATEMENT_SUFFIX) {
|
||||
branchCode = Blockly.Python.statementToCode(block, 'ELSE') ||
|
||||
Blockly.Python.PASS;
|
||||
if (Blockly.Python.STATEMENT_SUFFIX) {
|
||||
branchCode = Blockly.Python.prefixLines(
|
||||
Blockly.Python.injectId(Blockly.Python.STATEMENT_SUFFIX, block),
|
||||
Blockly.Python.INDENT) + branchCode;
|
||||
}
|
||||
code += 'else:\n' + branchCode;
|
||||
}
|
||||
return code;
|
||||
|
||||
Reference in New Issue
Block a user