Permalink
Browse files

parsing multiplication and division

  • Loading branch information...
1 parent 47d8d2f commit 8d00ec2bc8567466e964ec54803d0836200b5a14 @chrisdew committed Nov 21, 2012
Showing with 10 additions and 3 deletions.
  1. +9 −2 lib/grammar.pegjs
  2. +1 −1 test/session-test.js
View
@@ -96,10 +96,17 @@ Bool
{ return {fn:"equal",args:[arg0,arg1]}; }
Additive
- = arg0:Primary _? "+" _? arg1:Primary
+ = arg0:Multiplicative _? "+" _? arg1:Additive
{ return {fn:"add",args:[arg0,arg1]}; }
- / arg0:Primary _? "-" _? arg1:Primary
+ / arg0:Multiplicative _? "-" _? arg1:Additive
{ return {fn:"sub",args:[arg0,arg1]}; }
+ / Multiplicative
+
+Multiplicative
+ = arg0:Primary _? "*" _? arg1:Multiplicative
+ { return {fn:"mult",args:[arg0,arg1]}; }
+ / arg0:Primary _? "/" _? arg1:Multiplicative
+ { return {fn:"div",args:[arg0,arg1]}; }
/ Primary
Primary
View
@@ -23,7 +23,7 @@ describe('Session', function() {
var sess = new session.Session(db);
it('should event an error when executing nonsense', function(done) {
sess.exec('select three sheep from a field', function(err, res) {
- assert.equal(' ^\nSyntax error: Expected "+", ",", "-", "=" or "from" but "s" found.',
+ assert.equal(' ^\nSyntax error: Expected "*", "+", ",", "-", "/", "=" or "from" but "s" found.',
err);
done();
});

0 comments on commit 8d00ec2

Please sign in to comment.