Skip to content

Commit

Permalink
fix: handle whitespace at the end of the query
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Oct 2, 2022
1 parent 32620de commit a14e8c3
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/grammar.ne
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
@preprocessor typescript

main -> _ logical_expression {% (data) => data[1] %}
main -> _ logical_expression _ {% (data) => data[1] %}

# Whitespace: `_` is optional, `__` is mandatory.
_ -> whitespace_character:* {% (data) => data[0].length %}
Expand Down
2 changes: 1 addition & 1 deletion src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ interface Grammar {
const grammar: Grammar = {
Lexer: undefined,
ParserRules: [
{"name": "main", "symbols": ["_", "logical_expression"], "postprocess": (data) => data[1]},
{"name": "main", "symbols": ["_", "logical_expression", "_"], "postprocess": (data) => data[1]},
{"name": "_$ebnf$1", "symbols": []},
{"name": "_$ebnf$1", "symbols": ["_$ebnf$1", "whitespace_character"], "postprocess": (d) => d[0].concat([d[1]])},
{"name": "_", "symbols": ["_$ebnf$1"], "postprocess": (data) => data[0].length},
Expand Down
2 changes: 1 addition & 1 deletion test/liqe/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ test('foo with whitespace at the start', (t) => {
});

test('foo with whitespace at the end', (t) => {
t.deepEqual(parse('foo'), {
t.deepEqual(parse('foo '), {
expression: {
location: {
end: 3,
Expand Down

0 comments on commit a14e8c3

Please sign in to comment.