Commits

firefly  committed 82aab62

Added Group-Time Evaluation (GTE) operators.

  • Participants
  • Parent commits b7ed95c

Comments (0)

Files changed (2)

File src/floop.js

 		throw new Error("Syntax error: " + reason + ". (near '" + error + "')");
 	}
 	
-	Grouper.prototype.add = function(op, func, prec) {
+	Grouper.prototype.add = function(op, func, prec, isGroupTime) {
 		if (op instanceof Array) var op =
-				new Grouper.Operator(op, func, prec, this);
+				new Grouper.Operator(op, func, prec, !!isGroupTime, this);
 		
 		this.operators.push(op);
 		this.operators.sort(function(a, b) {
 		
 		for (var i=0; i<this.operators.length; i++) {
 			for (var j=0; j<tokens.length; j++) {
-				indentation++;
-				var match = this.operators[i].match(tokens.slice(j));
-				indentation--;
+				var op = this.operators[i];
+				var match = op.match(tokens.slice(j));
 				
 				if (match) {
-					tokens.splice(j, match[1], match[0]);
+					var nTree = match[0];
+					
+					if (op.isGroupTime) {
+						nTree = nTree[0].apply(this, nTree.slice(1));
+					}
+					
+					tokens.splice(j, match[1], nTree);
 					j -= match[1] - 1;
 				}
 			}
 		}
 	};
 	
-	Grouper.Operator = function(tokens, func, prec, grouper) {
+	Grouper.Operator = function(tokens, func, prec, isGroupTime, grouper) {
 		this.precedence = prec;
 		this.proto = tokens;
 		this.func = func;
+		this.isGroupTime = isGroupTime;
 		this.grouper = grouper;
 		
 		this.valueArity = 0;

File src/floop.js~

 		throw new Error("Syntax error: " + reason + ". (near '" + error + "')");
 	}
 	
-	Grouper.prototype.add = function(op, func, prec) {
+	Grouper.prototype.add = function(op, func, prec, isGroupTime) {
 		if (op instanceof Array) var op =
-				new Grouper.Operator(op, func, prec, this);
+				new Grouper.Operator(op, func, prec, !!isGroupTime, this);
 		
 		this.operators.push(op);
 		this.operators.sort(function(a, b) {
 		
 		for (var i=0; i<this.operators.length; i++) {
 			for (var j=0; j<tokens.length; j++) {
-				indentation++;
-				var match = this.operators[i].match(tokens.slice(j));
-				indentation--;
+				var op = this.operators[i];
+				var match = op.match(tokens.slice(j));
 				
 				if (match) {
+					if (op.isGroupTime) {
+						
+					}
+					
 					tokens.splice(j, match[1], match[0]);
 					j -= match[1] - 1;
 				}
 		}
 	};
 	
-	Grouper.Operator = function(tokens, func, prec, grouper) {
+	Grouper.Operator = function(tokens, func, prec, isGroupTime, grouper) {
 		this.precedence = prec;
 		this.proto = tokens;
 		this.func = func;
+		this.isGroupTime = isGroupTime;
 		this.grouper = grouper;
 		
 		this.valueArity = 0;