This repository has no description
0

Configure Feed

Select the types of activity you want to include in your feed.

added conditional assignments! in on-arrival and on-departure, you can use statements of the form

+65
+24
lib/parsers/logic.js
··· 16 16 {regex:/not|NOT/, token:'negation'}, 17 17 {regex:/true|TRUE/, token:'boolean'}, 18 18 {regex:/false|FALSE/, token:'boolean'}, 19 + {regex:/if/, token:'if'}, 20 + {regex:/then/, token:'then'}, 21 + {regex:/else/, token:'else'}, 19 22 {regex:/\=/, token:'equals'}, 20 23 {regex:/<=|>=|<|>|!=|==/, token:'comparator'}, 21 24 {regex:/\+=|-=|\*=|\/=/, token:'modification-operator'}, ··· 123 126 function(sequence) { 124 127 return _sequence(sequence[0], [' = '], sequence[2], [';']); 125 128 }), 129 + _rule('.command ::= .command if .bool-exp', 130 + function(sequence) { 131 + return _sequence([' if ('], sequence[2], [' ) { '], 132 + sequence[0], [' } ']); 133 + }), 134 + _rule('.command ::= .command if .bool-exp else .command', 135 + function(sequence) { 136 + return _sequence([' if ('], sequence[2], [' ) { \n'], 137 + sequence[0], [';\n } else { '], sequence[5], [' } ']); 138 + }), 139 + _rule('.command ::= if .bool-exp then .command', 140 + function(sequence) { 141 + return _sequence([' if ('], sequence[1], [' ) { '], 142 + sequence[3], [' } ']); 143 + }), 144 + _rule('.command ::= if .bool-exp then .command else .command', 145 + function(sequence) { 146 + return _sequence([' if ('], sequence[1], [' ) { '], 147 + sequence[3], [';\n } else { '], sequence[5], [' } ']); 148 + }), 149 + 126 150 127 151 // PREDICATE 128 152 _rule('.predicate ::= .bool-exp', _return),
+41
test/test_parsers_logic.js
··· 439 439 done(); 440 440 }); 441 441 }); 442 + 443 + it('should allow conditionals', function(done) { 444 + logic.compileActions('foo = 2 if (bar >= 1);', function(err, fn) { 445 + noerr(err); 446 + var state = { 447 + qualities: {bar: 1} 448 + }; 449 + engine.runActions([fn], {}, state); 450 + state.qualities.bar.should.equal(1); 451 + state.qualities.foo.should.equal(2); 452 + done(); 453 + }); 454 + }); 455 + 456 + it('should allow conditionals of the form if-then', function(done) { 457 + logic.compileActions('if (bar >= 1) then foo = 2;', function(err, fn) { 458 + noerr(err); 459 + var state = { 460 + qualities: {bar: 1} 461 + }; 462 + engine.runActions([fn], {}, state); 463 + state.qualities.bar.should.equal(1); 464 + state.qualities.foo.should.equal(2); 465 + done(); 466 + }); 467 + }); 468 + 469 + it('should allow conditionals of the form if-then-else', function(done) { 470 + logic.compileActions('if (bar >= 1) then foo=2 else foo=6; if (foo==6) then x = 1 else x=2;', function(err, fn) { 471 + noerr(err); 472 + var state = { 473 + qualities: {bar: 1} 474 + }; 475 + engine.runActions([fn], {}, state); 476 + state.qualities.bar.should.equal(1); 477 + state.qualities.foo.should.equal(2); 478 + state.qualities.x.should.equal(2); 479 + done(); 480 + }); 481 + }); 482 + 442 483 }); 443 484 444 485 // ----------------------------------------------------------------------