Skip to content

Commit

Permalink
Merge pull request #1653 from dvoytenko/access25
Browse files Browse the repository at this point in the history
Access expressions: fix name grammar
  • Loading branch information
dvoytenko committed Jan 28, 2016
2 parents 30261d4 + ca24238 commit f1b7856
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion extensions/amp-access/0.1/access-expr-impl.jison
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"==" return 'DEQ'
"=" return 'EQ'
[0-9]+("."[0-9]+)?\b return 'NUMERIC'
[a-zA-Z0-9]+ return 'NAME'
[a-zA-Z_][a-zA-Z0-9_]* return 'NAME'
\'[^\']*\' return 'STRING'
\"[^\"]*\" return 'STRING'
. return 'INVALID'
Expand Down
2 changes: 1 addition & 1 deletion extensions/amp-access/0.1/access-expr-impl.js
Original file line number Diff line number Diff line change
Expand Up @@ -689,7 +689,7 @@ case 24:return 5
break;
}
},
rules: [/^(?:\s+)/,/^(?:AND\b)/,/^(?:OR\b)/,/^(?:NOT\b)/,/^(?:NULL\b)/,/^(?:TRUE\b)/,/^(?:true\b)/,/^(?:FALSE\b)/,/^(?:false\b)/,/^(?:\()/,/^(?:\))/,/^(?:\|)/,/^(?:<=)/,/^(?:<)/,/^(?:>=)/,/^(?:>)/,/^(?:!=)/,/^(?:==)/,/^(?:=)/,/^(?:[0-9]+(\.[0-9]+)?\b)/,/^(?:[a-zA-Z0-9]+)/,/^(?:'[^\']*')/,/^(?:"[^\"]*")/,/^(?:.)/,/^(?:$)/],
rules: [/^(?:\s+)/,/^(?:AND\b)/,/^(?:OR\b)/,/^(?:NOT\b)/,/^(?:NULL\b)/,/^(?:TRUE\b)/,/^(?:true\b)/,/^(?:FALSE\b)/,/^(?:false\b)/,/^(?:\()/,/^(?:\))/,/^(?:\|)/,/^(?:<=)/,/^(?:<)/,/^(?:>=)/,/^(?:>)/,/^(?:!=)/,/^(?:==)/,/^(?:=)/,/^(?:[0-9]+(\.[0-9]+)?\b)/,/^(?:[a-zA-Z_][a-zA-Z0-9_]*)/,/^(?:'[^\']*')/,/^(?:"[^\"]*")/,/^(?:.)/,/^(?:$)/],
conditions: {"INITIAL":{"rules":[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24],"inclusive":true}}
});
return lexer;
Expand Down
17 changes: 17 additions & 0 deletions extensions/amp-access/0.1/test/test-access-expr.js
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,21 @@ describe('evaluateAccessExpr', () => {
expect(evaluateAccessExpr('a AND b', {a: 1, b: 2})).to.be.true;
expect(evaluateAccessExpr('a AND c', {a: 1, b: 2})).to.be.false;
});

it('should accept name grammar', () => {
expect(evaluateAccessExpr('num = 10', {num: 10})).to.be.true;
expect(evaluateAccessExpr('num1 = 10', {num1: 10})).to.be.true;
expect(evaluateAccessExpr('num_ = 10', {num_: 10})).to.be.true;
expect(evaluateAccessExpr('_num = 10', {_num: 10})).to.be.true;

expect(() => {
evaluateAccessExpr('1num = 10', {"1num": 10});
}).to.throw();
expect(() => {
evaluateAccessExpr('num-a = 10', {"num-a": 10});
}).to.throw();
expect(() => {
evaluateAccessExpr('num.a = 10', {"num.a": 10});
}).to.throw();
});
});

0 comments on commit f1b7856

Please sign in to comment.