Update to latest version.

This commit is contained in:
Neil Fraser
2014-09-08 14:26:52 -07:00
parent 58f264f4ce
commit d998a1c8ec
737 changed files with 29546 additions and 27625 deletions

View File

@@ -29,6 +29,10 @@ goog.provide('Blockly.Python');
goog.require('Blockly.Generator');
/**
* Python code generator.
* @type !Blockly.Generator
*/
Blockly.Python = new Blockly.Generator('Python');
/**
@@ -75,14 +79,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.
*/
@@ -93,22 +89,20 @@ Blockly.Python.init = function() {
// to actual function names (to avoid collisions with user functions).
Blockly.Python.functionNames_ = Object.create(null);
if (Blockly.Variables) {
if (!Blockly.Python.variableDB_) {
Blockly.Python.variableDB_ =
new Blockly.Names(Blockly.Python.RESERVED_WORDS_);
} else {
Blockly.Python.variableDB_.reset();
}
var defvars = [];
var variables = Blockly.Variables.allVariables();
for (var x = 0; x < variables.length; x++) {
defvars[x] = Blockly.Python.variableDB_.getName(variables[x],
Blockly.Variables.NAME_TYPE) + ' = None';
}
Blockly.Python.definitions_['variables'] = defvars.join('\n');
if (!Blockly.Python.variableDB_) {
Blockly.Python.variableDB_ =
new Blockly.Names(Blockly.Python.RESERVED_WORDS_);
} else {
Blockly.Python.variableDB_.reset();
}
var defvars = [];
var variables = Blockly.Variables.allVariables();
for (var x = 0; x < variables.length; x++) {
defvars[x] = Blockly.Python.variableDB_.getName(variables[x],
Blockly.Variables.NAME_TYPE) + ' = None';
}
Blockly.Python.definitions_['variables'] = defvars.join('\n');
};
/**
@@ -164,21 +158,16 @@ Blockly.Python.quote_ = function(string) {
* @param {!Blockly.Block} block The current block.
* @param {string} code The Python code created for this block.
* @return {string} Python code with comments and subsequent blocks added.
* @this {Blockly.CodeGenerator}
* @private
*/
Blockly.Python.scrub_ = function(block, code) {
if (code === null) {
// Block has handled code generation itself.
return '';
}
var commentCode = '';
// Only collect comments for blocks that aren't inline.
if (!block.outputConnection || !block.outputConnection.targetConnection) {
// Collect comment for this block.
var comment = block.getCommentText();
if (comment) {
commentCode += this.prefixLines(comment, '# ') + '\n';
commentCode += Blockly.Python.prefixLines(comment, '# ') + '\n';
}
// Collect comments for all value arguments.
// Don't collect comments for nested statements.
@@ -186,15 +175,15 @@ Blockly.Python.scrub_ = function(block, code) {
if (block.inputList[x].type == Blockly.INPUT_VALUE) {
var childBlock = block.inputList[x].connection.targetBlock();
if (childBlock) {
var comment = this.allNestedComments(childBlock);
var comment = Blockly.Python.allNestedComments(childBlock);
if (comment) {
commentCode += this.prefixLines(comment, '# ');
commentCode += Blockly.Python.prefixLines(comment, '# ');
}
}
}
}
}
var nextBlock = block.nextConnection && block.nextConnection.targetBlock();
var nextCode = this.blockToCode(nextBlock);
var nextCode = Blockly.Python.blockToCode(nextBlock);
return commentCode + code + nextCode;
};