Skip to content

Commit

Permalink
skip converting to numeric value in liqe
Browse files Browse the repository at this point in the history
  • Loading branch information
sywhb committed Dec 12, 2023
1 parent 07868c7 commit 5bac173
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 119 deletions.
82 changes: 41 additions & 41 deletions packages/liqe/src/grammar.ne
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ __ -> whitespace_character:+ {% (data) => data[0].length %}

whitespace_character -> [ \t\n\v\f] {% id %}

# Numbers
decimal -> "-":? [0-9]:+ ("." [0-9]:+):? {%
(data) => parseFloat(
(data[0] || "") +
data[1].join("") +
(data[2] ? "."+data[2][1].join("") : "")
)
%}
# # Numbers
# decimal -> "-":? [0-9]:+ ("." [0-9]:+):? {%
# (data) => parseFloat(
# (data[0] || "") +
# data[1].join("") +
# (data[2] ? "."+data[2][1].join("") : "")
# )
# %}

# Double-quoted string
dqstring -> "\"" dstrchar:* "\"" {% (data) => data[1].join('') %}
Expand Down Expand Up @@ -198,9 +198,9 @@ field ->
| dqstring {% (data, start) => ({type: 'LiteralExpression', name: data[0], quoted: true, quotes: 'double', location: {start, end: start + data[0].length + 2}}) %}

expression ->
decimal {% (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length}, type: 'LiteralExpression', quoted: false, value: Number(data.join(''))}}) %}
| regex {% (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length}, type: 'RegexExpression', value: data.join('')}}) %}
| range {% (data) => data[0] %}
# decimal {% (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length}, type: 'LiteralExpression', quoted: false, value: Number(data.join(''))}}) %}
regex {% (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length}, type: 'RegexExpression', value: data.join('')}}) %}
# | range {% (data) => data[0] %}
| unquoted_value {% (data, start, reject) => {
const value = data.join('');

Expand Down Expand Up @@ -236,36 +236,36 @@ expression ->
| sqstring {% (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length + 2}, type: 'LiteralExpression', quoted: true, quotes: 'single', value: data.join('')}}) %}
| dqstring {% (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length + 2}, type: 'LiteralExpression', quoted: true, quotes: 'double', value: data.join('')}}) %}

range ->
range_open decimal " TO " decimal range_close {% (data, start) => {
return {
location: {
start,
},
type: 'Tag',
expression: {
location: {
start: data[0].location.start,
end: data[4].location.start + 1,
},
type: 'RangeExpression',
range: {
min: data[1],
minInclusive: data[0].inclusive,
maxInclusive: data[4].inclusive,
max: data[3],
}
}
}
} %}

range_open ->
"[" {% (data, start) => ({location: {start}, inclusive: true}) %}
| "{" {% (data, start) => ({location: {start}, inclusive: false}) %}

range_close ->
"]" {% (data, start) => ({location: {start}, inclusive: true}) %}
| "}" {% (data, start) => ({location: {start}, inclusive: false}) %}
# range ->
# range_open decimal " TO " decimal range_close {% (data, start) => {
# return {
# location: {
# start,
# },
# type: 'Tag',
# expression: {
# location: {
# start: data[0].location.start,
# end: data[4].location.start + 1,
# },
# type: 'RangeExpression',
# range: {
# min: data[1],
# minInclusive: data[0].inclusive,
# maxInclusive: data[4].inclusive,
# max: data[3],
# }
# }
# }
# } %}
#
# range_open ->
# "[" {% (data, start) => ({location: {start}, inclusive: true}) %}
# | "{" {% (data, start) => ({location: {start}, inclusive: false}) %}
#
# range_close ->
# "]" {% (data, start) => ({location: {start}, inclusive: true}) %}
# | "}" {% (data, start) => ({location: {start}, inclusive: false}) %}

comparison_operator ->
(
Expand Down
44 changes: 0 additions & 44 deletions packages/liqe/src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,6 @@ const grammar: Grammar = {
{"name": "__$ebnf$1", "symbols": ["__$ebnf$1", "whitespace_character"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "__", "symbols": ["__$ebnf$1"], "postprocess": (data) => data[0].length},
{"name": "whitespace_character", "symbols": [/[ \t\n\v\f]/], "postprocess": id},
{"name": "decimal$ebnf$1", "symbols": [{"literal":"-"}], "postprocess": id},
{"name": "decimal$ebnf$1", "symbols": [], "postprocess": () => null},
{"name": "decimal$ebnf$2", "symbols": [/[0-9]/]},
{"name": "decimal$ebnf$2", "symbols": ["decimal$ebnf$2", /[0-9]/], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": [/[0-9]/]},
{"name": "decimal$ebnf$3$subexpression$1$ebnf$1", "symbols": ["decimal$ebnf$3$subexpression$1$ebnf$1", /[0-9]/], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "decimal$ebnf$3$subexpression$1", "symbols": [{"literal":"."}, "decimal$ebnf$3$subexpression$1$ebnf$1"]},
{"name": "decimal$ebnf$3", "symbols": ["decimal$ebnf$3$subexpression$1"], "postprocess": id},
{"name": "decimal$ebnf$3", "symbols": [], "postprocess": () => null},
{"name": "decimal", "symbols": ["decimal$ebnf$1", "decimal$ebnf$2", "decimal$ebnf$3"], "postprocess":
(data) => parseFloat(
(data[0] || "") +
data[1].join("") +
(data[2] ? "."+data[2][1].join("") : "")
)
},
{"name": "dqstring$ebnf$1", "symbols": []},
{"name": "dqstring$ebnf$1", "symbols": ["dqstring$ebnf$1", "dstrchar"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "dqstring", "symbols": [{"literal":"\""}, "dqstring$ebnf$1", {"literal":"\""}], "postprocess": (data) => data[1].join('')},
Expand Down Expand Up @@ -213,9 +197,7 @@ const grammar: Grammar = {
{"name": "field", "symbols": [/[_a-zA-Z$]/, "field$ebnf$1"], "postprocess": (data, start) => ({type: 'LiteralExpression', name: data[0] + data[1].join(''), quoted: false, location: {start, end: start + (data[0] + data[1].join('')).length}})},
{"name": "field", "symbols": ["sqstring"], "postprocess": (data, start) => ({type: 'LiteralExpression', name: data[0], quoted: true, quotes: 'single', location: {start, end: start + data[0].length + 2}})},
{"name": "field", "symbols": ["dqstring"], "postprocess": (data, start) => ({type: 'LiteralExpression', name: data[0], quoted: true, quotes: 'double', location: {start, end: start + data[0].length + 2}})},
{"name": "expression", "symbols": ["decimal"], "postprocess": (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length}, type: 'LiteralExpression', quoted: false, value: Number(data.join(''))}})},
{"name": "expression", "symbols": ["regex"], "postprocess": (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length}, type: 'RegexExpression', value: data.join('')}})},
{"name": "expression", "symbols": ["range"], "postprocess": (data) => data[0]},
{"name": "expression", "symbols": ["unquoted_value"], "postprocess": (data, start, reject) => {
const value = data.join('');

Expand Down Expand Up @@ -250,32 +232,6 @@ const grammar: Grammar = {
} },
{"name": "expression", "symbols": ["sqstring"], "postprocess": (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length + 2}, type: 'LiteralExpression', quoted: true, quotes: 'single', value: data.join('')}})},
{"name": "expression", "symbols": ["dqstring"], "postprocess": (data, start) => ({type: 'Tag', expression: {location: {start, end: start + data.join('').length + 2}, type: 'LiteralExpression', quoted: true, quotes: 'double', value: data.join('')}})},
{"name": "range$string$1", "symbols": [{"literal":" "}, {"literal":"T"}, {"literal":"O"}, {"literal":" "}], "postprocess": (d) => d.join('')},
{"name": "range", "symbols": ["range_open", "decimal", "range$string$1", "decimal", "range_close"], "postprocess": (data, start) => {
return {
location: {
start,
},
type: 'Tag',
expression: {
location: {
start: data[0].location.start,
end: data[4].location.start + 1,
},
type: 'RangeExpression',
range: {
min: data[1],
minInclusive: data[0].inclusive,
maxInclusive: data[4].inclusive,
max: data[3],
}
}
}
} },
{"name": "range_open", "symbols": [{"literal":"["}], "postprocess": (data, start) => ({location: {start}, inclusive: true})},
{"name": "range_open", "symbols": [{"literal":"{"}], "postprocess": (data, start) => ({location: {start}, inclusive: false})},
{"name": "range_close", "symbols": [{"literal":"]"}], "postprocess": (data, start) => ({location: {start}, inclusive: true})},
{"name": "range_close", "symbols": [{"literal":"}"}], "postprocess": (data, start) => ({location: {start}, inclusive: false})},
{"name": "comparison_operator$subexpression$1", "symbols": [{"literal":":"}]},
{"name": "comparison_operator$subexpression$1$string$1", "symbols": [{"literal":":"}, {"literal":"="}], "postprocess": (d) => d.join('')},
{"name": "comparison_operator$subexpression$1", "symbols": ["comparison_operator$subexpression$1$string$1"]},
Expand Down
26 changes: 13 additions & 13 deletions packages/liqe/test/liqe/filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,12 @@ test('name:/(david)|(john)/', testQuery, ['david', 'john']);
test('name:/(David)|(John)/', testQuery, []);
test('name:/(David)|(John)/i', testQuery, ['david', 'john']);

test('height:[200 TO 300]', testQuery, ['robert', 'noah']);
test('height:[220 TO 300]', testQuery, ['robert', 'noah']);
test('height:{220 TO 300]', testQuery, ['noah']);
test('height:[200 TO 225]', testQuery, ['robert', 'noah']);
test('height:[200 TO 225}', testQuery, ['robert']);
test('height:{220 TO 225}', testQuery, []);
test.skip('height:[200 TO 300]', testQuery, ['robert', 'noah']);
test.skip('height:[220 TO 300]', testQuery, ['robert', 'noah']);
test.skip('height:{220 TO 300]', testQuery, ['noah']);
test.skip('height:[200 TO 225]', testQuery, ['robert', 'noah']);
test.skip('height:[200 TO 225}', testQuery, ['robert']);
test.skip('height:{220 TO 225}', testQuery, []);

test('NOT David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']);
test('-David', testQuery, ['john', 'mike', 'robert', 'noah', 'foo bar', 'fox']);
Expand All @@ -115,12 +115,12 @@ test('name:David OR name:John', testQuery, ['david', 'john']);
test('name:"david" OR name:"john"', testQuery, ['david', 'john']);
test('name:"David" OR name:"John"', testQuery, []);

test('height:=175', testQuery, ['john', 'mike']);
test('height:>200', testQuery, ['robert', 'noah']);
test('height:>220', testQuery, ['noah']);
test('height:>=220', testQuery, ['robert', 'noah']);
test.skip('height:=175', testQuery, ['john', 'mike']);
test.skip('height:>200', testQuery, ['robert', 'noah']);
test.skip('height:>220', testQuery, ['noah']);
test.skip('height:>=220', testQuery, ['robert', 'noah']);

test('height:=175 AND NOT name:mike', testQuery, ['john']);
test.skip('height:=175 AND NOT name:mike', testQuery, ['john']);

test('"member"', testQuery, ['robert']);

Expand All @@ -138,9 +138,9 @@ test('subscribed:true', testQuery, ['noah']);
test('email:/[^.:@\\s](?:[^:@\\s]*[^.:@\\s])?@[^.@\\s]+(?:\\.[^.@\\s]+)*/', testQuery, ['noah']);

test('phoneNumber:"404-050-2611"', testQuery, ['noah']);
test('phoneNumber:404', testQuery, ['noah']);
test.skip('phoneNumber:404', testQuery, ['noah']);

test('balance:364', testQuery, ['noah']);
test.skip('balance:364', testQuery, ['noah']);

test('(David)', testQuery, ['david']);
test('(name:david OR name:john)', testQuery, ['david', 'john']);
Expand Down
6 changes: 3 additions & 3 deletions packages/liqe/test/liqe/highlight.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ test(
],
);

test(
test.skip(
'matches or',
testQuery,
'name:foo OR name:bar OR height:=180',
Expand Down Expand Up @@ -181,7 +181,7 @@ test.skip(
],
);

test(
test.skip(
'matches number',
testQuery,
'height:=180',
Expand All @@ -195,7 +195,7 @@ test(
],
);

test(
test.skip(
'matches range',
testQuery,
'height:[100 TO 200]',
Expand Down
18 changes: 9 additions & 9 deletions packages/liqe/test/liqe/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ test.skip('foo: bar', testQuery, {
type: 'Tag',
});

test('foo:123', testQuery, {
test.skip('foo:123', testQuery, {
expression: {
location: {
end: 7,
Expand Down Expand Up @@ -564,7 +564,7 @@ test('foo:123', testQuery, {
type: 'Tag',
});

test('foo:=123', testQuery, {
test.skip('foo:=123', testQuery, {
expression: {
location: {
end: 8,
Expand Down Expand Up @@ -636,7 +636,7 @@ test.skip('foo:= 123', testQuery, {
type: 'Tag',
});

test('foo:=-123', testQuery, {
test.skip('foo:=-123', testQuery, {
expression: {
location: {
end: 9,
Expand Down Expand Up @@ -671,7 +671,7 @@ test('foo:=-123', testQuery, {
type: 'Tag',
});

test('foo:=123.4', testQuery, {
test.skip('foo:=123.4', testQuery, {
expression: {
location: {
end: 10,
Expand Down Expand Up @@ -706,7 +706,7 @@ test('foo:=123.4', testQuery, {
type: 'Tag',
});

test('foo:>=123', testQuery, {
test.skip('foo:>=123', testQuery, {
expression: {
location: {
end: 9,
Expand Down Expand Up @@ -2415,7 +2415,7 @@ test('(foo:bar OR baz:qux) OR quuz:corge', testQuery, {
type: 'LogicalExpression',
});

test('[1 TO 2]', testQuery, {
test.skip('[1 TO 2]', testQuery, {
expression: {
location: {
end: 8,
Expand All @@ -2438,7 +2438,7 @@ test('[1 TO 2]', testQuery, {
type: 'Tag',
});

test('{1 TO 2]', testQuery, {
test.skip('{1 TO 2]', testQuery, {
expression: {
location: {
end: 8,
Expand All @@ -2461,7 +2461,7 @@ test('{1 TO 2]', testQuery, {
type: 'Tag',
});

test('[1 TO 2}', testQuery, {
test.skip('[1 TO 2}', testQuery, {
expression: {
location: {
end: 8,
Expand All @@ -2484,7 +2484,7 @@ test('[1 TO 2}', testQuery, {
type: 'Tag',
});

test('{1 TO 2}', testQuery, {
test.skip('{1 TO 2}', testQuery, {
expression: {
location: {
end: 8,
Expand Down
18 changes: 9 additions & 9 deletions packages/liqe/test/liqe/serialize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,19 @@ test('foo:bar', testQuery);
// https://github.com/gajus/liqe/issues/19
test.skip('foo: bar', testQuery);

test('foo:123', testQuery);
test.skip('foo:123', testQuery);

test('foo:=123', testQuery);
test.skip('foo:=123', testQuery);

// https://github.com/gajus/liqe/issues/18
// https://github.com/gajus/liqe/issues/19
test.skip('foo:= 123', testQuery);

test('foo:=-123', testQuery);
test.skip('foo:=-123', testQuery);

test('foo:=123.4', testQuery);
test.skip('foo:=123.4', testQuery);

test('foo:>=123', testQuery);
test.skip('foo:>=123', testQuery);

test('foo:true', testQuery);

Expand Down Expand Up @@ -124,10 +124,10 @@ test('(foo:bar OR (baz:qux OR quuz:corge))', testQuery);

test('((foo:bar OR baz:qux) OR quuz:corge)', testQuery);

test('[1 TO 2]', testQuery);
test.skip('[1 TO 2]', testQuery);

test('{1 TO 2]', testQuery);
test.skip('{1 TO 2]', testQuery);

test('[1 TO 2}', testQuery);
test.skip('[1 TO 2}', testQuery);

test('{1 TO 2}', testQuery);
test.skip('{1 TO 2}', testQuery);

0 comments on commit 5bac173

Please sign in to comment.