Commit adc1c5a3 authored by Neil Fraser's avatar Neil Fraser

Restore order of operations on same-order groups.

parent 57d0ffa6
...@@ -208,16 +208,20 @@ Blockly.Generator.prototype.valueToCode = function(block, name, order) { ...@@ -208,16 +208,20 @@ Blockly.Generator.prototype.valueToCode = function(block, name, order) {
if (isNaN(innerOrder)) { if (isNaN(innerOrder)) {
throw 'Expecting valid order from value block "' + targetBlock.type + '".'; throw 'Expecting valid order from value block "' + targetBlock.type + '".';
} }
// 0 is the atomic order, 99 is the none order. No parentheses needed. if (code && order <= innerOrder) {
// In all known languages multiple such code blocks are not order if (order == innerOrder && (order == 0 || order == 99)) {
// sensitive. In fact in Python ('a' 'b') 'c' would fail. // Don't generate parens around NONE-NONE and ATOMIC-ATOMIC pairs.
if (code && order <= innerOrder && order != 0 && order != 99) { // 0 is the atomic order, 99 is the none order. No parentheses needed.
// The operators outside this code are stonger than the operators // In all known languages multiple such code blocks are not order
// inside this code. To prevent the code from being pulled apart, // sensitive. In fact in Python ('a' 'b') 'c' would fail.
// wrap the code in parentheses. } else {
// Technically, this should be handled on a language-by-language basis. // The operators outside this code are stonger than the operators
// However all known (sane) languages use parentheses for grouping. // inside this code. To prevent the code from being pulled apart,
code = '(' + code + ')'; // wrap the code in parentheses.
// Technically, this should be handled on a language-by-language basis.
// However all known (sane) languages use parentheses for grouping.
code = '(' + code + ')';
}
} }
return code; return code;
}; };
......
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