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

View File

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

View File

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

View File

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