diff --git a/blockly_compressed.js b/blockly_compressed.js index e2fe56d2d..6da227d31 100644 --- a/blockly_compressed.js +++ b/blockly_compressed.js @@ -1264,14 +1264,15 @@ Blockly.FieldVariable.prototype.init=function(a){this.fieldGroup_||(Blockly.Fiel Blockly.FieldVariable.prototype.setValue=function(a){this.sourceBlock_&&Blockly.Events.isEnabled()&&Blockly.Events.fire(new Blockly.Events.Change(this.sourceBlock_,"field",this.name,this.value_,a));this.value_=a;this.setText(a)}; Blockly.FieldVariable.dropdownCreate=function(){var a=this.sourceBlock_&&this.sourceBlock_.workspace?Blockly.Variables.allVariables(this.sourceBlock_.workspace):[],b=this.getText();b&&-1==a.indexOf(b)&&a.push(b);a.sort(goog.string.caseInsensitiveCompare);a.push(Blockly.Msg.RENAME_VARIABLE);a.push(Blockly.Msg.NEW_VARIABLE);for(var b=[],c=0;c} code A list of Python statements. + * @param {!Array.} code A list of statements. Use ' ' for indents. * @return {string} The actual name of the new function. This may differ * from desiredName if the former has already been taken by the user. * @private @@ -322,8 +322,15 @@ Blockly.Generator.prototype.provideFunction_ = function(desiredName, code) { var functionName = this.variableDB_.getDistinctName(desiredName, this.NAME_TYPE); this.functionNames_[desiredName] = functionName; - this.definitions_[desiredName] = code.join('\n').replace( + var codeText = code.join('\n').replace( this.FUNCTION_NAME_PLACEHOLDER_REGEXP_, functionName); + // Change all ' ' indents into the desired indent. + var oldCodeText; + while (oldCodeText != codeText) { + oldCodeText = codeText; + codeText = codeText.replace(/^(( )*) /gm, '$1' + this.INDENT); + } + this.definitions_[desiredName] = codeText; } return this.functionNames_[desiredName]; }; diff --git a/generators/python.js b/generators/python.js index 9a227b2bf..8c576f582 100644 --- a/generators/python.js +++ b/generators/python.js @@ -79,16 +79,15 @@ Blockly.Python.ORDER_CONDITIONAL = 15; // if else Blockly.Python.ORDER_LAMBDA = 16; // lambda Blockly.Python.ORDER_NONE = 99; // (...) -/** - * Empty loops or conditionals are not allowed in Python. - */ -Blockly.Python.PASS = ' pass\n'; - /** * Initialise the database of variable names. * @param {!Blockly.Workspace} workspace Workspace to generate code from. */ Blockly.Python.init = function(workspace) { + /** + * Empty loops or conditionals are not allowed in Python. + */ + Blockly.Python.PASS = this.INDENT + 'pass\n'; // Create a dictionary of definitions to be printed before the code. Blockly.Python.definitions_ = Object.create(null); // Create a dictionary mapping desired function names in definitions_ diff --git a/python_compressed.js b/python_compressed.js index f2e8a0d42..ea13b4007 100644 --- a/python_compressed.js +++ b/python_compressed.js @@ -5,9 +5,9 @@ // Copyright 2012 Google Inc. Apache License 2.0 Blockly.Python=new Blockly.Generator("Python");Blockly.Python.addReservedWords("and,as,assert,break,class,continue,def,del,elif,else,except,exec,finally,for,from,global,if,import,in,is,lambda,not,or,pass,print,raise,return,try,while,with,yield,True,False,None,NotImplemented,Ellipsis,__debug__,quit,exit,copyright,license,credits,abs,divmod,input,open,staticmethod,all,enumerate,int,ord,str,any,eval,isinstance,pow,sum,basestring,execfile,issubclass,print,super,bin,file,iter,property,tuple,bool,filter,len,range,type,bytearray,float,list,raw_input,unichr,callable,format,locals,reduce,unicode,chr,frozenset,long,reload,vars,classmethod,getattr,map,repr,xrange,cmp,globals,max,reversed,zip,compile,hasattr,memoryview,round,__import__,complex,hash,min,set,apply,delattr,help,next,setattr,buffer,dict,hex,object,slice,coerce,dir,id,oct,sorted,intern"); Blockly.Python.ORDER_ATOMIC=0;Blockly.Python.ORDER_COLLECTION=1;Blockly.Python.ORDER_STRING_CONVERSION=1;Blockly.Python.ORDER_MEMBER=2;Blockly.Python.ORDER_FUNCTION_CALL=2;Blockly.Python.ORDER_EXPONENTIATION=3;Blockly.Python.ORDER_UNARY_SIGN=4;Blockly.Python.ORDER_BITWISE_NOT=4;Blockly.Python.ORDER_MULTIPLICATIVE=5;Blockly.Python.ORDER_ADDITIVE=6;Blockly.Python.ORDER_BITWISE_SHIFT=7;Blockly.Python.ORDER_BITWISE_AND=8;Blockly.Python.ORDER_BITWISE_XOR=9;Blockly.Python.ORDER_BITWISE_OR=10; -Blockly.Python.ORDER_RELATIONAL=11;Blockly.Python.ORDER_LOGICAL_NOT=12;Blockly.Python.ORDER_LOGICAL_AND=13;Blockly.Python.ORDER_LOGICAL_OR=14;Blockly.Python.ORDER_CONDITIONAL=15;Blockly.Python.ORDER_LAMBDA=16;Blockly.Python.ORDER_NONE=99;Blockly.Python.PASS=" pass\n"; -Blockly.Python.init=function(a){Blockly.Python.definitions_=Object.create(null);Blockly.Python.functionNames_=Object.create(null);Blockly.Python.variableDB_?Blockly.Python.variableDB_.reset():Blockly.Python.variableDB_=new Blockly.Names(Blockly.Python.RESERVED_WORDS_);var b=[];a=Blockly.Variables.allVariables(a);for(var c=0;c