Skip to content

Commit 4a6ad69

Browse files
committed
fix: pipe operator has wrong precedence
1 parent 0233a2d commit 4a6ad69

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -214,14 +214,14 @@ The operators have the following precedence, from highest to lowest:
214214

215215
| Precedence | Associativity | Operators |
216216
|-----------------------------|---------------|--------------------------------------|
217-
| 8: pipe | left-to-right | `\|` |
218-
| 7: exponentiation | n/a | `^` |
219-
| 6: multiplicative operators | left-to-right | `*`, `/`, `%` |
220-
| 5: additive operators | left-to-right | `+`, `-` |
221-
| 4: relational operators | n/a | `>`, `>=`, `<`, `<=`, `in`, `not in` |
222-
| 3: equality operators | n/a | `==`, `!=` |
223-
| 2: and | left-to-right | `and` |
224-
| 1: or | left-to-right | `or` |
217+
| 8: exponentiation | n/a | `^` |
218+
| 7: multiplicative operators | left-to-right | `*`, `/`, `%` |
219+
| 6: additive operators | left-to-right | `+`, `-` |
220+
| 5: relational operators | n/a | `>`, `>=`, `<`, `<=`, `in`, `not in` |
221+
| 4: equality operators | n/a | `==`, `!=` |
222+
| 3: and | left-to-right | `and` |
223+
| 2: or | left-to-right | `or` |
224+
| 1: pipe | left-to-right | `\|` |
225225

226226
See section [Function reference](reference/functions.md) for a detailed overview of all available functions and operators.
227227

src/operators.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@ import type { CustomOperator, OperatorGroup } from './types'
33

44
// operator precedence from highest to lowest
55
export const operators: OperatorGroup[] = [
6-
{ pipe: '|' },
76
{ pow: '^' },
87
{ multiply: '*', divide: '/', mod: '%' },
98
{ add: '+', subtract: '-' },
109
{ gt: '>', gte: '>=', lt: '<', lte: '<=', in: 'in', 'not in': 'not in' },
1110
{ eq: '==', ne: '!=' },
1211
{ and: 'and' },
13-
{ or: 'or' }
12+
{ or: 'or' },
13+
{ pipe: '|' }
1414
]
1515

1616
export const varargOperators = ['|', 'and', 'or']

test-suite/parse.test.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@
217217
{ "input": "2 and 3 or 4", "output": ["or", ["and", 2, 3], 4] },
218218
{ "input": "2 or 3 and 4", "output": ["or", 2, ["and", 3, 4]] },
219219
{ "input": "2 > 3 and 4", "output": ["and", ["gt", 2, 3], 4] },
220-
{ "input": "2 and 3 > 4", "output": ["and", 2, ["gt", 3, 4]] }
220+
{ "input": "2 and 3 > 4", "output": ["and", 2, ["gt", 3, 4]] },
221+
{ "input": "2 or 3 | 4", "output": ["pipe", ["or", 2, 3], 4] },
222+
{ "input": "2 | 3 or 4", "output": ["pipe", 2, ["or", 3, 4]] }
221223
]
222224
},
223225
{

0 commit comments

Comments
 (0)