Skip to content

Commit 7de6915

Browse files
RahafTahaynehRahaf
andauthored
fix: allow hyphens in field names and add tests or hyphenated field name (#41)
Co-authored-by: Rahaf <rahaf.tahayneh@taha>
1 parent 10dd864 commit 7de6915

File tree

3 files changed

+37
-2
lines changed

3 files changed

+37
-2
lines changed

src/grammar.ne

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ tag_expression ->
193193
} %}
194194

195195
field ->
196-
[_a-zA-Z$] [a-zA-Z\d_$.]:* {% (data, start) => ({type: 'LiteralExpression', name: data[0] + data[1].join(''), quoted: false, location: {start, end: start + (data[0] + data[1].join('')).length}}) %}
196+
[_a-zA-Z$] [a-zA-Z\d_$.-]:* {% (data, start) => ({type: 'LiteralExpression', name: data[0] + data[1].join(''), quoted: false, location: {start, end: start + (data[0] + data[1].join('')).length}}) %}
197197
| sqstring {% (data, start) => ({type: 'LiteralExpression', name: data[0], quoted: true, quotes: 'single', location: {start, end: start + data[0].length + 2}}) %}
198198
| dqstring {% (data, start) => ({type: 'LiteralExpression', name: data[0], quoted: true, quotes: 'double', location: {start, end: start + data[0].length + 2}}) %}
199199

src/grammar.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ const grammar: Grammar = {
490490
{
491491
name: 'field$ebnf$1',
492492
postprocess: (d) => d[0].concat([d[1]]),
493-
symbols: ['field$ebnf$1', /[\w$.]/],
493+
symbols: ['field$ebnf$1', /[\w$.-]/],
494494
},
495495
{
496496
name: 'field',

test/liqe/parse.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,3 +2669,38 @@ test('( foo OR bar AND baz )', testQuery, {
26692669
location: { end: 22, start: 0 },
26702670
type: 'ParenthesizedExpression',
26712671
});
2672+
2673+
test("attrs.user-id:12345", testQuery, {
2674+
expression: {
2675+
location: {
2676+
end: 19,
2677+
start: 14,
2678+
},
2679+
quoted: false,
2680+
type: "LiteralExpression",
2681+
value: 12345,
2682+
},
2683+
field: {
2684+
location: {
2685+
end: 13,
2686+
start: 0,
2687+
},
2688+
name: "attrs.user-id",
2689+
path: ["attrs", "user-id"],
2690+
quoted: false,
2691+
type: "Field",
2692+
},
2693+
location: {
2694+
end: 19,
2695+
start: 0,
2696+
},
2697+
operator: {
2698+
location: {
2699+
end: 14,
2700+
start: 13,
2701+
},
2702+
operator: ":",
2703+
type: "ComparisonOperator",
2704+
},
2705+
type: "Tag",
2706+
});

0 commit comments

Comments
 (0)