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:
Neil Fraser
2019-05-14 13:59:19 -07:00
committed by Neil Fraser
parent 25adb40e66
commit c0e14c3a7c
19 changed files with 210 additions and 73 deletions

View File

@@ -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;