Skip to content
This repository has been archived by the owner on Dec 2, 2020. It is now read-only.

Grammar update: lock expression #136

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
node_modules
.jshintrc
Procfile
*.un~
*.swo
*.swp
118 changes: 97 additions & 21 deletions lib/cube/event-expression.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion lib/cube/event-expression.peg
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,14 @@
}

start
= _ expression:event_expression _ { expression.source = input; return expression; }
= _ expression:event_expression _ ":" _ lock_expression:event_expression _
{
var uf = expression.filter;
expression.type = lock_expression.type;
expression.filter = function(filter) { uf(filter); lock_expression.filter(filter); };
return expression;
}
/ _ expression:event_expression _ { expression.source = input; return expression; }

event_expression
= value:event_value_expression filters:(_ "." _ event_filter_expression)*
Expand Down
118 changes: 97 additions & 21 deletions lib/cube/metric-expression.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion lib/cube/metric-expression.peg
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,14 @@
}

start
= _ expression:metric_additive_expression _ { return expression; }
= _ expression:metric_additive_expression _ ":" _ lock_expression:event_expression _
{
var uf = expression.filter;
expression.type = lock_expression.type;
expression.filter = function(filter){ uf(filter); lock_expression.filter(filter); };
return expression;
}
/ _ expression:metric_additive_expression _ { return expression; }

metric_additive_expression
= head:metric_multiplicative_expression tail:(_ additive_operator _ metric_additive_expression)* { return compoundMetric(head, tail); }
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"dependencies": {
"mongodb": "~1.3.18",
"node-static": "0.6.5",
"pegjs": "0.7.0",
"pegjs": "0.6.2",
"vows": "0.7.0",
"websocket": "1.0.8",
"websocket-server": "1.4.04"
Expand Down
12 changes: 11 additions & 1 deletion test/event-expression-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,18 @@ suite.addBatch({
parser.parse("test.in(i, [\"foo\", 42])").filter(filter);
assert.deepEqual(filter, {"d.i": {$in: ["foo", 42]}});
}
},
"lock expression": {
"lock expression merges additional filters": function() {
var filter = {};
parser.parse("test.gt(i, 42):test.le(i, 52)").filter(filter);
assert.deepEqual(filter, {"d.i": {$gt: 42, $lte: 52}});
},
"lock expression results in expected type": function() {
var e = parser.parse("test1.gt(i, 42):test.le(i, 52)");
assert.equal(e.type, "test")
}
}

});

suite.export(module);
14 changes: 12 additions & 2 deletions test/metric-expression-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ var vows = require("vows"),
var suite = vows.describe("metric-expression");

suite.addBatch({

"a simple unary expression, sum(test)": {
topic: parser.parse("sum(test)"),
"is unary (has no associated binary operator)": function(e) {
Expand Down Expand Up @@ -295,9 +295,19 @@ suite.addBatch({
var filter = {};
parser.parse("sum(test.in(i, [\"foo\", 42]))").filter(filter);
assert.deepEqual(filter, {"d.i": {$in: ["foo", 42]}});
},
},
"lock expression": {
"lock expression merges additional filters": function() {
var filter = {};
parser.parse("sum(test.gt(i, 42)):test.le(i, 52)").filter(filter);
assert.deepEqual(filter, {"d.i": {$gt: 42, $lte: 52}});
},
"lock expression results in expected type": function() {
var e = parser.parse("sum(test1.gt(i, 42)):test.le(i, 52)");
assert.equal(e.type, "test")
}
}

});

suite.export(module);