pretty printing support for mapped code

better formatting capabilites now support Python mappings
pull/3/merge
jmoenig 2013-06-24 17:49:47 +02:00
rodzic 8ef095c719
commit 416d92d78b
3 zmienionych plików z 39 dodań i 37 usunięć

Wyświetl plik

@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.blocks = '2013-June-21';
modules.blocks = '2013-June-24';
var SyntaxElementMorph;
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 () {
var key = this.selector.substr(0, 5) === 'reify' ?
'reify' : this.selector,
@ -2259,30 +2235,33 @@ BlockMorph.prototype.mappedCode = function () {
: StageMorph.prototype.codeMappings[key] || '';
codeLines = code.split('\n');
this.inputs().forEach(function (input) {
parts.push(input.mappedCode());
parts.push(input.mappedCode().toString());
});
parts.forEach(function (part) {
var partLines = part.split('\n'),
placeHolder = '<#' + count + '>',
rx = new RegExp(placeHolder, 'g');
codeLines.forEach(function (codeLine) {
codeLines.forEach(function (codeLine, idx) {
var prefix = '',
indent;
if (codeLine.trimLeft().startsWith(placeHolder)) {
if (codeLine.trimLeft().indexOf(placeHolder) === 0) {
indent = codeLine.indexOf(placeHolder);
prefix = codeLine.slice(0, indent);
}
code = codeLine.replace(new RexExp(placeHolder), part);
code = code.replace(rx, part);
codeLines[idx] = codeLine.replace(
new RegExp(placeHolder),
partLines.join('\n' + prefix)
);
codeLines[idx] = codeLines[idx].replace(rx, partLines.join('\n'));
});
count += 1;
});
code = codeLines.join('\n');
if (this.nextBlock && this.nextBlock()) { // Command
code += this.nextBlock().mappedCode();
code += ('\n' + this.nextBlock().mappedCode());
}
return code;
};
*/
BlockMorph.prototype.codeMappingHeader = function () {
var block = this.definition ? this.definition.blockInstance()
@ -5425,11 +5404,30 @@ CSlotMorph.prototype.getSpec = function () {
CSlotMorph.prototype.mappedCode = function () {
var code = StageMorph.prototype.codeMappings.reify || '<#1>',
part = this.nestedBlock(),
nestedCode = part ? part.mappedCode() : '';
return code.replace(/<#1>/g, nestedCode);
codeLines = code.split('\n'),
nested = this.nestedBlock(),
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.prototype.fixLayout = function () {

Wyświetl plik

@ -1753,3 +1753,7 @@ ______
------
* Morphic, Blocks: "flat" design fix: Handle manually "unshadowed" StringMorphs
* 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

Wyświetl plik

@ -123,7 +123,7 @@ PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
modules.objects = '2013-June-21';
modules.objects = '2013-June-24';
var SpriteMorph;
var StageMorph;
@ -5200,7 +5200,7 @@ CellMorph.prototype.drawNew = function () {
null,
true,
false,
'center'
'left' // was formerly 'center', reverted b/c of code-mapping
);
if (this.isEditable) {
this.contentsMorph.isEditable = true;