From c0ac816fdad9fb43bb66a2aec3d9ca8b4c2cfefc Mon Sep 17 00:00:00 2001 From: Danny Yoo Date: Thu, 1 Sep 2011 12:59:39 -0400 Subject: [PATCH] continuing to work on xexps --- web-world/impl.rkt | 5 ++ web-world/js-impl.js | 96 +++++++++++++++++++++++++++++++++++++++ web-world/racket-impl.rkt | 12 ++++- 3 files changed, 112 insertions(+), 1 deletion(-) diff --git a/web-world/impl.rkt b/web-world/impl.rkt index 7acb896..bd62ce5 100644 --- a/web-world/impl.rkt +++ b/web-world/impl.rkt @@ -65,4 +65,9 @@ view-form-value update-view-form-value view-append-child + + + xexp? + xexp->dom + )) diff --git a/web-world/js-impl.js b/web-world/js-impl.js index 8e3a471..4b639c9 100644 --- a/web-world/js-impl.js +++ b/web-world/js-impl.js @@ -9,6 +9,10 @@ var finalizeClosureCall = plt.baselib.functions.finalizeClosureCall; var PAUSE = plt.runtime.PAUSE; var isString = plt.baselib.strings.isString; + var isSymbol = plt.baselib.symbols.isSymbol; + var isList = plt.baselib.lists.isList; + var isEmpty = plt.baselib.lists.isEmpty; + var listLength = plt.baselib.lists.length; var makeList = plt.baselib.lists.makeList; var makePair = plt.baselib.lists.makePair; var makeSymbol = plt.baselib.symbols.makeSymbol; @@ -1113,6 +1117,78 @@ + + var isAttributeList = function(x) { + var children; + if (isList(x) && (! isEmpty(x))){ + if (isSymbol(x.first) && x.first.val === '@') { + children = x.rest; + while(! isEmpty(children)) { + if (isList(children.first) && + listLength(children.first) === 2 && + isSymbol(children.first.first) && + isString(children.first.rest.first)) { + + children = children.rest; + + } else { + return false; + } + } + return true; + } else { + return false; + } + } else { + return false; + } + }; + + + + // An xexp is one of the following: + // xexp :== (name (@ (key value) ...) xexp ...) + // :== (name xexp ...) + // :== string + var isXexp = function(x) { + var children; + if (isString(x)) { + return true; + } + if (isList(x) && !(isEmpty(x))) { + if (isSymbol(x.first)) { + children = x.rest; + // Check the rest of the children. The first is special. + if (isEmpty(children)) { + return true; + } + if (isAttributeList(children.first)) { + children = children.rest; + } + while (! (isEmpty(children))) { + if (! isXexp(children.first)) { + return false; + } + children = children.rest; + } + return true; + } else { + return false; + } + } + return false; + }; + + + + var xexpToDom = function(x) { + return x; + }; + + + + + ////////////////////////////////////////////////////////////////////// var checkReal = plt.baselib.check.checkReal; @@ -1120,6 +1196,7 @@ var checkSymbolOrString = plt.baselib.check.checkSymbolOrString; var checkProcedure = plt.baselib.check.checkProcedure; + var checkWorldHandler = plt.baselib.check.makeCheckArgumentType( isWorldHandler, 'world handler'); @@ -1132,6 +1209,9 @@ var checkSelector = plt.baselib.check.makeCheckArgumentType( isString, 'selector'); + var checkXexp = plt.baselib.check.makeCheckArgumentType( + isXexp, 'xexp'); + EXPORTS['big-bang'] = makeClosure( 'big-bang', @@ -1508,6 +1588,22 @@ }); + EXPORTS['xexp?'] = makePrimitiveProcedure( + 'xexp?', + 1, + function(MACHINE) { + return isXexp(MACHINE.env[MACHINE.env.length - 1]); + }); + + + EXPORTS['xexp->dom'] = makePrimitiveProcedure( + 'xexp->dom', + 1, + function(MACHINE) { + var xexp = checkXexp(MACHINE, 'xexp->dom', 0); + return xexpToDom(xexp); + }); + ////////////////////////////////////////////////////////////////////// }()); \ No newline at end of file diff --git a/web-world/racket-impl.rkt b/web-world/racket-impl.rkt index d10b69d..cd62fc0 100644 --- a/web-world/racket-impl.rkt +++ b/web-world/racket-impl.rkt @@ -22,7 +22,10 @@ view-hide view-append-child - open-output-element) + open-output-element + + xexp? + xexp->dom) (define (big-bang world . handlers) @@ -142,3 +145,10 @@ (define (open-output-element id) (error 'open-output-element "Please run in JavaScript context.")) + + +(define (xexp? x) + (error 'xexp? "Please run in JavaScript context.")) + +(define (xexp->dom x) + (error 'xexp->dom "Please run in JavaScript context."))