constructor printing
This commit is contained in:
parent
bcf19edfe4
commit
9a7ee2dff4
|
@ -2,5 +2,6 @@
|
|||
|
||||
;; Like the big whalesong language, but with additional ASL restrictions.
|
||||
|
||||
(current-print-mode "constructor")
|
||||
|
||||
(provide (all-from-out "../lang/whalesong.rkt"))
|
|
@ -43,10 +43,16 @@
|
|||
};
|
||||
|
||||
Box.prototype.toDomNode = function(params) {
|
||||
var parent = document.createElement("span");
|
||||
parent.appendChild(document.createTextNode('#&'));
|
||||
parent.appendChild(params.recur(this.val));
|
||||
return parent;
|
||||
var node = document.createElement("span");
|
||||
if (params.getMode() === 'constructor') {
|
||||
node.appendChild(document.createTextNode("(box "));
|
||||
node.appendChild(params.recur(this.val));
|
||||
node.appendChild(document.createTextNode(")"));
|
||||
} else {
|
||||
node.appendChild(document.createTextNode('#&'));
|
||||
node.appendChild(params.recur(this.val));
|
||||
}
|
||||
return node;
|
||||
};
|
||||
|
||||
Box.prototype.equals = function(other, aUnionFind) {
|
||||
|
|
|
@ -390,7 +390,7 @@
|
|||
if (typeof(x) === 'string') {
|
||||
var wrapper = document.createElement("span");
|
||||
wrapper.style["white-space"] = "pre";
|
||||
if (params.getMode() === 'write' || params.getMode() === 'print') {
|
||||
if (params.getMode() === 'write' || params.getMode() === 'print' || params.getMode() === 'constructor') {
|
||||
node = document.createTextNode(toWrittenString(x));
|
||||
} else {
|
||||
node = document.createTextNode(toDisplayedString(x));
|
||||
|
|
|
@ -174,11 +174,11 @@
|
|||
} else {
|
||||
node = document.createElement("span");
|
||||
node.appendChild(document.createTextNode("("));
|
||||
node.appendChild(document.createTextElement("list"));
|
||||
node.appendChild(document.createTextElement(" "));
|
||||
node.appendChild(document.createTextNode("list"));
|
||||
node.appendChild(document.createTextNode(" "));
|
||||
node.appendChild(subelts[0]);
|
||||
for (i = 1; i < subelts.length; i++) {
|
||||
node.appendChild(document.createTextElement(" "));
|
||||
node.appendChild(document.createTextNode(" "));
|
||||
node.appendChild(subelts[i]);
|
||||
}
|
||||
node.appendChild(document.createTextNode(")"));
|
||||
|
|
|
@ -265,6 +265,19 @@
|
|||
});
|
||||
|
||||
|
||||
installPrimitiveProcedure(
|
||||
'current-print-mode',
|
||||
makeList(0, 1),
|
||||
function (M) {
|
||||
if (M.a === 1) {
|
||||
M.params['print-mode'] = checkString(M, 'print-mode', 0);
|
||||
return VOID;
|
||||
} else {
|
||||
return M.params['print-mode'];
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
installPrimitiveProcedure(
|
||||
'current-output-port',
|
||||
makeList(0, 1),
|
||||
|
|
|
@ -44,6 +44,28 @@
|
|||
return this.val;
|
||||
};
|
||||
|
||||
Symbol.prototype.toDomNode = function(params) {
|
||||
if (params.getMode() === 'write') {
|
||||
return $("<span/>").text(this.val).get(0);
|
||||
}
|
||||
if (params.getMode() === 'display') {
|
||||
return $("<span/>").text(this.val).get(0);
|
||||
}
|
||||
if (params.getMode() === 'print') {
|
||||
if (params.getDepth() === 0) {
|
||||
return $("<span/>").text("'" + this.val).get(0);
|
||||
} else {
|
||||
return $("<span/>").text(this.val).get(0);
|
||||
}
|
||||
}
|
||||
if (params.getMode() === 'constructor') {
|
||||
return $("<span/>").text("'" + this.val).get(0);
|
||||
}
|
||||
|
||||
return $("<span/>").text(this.val).get(0);
|
||||
};
|
||||
|
||||
|
||||
|
||||
var isSymbol = function (x) { return x instanceof Symbol; };
|
||||
|
||||
|
|
|
@ -84,14 +84,23 @@
|
|||
|
||||
Vector.prototype.toDomNode = function (params) {
|
||||
var node = document.createElement("span"), i;
|
||||
node.appendChild(document.createTextNode("#("));
|
||||
for (i = 0; i < this.length(); i++) {
|
||||
node.appendChild(params.recur(this.ref(i)));
|
||||
if (i !== this.length() - 1) {
|
||||
if (params.getMode() === 'constructor') {
|
||||
node.appendChild(document.createTextNode("(vector"));
|
||||
for (i = 0; i < this.length(); i++) {
|
||||
node.appendChild(document.createTextNode(" "));
|
||||
node.appendChild(params.recur(this.ref(i)));
|
||||
}
|
||||
node.appendChild(document.createTextNode(")"));
|
||||
} else {
|
||||
node.appendChild(document.createTextNode("#("));
|
||||
for (i = 0; i < this.length(); i++) {
|
||||
node.appendChild(params.recur(this.ref(i)));
|
||||
if (i !== this.length() - 1) {
|
||||
node.appendChild(document.createTextNode(" "));
|
||||
}
|
||||
}
|
||||
node.appendChild(document.createTextNode(")"));
|
||||
}
|
||||
node.appendChild(document.createTextNode(")"));
|
||||
return node;
|
||||
};
|
||||
|
||||
|
|
|
@ -27,6 +27,15 @@
|
|||
(define e (racket:exp 1))
|
||||
|
||||
|
||||
(define my-current-print-mode "write")
|
||||
(define current-print-mode
|
||||
(case-lambda
|
||||
[() my-current-print-mode]
|
||||
[(v) (set! my-current-print-mode v)]))
|
||||
|
||||
(provide current-print-mode)
|
||||
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; Primitive function stubs
|
||||
|
||||
|
@ -188,6 +197,9 @@
|
|||
|
||||
current-output-port
|
||||
current-print
|
||||
|
||||
|
||||
|
||||
write
|
||||
write-byte
|
||||
display
|
||||
|
|
12
tests/more-tests/printing.expected
Normal file
12
tests/more-tests/printing.expected
Normal file
|
@ -0,0 +1,12 @@
|
|||
(list 1 2 3)
|
||||
(list "hello" "world")
|
||||
(list 'hello 'world)
|
||||
(cons 1 2)
|
||||
(list 1 2 3)
|
||||
(cons 1 (cons 2 (cons 3 4)))
|
||||
(list)
|
||||
'hello
|
||||
(box 'hello)
|
||||
(vector 'hello 'world)
|
||||
(person 'danny 32)
|
||||
(person "jerry" 32)
|
20
tests/more-tests/printing.rkt
Normal file
20
tests/more-tests/printing.rkt
Normal file
|
@ -0,0 +1,20 @@
|
|||
#lang planet dyoo/whalesong/base
|
||||
|
||||
(current-print-mode "constructor")
|
||||
|
||||
|
||||
'(1 2 3)
|
||||
(list "hello" "world")
|
||||
(list 'hello 'world)
|
||||
(cons 1 2)
|
||||
(cons 1 (cons 2 (cons 3 empty)))
|
||||
(cons 1 (cons 2 (cons 3 4)))
|
||||
'()
|
||||
|
||||
'hello
|
||||
(box 'hello)
|
||||
(vector 'hello 'world)
|
||||
|
||||
(define-struct person (name age))
|
||||
(person 'danny 32)
|
||||
(person "jerry" 32)
|
|
@ -13,6 +13,7 @@
|
|||
(test "more-tests/numbers.rkt")
|
||||
(test "more-tests/hello.rkt")
|
||||
(test "more-tests/sharing.rkt")
|
||||
(test "more-tests/printing.rkt")
|
||||
(test "more-tests/simple-functions.rkt")
|
||||
(test "more-tests/map.rkt")
|
||||
(test "more-tests/quasi.rkt")
|
||||
|
|
Loading…
Reference in New Issue
Block a user