summaryrefslogtreecommitdiff
path: root/src/www/syntax-editor/ast.js
diff options
context:
space:
mode:
authorjohn.j.camilleri <john.j.camilleri@chalmers.se>2012-12-11 15:09:16 +0000
committerjohn.j.camilleri <john.j.camilleri@chalmers.se>2012-12-11 15:09:16 +0000
commit2623925e67b240f289b7ca507dd9c1ae194a93ce (patch)
tree3c34e1296732d09613084d92516a9c2c710dff41 /src/www/syntax-editor/ast.js
parent6ef74e13d68531a07015c32a2ed648e037c32c51 (diff)
Syntax editor: unwrap feature
Diffstat (limited to 'src/www/syntax-editor/ast.js')
-rw-r--r--src/www/syntax-editor/ast.js27
1 files changed, 24 insertions, 3 deletions
diff --git a/src/www/syntax-editor/ast.js b/src/www/syntax-editor/ast.js
index ed8235a79..50c417e96 100644
--- a/src/www/syntax-editor/ast.js
+++ b/src/www/syntax-editor/ast.js
@@ -103,6 +103,9 @@ function AST(fun, cat) {
// return !this.hasParent();
}
+ this.getRoot = function() {
+ return this.root;
+ }
this.getFun = function() {
return this.currentNode.fun;
}
@@ -142,8 +145,8 @@ function AST(fun, cat) {
}
// Wrap the current node inside another node
- // Doesn't check whether child_id is within in range
- this.wrap = function(typeobj, child_id) {
+ // Doesn't check whether child_ix is within in range
+ this.wrap = function(typeobj, child_ix) {
var subtree = new ASTNode(this.currentNode);
this.currentNode.fun = typeobj.name;
this.currentNode.cat = typeobj.ret;
@@ -151,10 +154,28 @@ function AST(fun, cat) {
for (var i in typeobj.args) {
this.add(null, typeobj.args[i]);
}
- this.currentNode.children[child_id] = subtree;
+ this.currentNode.children[child_ix] = subtree;
return subtree;
}
+ // Wrap the current node inside another node
+ // Doesn't check whether child_ix is within in range
+ this.unwrap = function() {
+ var parent_id = this.currentID.clone();
+ parent_id.get().pop();
+ if (parent_id.get().length==1) {
+ this.root = this.currentNode;
+ this.currentID = new NodeID();
+ } else {
+ var gparent_id = parent_id.clone();
+ gparent_id.get().pop();
+ var gparent = this.find(gparent_id);
+ child_ix = parent_id.clone().get().pop();
+ gparent.children[child_ix] = this.currentNode;
+ this.currentID = parent_id;
+ }
+ }
+
// Determine if current node is writable (empty/no children)
this.is_writable=function() {
var cn = this.currentNode;