From 58c3e3db85d55cc9b746732583df83c19a9b68e0 Mon Sep 17 00:00:00 2001 From: "john.j.camilleri" Date: Fri, 30 Nov 2012 10:56:42 +0000 Subject: Syntax editor: in-place replacement of functions When at a non-leaf node, refinements with identical type signatures are highlighting and can re placed without destroying the children. If not, the refinement is greyed and the user is asked to clear the current subtree first if they wish to replace it. This aspect of the UI should be polished, but at least it is obvious. Also, some substantial optimizations can still be made to cache the processed type signatures (which determine what can be replaced in-place) --- src/www/syntax-editor/ast.js | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/www/syntax-editor/ast.js') diff --git a/src/www/syntax-editor/ast.js b/src/www/syntax-editor/ast.js index b73448f93..178bc920a 100644 --- a/src/www/syntax-editor/ast.js +++ b/src/www/syntax-editor/ast.js @@ -120,6 +120,29 @@ function AST(fun, cat) { x.children.push(node); } + // Determine if current node is writable (empty/no children) + this.is_writable=function() { + var current = this.getCurrent(); + var blank = current.fun == null || current.children.length == 0; + return blank; + } + + // Determine if a fun would fit in a current hole + this.fits_in_place=function(typeobj) { + var current = this.getCurrent(); + + var inplace = false; + if (typeobj.args.length == current.children.length) { + var matches = 0; + for (var i in typeobj.args) { + if (typeobj.args[i] == current.children[i].cat) + matches++; + } + inplace = matches == current.children.length; + } + return inplace; + } + // Set entire subtree at current node this.setSubtree = function(node) { this._setSubtree(this.current, node); @@ -140,9 +163,9 @@ function AST(fun, cat) { } node.children[lid.shift()] = new ASTNode(subtree); } - } + // Find a node in the tree from its ID this.find = function(id) { var lid = undefined if (Object.prototype.toString.call(id) == "[object Object]") { -- cgit v1.2.3