Skip to content

Commit

Permalink
fix: support non-English characters (fixes #34)
Browse files Browse the repository at this point in the history
  • Loading branch information
gajus committed Jan 3, 2025
1 parent fe42d04 commit 00deae8
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/grammar.ne
Original file line number Diff line number Diff line change
Expand Up @@ -292,4 +292,4 @@ regex_flags ->
[gmiyusd]:+ {% d => d[0].join('') %}

unquoted_value ->
[a-zA-Z_*?@#$] [a-zA-Z0-9\.\-_*?@#$]:* {% d => d[0] + d[1].join('') %}
[a-zA-Z_*?@#$\u0080-\uFFFF] [a-zA-Z0-9\.\-_*?@#$\u0080-\uFFFF]:* {% d => d[0] + d[1].join('') %}
4 changes: 2 additions & 2 deletions src/grammar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -771,12 +771,12 @@ const grammar: Grammar = {
{
name: 'unquoted_value$ebnf$1',
postprocess: (d) => d[0].concat([d[1]]),
symbols: ['unquoted_value$ebnf$1', /[\w#$*.?@\-]/],
symbols: ['unquoted_value$ebnf$1', /[\w#$*.?@\u0080-\uFFFF\-]/],
},
{
name: 'unquoted_value',
postprocess: (d) => d[0] + d[1].join(''),
symbols: [/[#$*?@A-Z_a-z]/, 'unquoted_value$ebnf$1'],
symbols: [/[#$*?@A-Z_a-z\u0080-\uFFFF]/, 'unquoted_value$ebnf$1'],
},
],
ParserStart: 'main',
Expand Down
55 changes: 55 additions & 0 deletions test/liqe/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,26 @@ test('foo123', testQuery, {
type: 'Tag',
});

test('测试', testQuery, {
expression: {
location: {
end: 2,
start: 0,
},
quoted: false,
type: 'LiteralExpression',
value: '测试',
},
field: {
type: 'ImplicitField',
},
location: {
end: 2,
start: 0,
},
type: 'Tag',
});

test('foo with whitespace at the start', (t) => {
t.deepEqual(parse(' foo'), {
expression: {
Expand Down Expand Up @@ -547,6 +567,41 @@ test('foo:bar123', testQuery, {
type: 'Tag',
});

test('foo:测试', testQuery, {
expression: {
location: {
end: 6,
start: 4,
},
quoted: false,
type: 'LiteralExpression',
value: '测试',
},
field: {
location: {
end: 3,
start: 0,
},
name: 'foo',
path: ['foo'],
quoted: false,
type: 'Field',
},
location: {
end: 6,
start: 0,
},
operator: {
location: {
end: 4,
start: 3,
},
operator: ':',
type: 'ComparisonOperator',
},
type: 'Tag',
});

// https://github.com/gajus/liqe/issues/18
// https://github.com/gajus/liqe/issues/19
test.skip('foo: bar', testQuery, {
Expand Down

0 comments on commit 00deae8

Please sign in to comment.