Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Access expressions: fix name grammar #1653

Merged
merged 1 commit into from
Jan 28, 2016
Merged
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
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_]*)/,/^(?:'[^\']*')/,/^(?:"[^\"]*")/,/^(?:.)/,/^(?:$)/],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

my EYES 🙈

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();
});
});