Skip to content

Commit 721f410

Browse files
authored
fix: support parsing strings starting with numbers (#44)
1 parent a9d2fff commit 721f410

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

src/grammar.ne

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,4 +292,5 @@ regex_flags ->
292292
[gmiyusd]:+ {% d => d[0].join('') %}
293293

294294
unquoted_value ->
295-
[a-zA-Z_*?@#$\u0080-\uFFFF] [a-zA-Z0-9\.\-_*?@#$\u0080-\uFFFF]:* {% d => d[0] + d[1].join('') %}
295+
[a-zA-Z_*?@#$\u0080-\uFFFF] [a-zA-Z0-9\.\-_*?@#$\u0080-\uFFFF]:* {% d => d[0] + d[1].join('') %}
296+
| [0-9]:+ [a-zA-Z\-_*?@#$\u0080-\uFFFF] [a-zA-Z0-9\.\-_*?@#$\u0080-\uFFFF]:* {% d => d[0].join('') + d[1] + d[2].join('') %}

src/grammar.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,27 @@ const grammar: Grammar = {
778778
postprocess: (d) => d[0] + d[1].join(''),
779779
symbols: [/[#$*?@A-Z_a-z\u0080-\uFFFF]/, 'unquoted_value$ebnf$1'],
780780
},
781+
{ name: 'unquoted_value$ebnf$2', symbols: [/\d/] },
782+
{
783+
name: 'unquoted_value$ebnf$2',
784+
postprocess: (d) => d[0].concat([d[1]]),
785+
symbols: ['unquoted_value$ebnf$2', /\d/],
786+
},
787+
{ name: 'unquoted_value$ebnf$3', symbols: [] },
788+
{
789+
name: 'unquoted_value$ebnf$3',
790+
postprocess: (d) => d[0].concat([d[1]]),
791+
symbols: ['unquoted_value$ebnf$3', /[\w#$*.?@\u0080-\uFFFF\-]/],
792+
},
793+
{
794+
name: 'unquoted_value',
795+
postprocess: (d) => d[0].join('') + d[1] + d[2].join(''),
796+
symbols: [
797+
'unquoted_value$ebnf$2',
798+
/[#$*?@A-Z_a-z\u0080-\uFFFF\-]/,
799+
'unquoted_value$ebnf$3',
800+
],
801+
},
781802
],
782803
ParserStart: 'main',
783804
};

test/liqe/parse.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,26 @@ test('foo123', testQuery, {
144144
type: 'Tag',
145145
});
146146

147+
test('1st', testQuery, {
148+
expression: {
149+
location: {
150+
end: 3,
151+
start: 0,
152+
},
153+
quoted: false,
154+
type: 'LiteralExpression',
155+
value: '1st',
156+
},
157+
field: {
158+
type: 'ImplicitField',
159+
},
160+
location: {
161+
end: 3,
162+
start: 0,
163+
},
164+
type: 'Tag',
165+
});
166+
147167
test('测试', testQuery, {
148168
expression: {
149169
location: {
@@ -567,6 +587,41 @@ test('foo:bar123', testQuery, {
567587
type: 'Tag',
568588
});
569589

590+
test('position:1st', testQuery, {
591+
expression: {
592+
location: {
593+
end: 12,
594+
start: 9,
595+
},
596+
quoted: false,
597+
type: 'LiteralExpression',
598+
value: '1st',
599+
},
600+
field: {
601+
location: {
602+
end: 8,
603+
start: 0,
604+
},
605+
name: 'position',
606+
path: ['position'],
607+
quoted: false,
608+
type: 'Field',
609+
},
610+
location: {
611+
end: 12,
612+
start: 0,
613+
},
614+
operator: {
615+
location: {
616+
end: 9,
617+
start: 8,
618+
},
619+
operator: ':',
620+
type: 'ComparisonOperator',
621+
},
622+
type: 'Tag',
623+
});
624+
570625
test('foo:测试', testQuery, {
571626
expression: {
572627
location: {

0 commit comments

Comments
 (0)