kopia lustrzana https://github.com/backface/turtlestitch
pretty printing support for mapped code
better formatting capabilites now support Python mappingspull/3/merge
rodzic
8ef095c719
commit
416d92d78b
68
blocks.js
68
blocks.js
|
@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.blocks = '2013-June-21';
|
modules.blocks = '2013-June-24';
|
||||||
|
|
||||||
var SyntaxElementMorph;
|
var SyntaxElementMorph;
|
||||||
var BlockMorph;
|
var BlockMorph;
|
||||||
|
@ -2223,30 +2223,6 @@ BlockMorph.prototype.mapCode = function (aString, key) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
BlockMorph.prototype.mappedCode = function () {
|
|
||||||
var key = this.selector.substr(0, 5) === 'reify' ?
|
|
||||||
'reify' : this.selector,
|
|
||||||
code,
|
|
||||||
count = 1,
|
|
||||||
parts = [];
|
|
||||||
code = key === 'reportGetVar' ? this.blockSpec
|
|
||||||
: this.definition ? this.definition.codeMapping || ''
|
|
||||||
: StageMorph.prototype.codeMappings[key] || '';
|
|
||||||
this.inputs().forEach(function (input) {
|
|
||||||
parts.push(input.mappedCode());
|
|
||||||
});
|
|
||||||
parts.forEach(function (part) {
|
|
||||||
var rx = new RegExp('<#' + count + '>', 'g');
|
|
||||||
code = code.replace(rx, part);
|
|
||||||
count += 1;
|
|
||||||
});
|
|
||||||
if (this.nextBlock && this.nextBlock()) { // Command
|
|
||||||
code += this.nextBlock().mappedCode();
|
|
||||||
}
|
|
||||||
return code;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* // under construction - pretty printing
|
|
||||||
BlockMorph.prototype.mappedCode = function () {
|
BlockMorph.prototype.mappedCode = function () {
|
||||||
var key = this.selector.substr(0, 5) === 'reify' ?
|
var key = this.selector.substr(0, 5) === 'reify' ?
|
||||||
'reify' : this.selector,
|
'reify' : this.selector,
|
||||||
|
@ -2259,30 +2235,33 @@ BlockMorph.prototype.mappedCode = function () {
|
||||||
: StageMorph.prototype.codeMappings[key] || '';
|
: StageMorph.prototype.codeMappings[key] || '';
|
||||||
codeLines = code.split('\n');
|
codeLines = code.split('\n');
|
||||||
this.inputs().forEach(function (input) {
|
this.inputs().forEach(function (input) {
|
||||||
parts.push(input.mappedCode());
|
parts.push(input.mappedCode().toString());
|
||||||
});
|
});
|
||||||
parts.forEach(function (part) {
|
parts.forEach(function (part) {
|
||||||
var partLines = part.split('\n'),
|
var partLines = part.split('\n'),
|
||||||
placeHolder = '<#' + count + '>',
|
placeHolder = '<#' + count + '>',
|
||||||
rx = new RegExp(placeHolder, 'g');
|
rx = new RegExp(placeHolder, 'g');
|
||||||
codeLines.forEach(function (codeLine) {
|
codeLines.forEach(function (codeLine, idx) {
|
||||||
var prefix = '',
|
var prefix = '',
|
||||||
indent;
|
indent;
|
||||||
if (codeLine.trimLeft().startsWith(placeHolder)) {
|
if (codeLine.trimLeft().indexOf(placeHolder) === 0) {
|
||||||
indent = codeLine.indexOf(placeHolder);
|
indent = codeLine.indexOf(placeHolder);
|
||||||
prefix = codeLine.slice(0, indent);
|
prefix = codeLine.slice(0, indent);
|
||||||
}
|
}
|
||||||
code = codeLine.replace(new RexExp(placeHolder), part);
|
codeLines[idx] = codeLine.replace(
|
||||||
code = code.replace(rx, part);
|
new RegExp(placeHolder),
|
||||||
|
partLines.join('\n' + prefix)
|
||||||
|
);
|
||||||
|
codeLines[idx] = codeLines[idx].replace(rx, partLines.join('\n'));
|
||||||
});
|
});
|
||||||
count += 1;
|
count += 1;
|
||||||
});
|
});
|
||||||
|
code = codeLines.join('\n');
|
||||||
if (this.nextBlock && this.nextBlock()) { // Command
|
if (this.nextBlock && this.nextBlock()) { // Command
|
||||||
code += this.nextBlock().mappedCode();
|
code += ('\n' + this.nextBlock().mappedCode());
|
||||||
}
|
}
|
||||||
return code;
|
return code;
|
||||||
};
|
};
|
||||||
*/
|
|
||||||
|
|
||||||
BlockMorph.prototype.codeMappingHeader = function () {
|
BlockMorph.prototype.codeMappingHeader = function () {
|
||||||
var block = this.definition ? this.definition.blockInstance()
|
var block = this.definition ? this.definition.blockInstance()
|
||||||
|
@ -5425,11 +5404,30 @@ CSlotMorph.prototype.getSpec = function () {
|
||||||
|
|
||||||
CSlotMorph.prototype.mappedCode = function () {
|
CSlotMorph.prototype.mappedCode = function () {
|
||||||
var code = StageMorph.prototype.codeMappings.reify || '<#1>',
|
var code = StageMorph.prototype.codeMappings.reify || '<#1>',
|
||||||
part = this.nestedBlock(),
|
codeLines = code.split('\n'),
|
||||||
nestedCode = part ? part.mappedCode() : '';
|
nested = this.nestedBlock(),
|
||||||
return code.replace(/<#1>/g, nestedCode);
|
part = nested ? nested.mappedCode() : '',
|
||||||
|
partLines = (part.toString()).split('\n'),
|
||||||
|
rx = new RegExp('<#1>', 'g');
|
||||||
|
|
||||||
|
codeLines.forEach(function (codeLine, idx) {
|
||||||
|
var prefix = '',
|
||||||
|
indent;
|
||||||
|
if (codeLine.trimLeft().indexOf('<#1>') === 0) {
|
||||||
|
indent = codeLine.indexOf('<#1>');
|
||||||
|
prefix = codeLine.slice(0, indent);
|
||||||
|
}
|
||||||
|
codeLines[idx] = codeLine.replace(
|
||||||
|
new RegExp('<#1>'),
|
||||||
|
partLines.join('\n' + prefix)
|
||||||
|
);
|
||||||
|
codeLines[idx] = codeLines[idx].replace(rx, partLines.join('\n'));
|
||||||
|
});
|
||||||
|
|
||||||
|
return codeLines.join('\n');
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// CSlotMorph layout:
|
// CSlotMorph layout:
|
||||||
|
|
||||||
CSlotMorph.prototype.fixLayout = function () {
|
CSlotMorph.prototype.fixLayout = function () {
|
||||||
|
|
|
@ -1753,3 +1753,7 @@ ______
|
||||||
------
|
------
|
||||||
* Morphic, Blocks: "flat" design fix: Handle manually "unshadowed" StringMorphs
|
* Morphic, Blocks: "flat" design fix: Handle manually "unshadowed" StringMorphs
|
||||||
* Objects, Blocks: %code input slot - multi-line, monospaced, type-in slot for code mappings
|
* Objects, Blocks: %code input slot - multi-line, monospaced, type-in slot for code mappings
|
||||||
|
|
||||||
|
130624
|
||||||
|
------
|
||||||
|
* Objects, Blocks: pretty printing for mapped code, now supporting Python mappings
|
||||||
|
|
|
@ -123,7 +123,7 @@ PrototypeHatBlockMorph*/
|
||||||
|
|
||||||
// Global stuff ////////////////////////////////////////////////////////
|
// Global stuff ////////////////////////////////////////////////////////
|
||||||
|
|
||||||
modules.objects = '2013-June-21';
|
modules.objects = '2013-June-24';
|
||||||
|
|
||||||
var SpriteMorph;
|
var SpriteMorph;
|
||||||
var StageMorph;
|
var StageMorph;
|
||||||
|
@ -5200,7 +5200,7 @@ CellMorph.prototype.drawNew = function () {
|
||||||
null,
|
null,
|
||||||
true,
|
true,
|
||||||
false,
|
false,
|
||||||
'center'
|
'left' // was formerly 'center', reverted b/c of code-mapping
|
||||||
);
|
);
|
||||||
if (this.isEditable) {
|
if (this.isEditable) {
|
||||||
this.contentsMorph.isEditable = true;
|
this.contentsMorph.isEditable = true;
|
||||||
|
|
Ładowanie…
Reference in New Issue