Skip to content

Commit

Permalink
support more variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
albehrens committed Aug 7, 2019
1 parent 9b83b49 commit dd9510f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"license": "MIT",
"scripts": {
"test": "./node_modules/mocha/bin/mocha test",
"test": "./node_modules/mocha/bin/mocha test",
"debug": "./node_modules/mocha/bin/mocha test --inspect-brk"
},
"dependencies": {
Expand Down
10 changes: 7 additions & 3 deletions src/filtrex.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,11 @@ function filtrexParser() {
['of[^\\w]', 'return "of";'],

['\\s+', ''], // skip whitespace
['[0-9]+(?:\\.[0-9]+)?\\b', 'return "NUMBER";'], // 212.321

['[a-zA-Z][\\.a-zA-Z0-9_]*',
['[0-9]+[\\.a-zA-Z_]{2,}',
`yytext = JSON.stringify(yytext);
return "SYMBOL";`
], // some.Symbol22
['[0-9]+(?:\\.[0-9]+)?\\b', 'return "NUMBER";'], // 212.321

[`'(?:[^\'])*'`,
`yytext = JSON.stringify(
Expand All @@ -140,6 +139,11 @@ function filtrexParser() {
return "SYMBOL";`
], // 'some-symbol'

['[a-zA-Z$_][\\.a-zA-Z0-9_]*',
`yytext = JSON.stringify(yytext);
return "SYMBOL";`
], // some.Symbol22

['"(?:\\\\"|[^"])*"', 'return "STRING";'], // "foo"

// End
Expand Down
8 changes: 8 additions & 0 deletions test/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,12 @@ describe('Object support', () => {
expect(compileExpression('toString of something')({ something: {}})).equals(undefined);
});

it('should support more variable names', () => {
expect(compileExpression('$.id == "id1"')({ '$.id': "id1"})).equals(1);
expect(compileExpression('__id == "id1"')({ '__id': "id1"})).equals(1);
expect(compileExpression('0.id == 1337')({ '0.id': 1337})).equals(1);
expect(compileExpression('\'0.\' == 1337')({ '0.': 1337})).equals(1);
expect(compileExpression('\'0.000id\' == 1337')({ '0.000id': 1337})).equals(1);
expect(compileExpression('\'<id>\' == 1337')({ '<id>': 1337})).equals(1);
});
});

0 comments on commit dd9510f

Please sign in to comment.