summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjmoenig <jens@moenig.org>2013-06-24 17:49:47 +0200
committerjmoenig <jens@moenig.org>2013-06-24 17:49:47 +0200
commit416d92d78b4e72fc9c3ccbc41c1ef98874d7e500 (patch)
tree50175a5e337c3abab06e79e940ae52689c5aeb8e
parent8ef095c7196e10bcfe533851a26d162a730947e9 (diff)
downloadsnap-yow-416d92d78b4e72fc9c3ccbc41c1ef98874d7e500.tar.gz
snap-yow-416d92d78b4e72fc9c3ccbc41c1ef98874d7e500.zip
pretty printing support for mapped code
better formatting capabilites now support Python mappings
-rw-r--r--blocks.js68
-rwxr-xr-xhistory.txt4
-rw-r--r--objects.js4
3 files changed, 39 insertions, 37 deletions
diff --git a/blocks.js b/blocks.js
index 942eae4..46a7e7e 100644
--- a/blocks.js
+++ b/blocks.js
@@ -155,7 +155,7 @@ DialogBoxMorph, BlockInputFragmentMorph, PrototypeHatBlockMorph*/
// Global stuff ////////////////////////////////////////////////////////
-modules.blocks = '2013-June-21';
+modules.blocks = '2013-June-24';
var SyntaxElementMorph;
var BlockMorph;
@@ -2227,30 +2227,6 @@ 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,
- code,
codeLines,
count = 1,
parts = [];
@@ -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 () {
diff --git a/history.txt b/history.txt
index 906062b..77f996c 100755
--- a/history.txt
+++ b/history.txt
@@ -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
diff --git a/objects.js b/objects.js
index 9652752..9f7e5b9 100644
--- a/objects.js
+++ b/objects.js
@@ -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;