diff --git a/src/grammar.ne b/src/grammar.ne index e5f749a..eb866b0 100644 --- a/src/grammar.ne +++ b/src/grammar.ne @@ -58,6 +58,7 @@ const field = d => { path: d[0].name.split('.').filter(Boolean), quoted: d[0].quoted, quotes: d[0].quotes, + location: d[0].location, }, ...d[3] } @@ -98,9 +99,9 @@ side -> | query {% d => ({field: {name: ''}, ...d[0]}) %} field -> - [_a-zA-Z$] [a-zA-Z\d_$.]:* {% d => ({name: d[0] + d[1].join(''), quoted: false}) %} - | sqstring {% d => ({name: d[0], quoted: true, quotes: 'single'}) %} - | dqstring {% d => ({name: d[0], quoted: true, quotes: 'double'}) %} + [_a-zA-Z$] [a-zA-Z\d_$.]:* {% (data, location) => ({name: data[0] + data[1].join(''), quoted: false, location}) %} + | sqstring {% (data, location) => ({name: data[0], quoted: true, quotes: 'single', location}) %} + | dqstring {% (data, location) => ({name: data[0], quoted: true, quotes: 'double', location}) %} query -> relational_operator _ decimal {% d => ({quoted: false, query: d[2], relationalOperator: d[0][0]}) %} diff --git a/src/grammar.ts b/src/grammar.ts index eacdbe9..54df8d3 100644 --- a/src/grammar.ts +++ b/src/grammar.ts @@ -56,6 +56,7 @@ const field = d => { path: d[0].name.split('.').filter(Boolean), quoted: d[0].quoted, quotes: d[0].quotes, + location: d[0].location, }, ...d[3] } @@ -231,9 +232,9 @@ const grammar: Grammar = { {"name": "side", "symbols": ["query"], "postprocess": d => ({field: {name: ''}, ...d[0]})}, {"name": "field$ebnf$1", "symbols": []}, {"name": "field$ebnf$1", "symbols": ["field$ebnf$1", /[a-zA-Z\d_$.]/], "postprocess": (d) => d[0].concat([d[1]])}, - {"name": "field", "symbols": [/[_a-zA-Z$]/, "field$ebnf$1"], "postprocess": d => ({name: d[0] + d[1].join(''), quoted: false})}, - {"name": "field", "symbols": ["sqstring"], "postprocess": d => ({name: d[0], quoted: true, quotes: 'single'})}, - {"name": "field", "symbols": ["dqstring"], "postprocess": d => ({name: d[0], quoted: true, quotes: 'double'})}, + {"name": "field", "symbols": [/[_a-zA-Z$]/, "field$ebnf$1"], "postprocess": (data, location) => ({name: data[0] + data[1].join(''), quoted: false, location})}, + {"name": "field", "symbols": ["sqstring"], "postprocess": (data, location) => ({name: data[0], quoted: true, quotes: 'single', location})}, + {"name": "field", "symbols": ["dqstring"], "postprocess": (data, location) => ({name: data[0], quoted: true, quotes: 'double', location})}, {"name": "query", "symbols": ["relational_operator", "_", "decimal"], "postprocess": d => ({quoted: false, query: d[2], relationalOperator: d[0][0]})}, {"name": "query", "symbols": ["decimal"], "postprocess": d => ({quoted: false, query: d.join('')})}, {"name": "query", "symbols": ["regex"], "postprocess": d => ({quoted: false, regex: true, query: d.join('')})}, diff --git a/test/liqe/parse.ts b/test/liqe/parse.ts index c9a3d38..f5f915c 100644 --- a/test/liqe/parse.ts +++ b/test/liqe/parse.ts @@ -195,6 +195,7 @@ test('foo:null', testQuery, { test('foo.bar:baz', testQuery, { field: { + location: 0, name: 'foo.bar', path: [ 'foo', @@ -206,6 +207,7 @@ test('foo.bar:baz', testQuery, { test('foo_bar:baz', testQuery, { field: { + location: 0, name: 'foo_bar', }, query: 'baz', @@ -213,6 +215,7 @@ test('foo_bar:baz', testQuery, { test('$foo:baz', testQuery, { field: { + location: 0, name: '$foo', }, query: 'baz', @@ -220,6 +223,7 @@ test('$foo:baz', testQuery, { test('"foo bar":baz', testQuery, { field: { + location: 0, name: 'foo bar', quoted: true, quotes: 'double', @@ -229,6 +233,7 @@ test('"foo bar":baz', testQuery, { test('\'foo bar\':baz', testQuery, { field: { + location: 0, name: 'foo bar', quoted: true, quotes: 'single',