Skip to content

Commit 18150b0

Browse files
committed
optional colon for domain:type in event expressions
1 parent fd517e9 commit 18150b0

File tree

4 files changed

+49
-37
lines changed

4 files changed

+49
-37
lines changed

packages/krl-parser/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,6 @@
4646
"dependencies": {
4747
"excerpt-at-line-col": "^1.0.0",
4848
"line-column": "^1.0.2",
49-
"nearley": "^2.16.0"
49+
"nearley": "2.16.0"
5050
}
5151
}

packages/krl-parser/src/grammar.js

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -657,61 +657,67 @@ var grammar = {
657657
{"name": "event_exp_fns", "symbols": [tok_repeat, "PositiveInteger", tok_OPEN_PAREN, "IndividualEventExpression", tok_CLSE_PAREN, "event_exp_fns$ebnf$2"], "postprocess": eventGroupOp("repeat", 1, 3, 5)},
658658
{"name": "event_exp_base", "symbols": [tok_OPEN_PAREN, "EventExpression", tok_CLSE_PAREN], "postprocess": getN(1)},
659659
{"name": "event_exp_base", "symbols": ["IndividualEventExpression"], "postprocess": id},
660-
{"name": "IndividualEventExpression$ebnf$1$subexpression$1$ebnf$1", "symbols": ["event_exp_attribute_pair"]},
661-
{"name": "IndividualEventExpression$ebnf$1$subexpression$1$ebnf$1", "symbols": ["IndividualEventExpression$ebnf$1$subexpression$1$ebnf$1", "event_exp_attribute_pair"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
662-
{"name": "IndividualEventExpression$ebnf$1$subexpression$1$ebnf$2$subexpression$1", "symbols": [tok_setting, tok_OPEN_PAREN, "Identifier_list_body", tok_CLSE_PAREN]},
663-
{"name": "IndividualEventExpression$ebnf$1$subexpression$1$ebnf$2", "symbols": ["IndividualEventExpression$ebnf$1$subexpression$1$ebnf$2$subexpression$1"], "postprocess": id},
664-
{"name": "IndividualEventExpression$ebnf$1$subexpression$1$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
665-
{"name": "IndividualEventExpression$ebnf$1$subexpression$1", "symbols": ["IndividualEventExpression$ebnf$1$subexpression$1$ebnf$1", "IndividualEventExpression$ebnf$1$subexpression$1$ebnf$2"]},
666-
{"name": "IndividualEventExpression$ebnf$1", "symbols": ["IndividualEventExpression$ebnf$1$subexpression$1"], "postprocess": id},
660+
{"name": "IndividualEventExpression$ebnf$1", "symbols": [tok_COLON], "postprocess": id},
667661
{"name": "IndividualEventExpression$ebnf$1", "symbols": [], "postprocess": function(d) {return null;}},
668-
{"name": "IndividualEventExpression$ebnf$2$subexpression$1", "symbols": [tok_where, "event_exp_where"]},
662+
{"name": "IndividualEventExpression$ebnf$2$subexpression$1$ebnf$1", "symbols": ["event_exp_attribute_pair"]},
663+
{"name": "IndividualEventExpression$ebnf$2$subexpression$1$ebnf$1", "symbols": ["IndividualEventExpression$ebnf$2$subexpression$1$ebnf$1", "event_exp_attribute_pair"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
664+
{"name": "IndividualEventExpression$ebnf$2$subexpression$1$ebnf$2$subexpression$1", "symbols": [tok_setting, tok_OPEN_PAREN, "Identifier_list_body", tok_CLSE_PAREN]},
665+
{"name": "IndividualEventExpression$ebnf$2$subexpression$1$ebnf$2", "symbols": ["IndividualEventExpression$ebnf$2$subexpression$1$ebnf$2$subexpression$1"], "postprocess": id},
666+
{"name": "IndividualEventExpression$ebnf$2$subexpression$1$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
667+
{"name": "IndividualEventExpression$ebnf$2$subexpression$1", "symbols": ["IndividualEventExpression$ebnf$2$subexpression$1$ebnf$1", "IndividualEventExpression$ebnf$2$subexpression$1$ebnf$2"]},
669668
{"name": "IndividualEventExpression$ebnf$2", "symbols": ["IndividualEventExpression$ebnf$2$subexpression$1"], "postprocess": id},
670669
{"name": "IndividualEventExpression$ebnf$2", "symbols": [], "postprocess": function(d) {return null;}},
671-
{"name": "IndividualEventExpression", "symbols": ["Identifier", "Identifier", "IndividualEventExpression$ebnf$1", "IndividualEventExpression$ebnf$2"], "postprocess":
670+
{"name": "IndividualEventExpression$ebnf$3$subexpression$1", "symbols": [tok_where, "event_exp_where"]},
671+
{"name": "IndividualEventExpression$ebnf$3", "symbols": ["IndividualEventExpression$ebnf$3$subexpression$1"], "postprocess": id},
672+
{"name": "IndividualEventExpression$ebnf$3", "symbols": [], "postprocess": function(d) {return null;}},
673+
{"name": "IndividualEventExpression", "symbols": ["Identifier", "IndividualEventExpression$ebnf$1", "Identifier", "IndividualEventExpression$ebnf$2", "IndividualEventExpression$ebnf$3"], "postprocess":
672674
function(data){
673675
return {
674676
type: 'EventExpression',
675677
loc: mkLoc(data),
676678
event_domain: data[0],
677-
event_type: data[1],
678-
event_attrs: (data[2] && data[2][0]) || [],
679-
setting: (data[2] && data[2][1] && data[2][1][2]) || [],
680-
where: data[3] && data[3][1],
679+
event_type: data[2],
680+
event_attrs: (data[3] && data[3][0]) || [],
681+
setting: (data[3] && data[3][1] && data[3][1][2]) || [],
682+
where: data[4] && data[4][1],
681683
aggregator: null//this is set by EventAggregator
682684
};
683685
}
684686
},
685-
{"name": "IndividualEventExpression$ebnf$3", "symbols": []},
686-
{"name": "IndividualEventExpression$ebnf$3", "symbols": ["IndividualEventExpression$ebnf$3", "event_exp_attribute_pair"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
687-
{"name": "IndividualEventExpression", "symbols": ["Identifier", "Identifier", "IndividualEventExpression$ebnf$3", tok_where, "event_exp_where", tok_setting, tok_OPEN_PAREN, "Identifier_list", tok_CLSE_PAREN], "postprocess":
687+
{"name": "IndividualEventExpression$ebnf$4", "symbols": [tok_COLON], "postprocess": id},
688+
{"name": "IndividualEventExpression$ebnf$4", "symbols": [], "postprocess": function(d) {return null;}},
689+
{"name": "IndividualEventExpression$ebnf$5", "symbols": []},
690+
{"name": "IndividualEventExpression$ebnf$5", "symbols": ["IndividualEventExpression$ebnf$5", "event_exp_attribute_pair"], "postprocess": function arrpush(d) {return d[0].concat([d[1]]);}},
691+
{"name": "IndividualEventExpression", "symbols": ["Identifier", "IndividualEventExpression$ebnf$4", "Identifier", "IndividualEventExpression$ebnf$5", tok_where, "event_exp_where", tok_setting, tok_OPEN_PAREN, "Identifier_list", tok_CLSE_PAREN], "postprocess":
688692
function(data){
689693
return {
690694
deprecated: "Move the `where` clause to be after the `setting`",
691695

692696
type: 'EventExpression',
693697
loc: mkLoc(data),
694698
event_domain: data[0],
695-
event_type: data[1],
696-
event_attrs: data[2],
697-
where: data[4],
698-
setting: data[7],
699+
event_type: data[2],
700+
event_attrs: data[3],
701+
where: data[5],
702+
setting: data[8],
699703
aggregator: null//this is set by EventAggregator
700704
};
701705
}
702706
},
703-
{"name": "IndividualEventExpression", "symbols": ["Identifier", "Identifier", tok_setting, tok_OPEN_PAREN, "Identifier_list", tok_CLSE_PAREN], "postprocess":
707+
{"name": "IndividualEventExpression$ebnf$6", "symbols": [tok_COLON], "postprocess": id},
708+
{"name": "IndividualEventExpression$ebnf$6", "symbols": [], "postprocess": function(d) {return null;}},
709+
{"name": "IndividualEventExpression", "symbols": ["Identifier", "IndividualEventExpression$ebnf$6", "Identifier", tok_setting, tok_OPEN_PAREN, "Identifier_list", tok_CLSE_PAREN], "postprocess":
704710
function(data){
705711
return {
706712
deprecated: "What are you `setting`? There are no attribute matches",
707713

708714
type: 'EventExpression',
709715
loc: mkLoc(data),
710716
event_domain: data[0],
711-
event_type: data[1],
717+
event_type: data[2],
712718
event_attrs: [],
713719
where: null,
714-
setting: data[4],
720+
setting: data[5],
715721
aggregator: null//this is set by EventAggregator
716722
};
717723
}

packages/krl-parser/src/grammar.ne

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -672,52 +672,52 @@ event_exp_base -> %tok_OPEN_PAREN EventExpression %tok_CLSE_PAREN {% getN(1) %}
672672
| IndividualEventExpression {% id %}
673673

674674
IndividualEventExpression ->
675-
Identifier Identifier
675+
Identifier %tok_COLON:? Identifier
676676
(event_exp_attribute_pair:+ (%tok_setting %tok_OPEN_PAREN Identifier_list_body %tok_CLSE_PAREN):?):?
677677
(%tok_where event_exp_where):? {%
678678
function(data){
679679
return {
680680
type: 'EventExpression',
681681
loc: mkLoc(data),
682682
event_domain: data[0],
683-
event_type: data[1],
684-
event_attrs: (data[2] && data[2][0]) || [],
685-
setting: (data[2] && data[2][1] && data[2][1][2]) || [],
686-
where: data[3] && data[3][1],
683+
event_type: data[2],
684+
event_attrs: (data[3] && data[3][0]) || [],
685+
setting: (data[3] && data[3][1] && data[3][1][2]) || [],
686+
where: data[4] && data[4][1],
687687
aggregator: null//this is set by EventAggregator
688688
};
689689
}
690690
%}
691691
## DEPRECATED
692-
| Identifier Identifier event_exp_attribute_pair:* %tok_where event_exp_where %tok_setting %tok_OPEN_PAREN Identifier_list %tok_CLSE_PAREN {%
692+
| Identifier %tok_COLON:? Identifier event_exp_attribute_pair:* %tok_where event_exp_where %tok_setting %tok_OPEN_PAREN Identifier_list %tok_CLSE_PAREN {%
693693
function(data){
694694
return {
695695
deprecated: "Move the `where` clause to be after the `setting`",
696696

697697
type: 'EventExpression',
698698
loc: mkLoc(data),
699699
event_domain: data[0],
700-
event_type: data[1],
701-
event_attrs: data[2],
702-
where: data[4],
703-
setting: data[7],
700+
event_type: data[2],
701+
event_attrs: data[3],
702+
where: data[5],
703+
setting: data[8],
704704
aggregator: null//this is set by EventAggregator
705705
};
706706
}
707707
%}
708708
## DEPRECATED
709-
| Identifier Identifier %tok_setting %tok_OPEN_PAREN Identifier_list %tok_CLSE_PAREN {%
709+
| Identifier %tok_COLON:? Identifier %tok_setting %tok_OPEN_PAREN Identifier_list %tok_CLSE_PAREN {%
710710
function(data){
711711
return {
712712
deprecated: "What are you `setting`? There are no attribute matches",
713713

714714
type: 'EventExpression',
715715
loc: mkLoc(data),
716716
event_domain: data[0],
717-
event_type: data[1],
717+
event_type: data[2],
718718
event_attrs: [],
719719
where: null,
720-
setting: data[4],
720+
setting: data[5],
721721
aggregator: null//this is set by EventAggregator
722722
};
723723
}

packages/krl-parser/tests/parser.test.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,12 @@ test('select when', function (t) {
294294
mk.eventOp('or', [mk.ee('d', 'b'), mk.ee('d', 'c')])
295295
]))
296296

297+
src = 'select when d:a and (d b or d:c)'
298+
asertRuleAST(src, mk.eventOp('and', [
299+
mk.ee('d', 'a'),
300+
mk.eventOp('or', [mk.ee('d', 'b'), mk.ee('d', 'c')])
301+
]))
302+
297303
t.end()
298304
})
299305

0 commit comments

Comments
 (0)