diff options
| author | john.j.camilleri <john.j.camilleri@chalmers.se> | 2012-12-07 15:32:31 +0000 |
|---|---|---|
| committer | john.j.camilleri <john.j.camilleri@chalmers.se> | 2012-12-07 15:32:31 +0000 |
| commit | 953b6b573ac9094f2152139ea349c14ef167a638 (patch) | |
| tree | 66c2b1ae8041e5e9a84786604c9b399edc762440 /src/www/syntax-editor/ast.js | |
| parent | c4931fccaf6ae5ed2c6d164f53f13d5d55c76a72 (diff) | |
Syntax editor: change startcat when wrapping top node
Diffstat (limited to 'src/www/syntax-editor/ast.js')
| -rw-r--r-- | src/www/syntax-editor/ast.js | 24 |
1 files changed, 14 insertions, 10 deletions
diff --git a/src/www/syntax-editor/ast.js b/src/www/syntax-editor/ast.js index 026452697..ed8235a79 100644 --- a/src/www/syntax-editor/ast.js +++ b/src/www/syntax-editor/ast.js @@ -94,6 +94,15 @@ function AST(fun, cat) { this.currentNode = this.find(this.currentID); } + this.hasParent = function() { + return this.currentID.get().length > 1; + // return !this.atRoot(); + } + this.atRoot = function() { + return this.currentNode == this.root; + // return !this.hasParent(); + } + this.getFun = function() { return this.currentNode.fun; } @@ -107,10 +116,6 @@ function AST(fun, cat) { this.currentNode.cat = c; } - this.hasParent = function() { - return this.currentID.get().length > 1; - } - // Add a single type dependency at current node this.addDep = function(k, type) { // Add unassigned type variable to current @@ -140,7 +145,7 @@ function AST(fun, cat) { // Doesn't check whether child_id is within in range this.wrap = function(typeobj, child_id) { var subtree = new ASTNode(this.currentNode); - this.currentNode.fun = typeobj.name.join(" "); + this.currentNode.fun = typeobj.name; this.currentNode.cat = typeobj.ret; this.currentNode.children = []; for (var i in typeobj.args) { @@ -185,15 +190,14 @@ function AST(fun, cat) { if (lid.length==1) { // Insert at root - this.root = new ASTNode(subtree); - this.currentNode = this.root; + this.currentNode = this.root = new ASTNode(subtree); } else { lid.shift(); // throw away root while (lid.length>1 && node.hasChildren()) { node = node.children[lid.shift()]; } - node.children[lid.shift()] = new ASTNode(subtree); + this.currentNode = node.children[lid.shift()] = new ASTNode(subtree); } } @@ -301,7 +305,7 @@ AST.parse_type_signature = function(str) { var obj = { signature: str, type: undefined, - name: [], + name: undefined, deps: [], args: [], ret: undefined @@ -313,7 +317,7 @@ AST.parse_type_signature = function(str) { obj.type = bits[0]; // name (possibly with constructors) - obj.name = bits.slice(1); + obj.name = bits.slice(1).join(" "); // function args (possibly with type dependency) var regex_dep = new RegExp(/\(\s*(.+?)\s*:\s*(.+?)\s*\)/); |
