refactor fns in ast

This commit is contained in:
Raghu Rajagopalan
2016-03-27 11:22:30 +05:30
parent f8f0454f33
commit 7b0e2513bd
4 changed files with 11 additions and 11 deletions

View File

@@ -16,7 +16,7 @@ function getId() {
exports.setDirection = function(dir) { exports.setDirection = function(dir) {
direction = dir; direction = dir;
} }
exports.pushCommit = function(msg) { exports.commit = function(msg) {
var commit = { id: getId(), var commit = { id: getId(),
message: msg, message: msg,
parent: head == null ? null : head.id}; parent: head == null ? null : head.id};
@@ -26,12 +26,12 @@ exports.pushCommit = function(msg) {
log.debug("in pushCommit"); log.debug("in pushCommit");
} }
exports.createBranch = function(name) { exports.branch = function(name) {
branches[name] = head != null ? head.id: null; branches[name] = head != null ? head.id: null;
log.debug("in createBranch"); log.debug("in createBranch");
} }
exports.mergeBranch = function() { exports.merge = function() {
log.debug("in mergeBranch"); log.debug("in mergeBranch");
} }
@@ -41,7 +41,7 @@ exports.checkout = function(branch) {
var id = branches[curBranch]; var id = branches[curBranch];
head = commits[id]; head = commits[id];
} }
exports.reset = function () { exports.clear = function () {
commits = {}; commits = {};
head = null; head = null;
branches = { "master" : head }; branches = { "master" : head };

View File

@@ -4,7 +4,7 @@ describe('when parsing a gitGraph',function() {
"use strict"; "use strict";
beforeEach(function () { beforeEach(function () {
parser.yy = ast; parser.yy = ast;
parser.yy.reset(); parser.yy.clear();
}); });
it('should handle a gitGraph defintion', function () { it('should handle a gitGraph defintion', function () {
var str = 'gitGraph:\n' + var str = 'gitGraph:\n' +

View File

@@ -57,10 +57,10 @@ line
; ;
statement statement
: COMMIT commit_arg {yy.pushCommit($2)} : COMMIT commit_arg {yy.commit($2)}
| BRANCH ID {yy.createBranch($2)} | BRANCH ID {yy.branch($2)}
| CHECKOUT ID {yy.checkout($2)} | CHECKOUT ID {yy.checkout($2)}
| MERGE ID {yy.mergeBranch($2)} | MERGE ID {yy.merge($2)}
; ;
commit_arg commit_arg

View File

@@ -101,16 +101,16 @@ case 5:
this.$ =$$[$0-1] this.$ =$$[$0-1]
break; break;
case 7: case 7:
yy.pushCommit($$[$0]) yy.commit($$[$0])
break; break;
case 8: case 8:
yy.createBranch($$[$0]) yy.branch($$[$0])
break; break;
case 9: case 9:
yy.checkout($$[$0]) yy.checkout($$[$0])
break; break;
case 10: case 10:
yy.mergeBranch($$[$0]) yy.merge($$[$0])
break; break;
case 11: case 11:
this.$ = "" this.$ = ""