From dd9510f9dbf66ea56f5af884965b26363df6e47e Mon Sep 17 00:00:00 2001 From: Alexander Behrens Date: Wed, 7 Aug 2019 09:55:58 +0200 Subject: [PATCH] support more variable names --- package.json | 2 +- src/filtrex.js | 10 +++++++--- test/objects.js | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 5d1f21f..e16b73d 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/filtrex.js b/src/filtrex.js index 1d6c36c..4fc5999 100644 --- a/src/filtrex.js +++ b/src/filtrex.js @@ -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( @@ -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 diff --git a/test/objects.js b/test/objects.js index fc16be8..9de181a 100644 --- a/test/objects.js +++ b/test/objects.js @@ -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('\'\' == 1337')({ '': 1337})).equals(1); + }); }); \ No newline at end of file