Skip to content

Commit dd1bebe

Browse files
change token to % and add docs
Signed-off-by: andrew-coleman <andrew_coleman@uk.ibm.com>
1 parent baec496 commit dd1bebe

File tree

11 files changed

+67
-37
lines changed

11 files changed

+67
-37
lines changed

docs/path-operators.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,36 @@ The key/value pairs between the curly braces determine the groupings (by evaluat
7878
See [Grouping and Aggregation](sorting-grouping#grouping) for more details.
7979

8080

81+
## `*` (Wildcard)
82+
83+
This wildcard selects the values of all the properties of the context object. It can be used in a path expression in place of a property name, but it cannot be combined with other characters like a glob pattern. The order of these values in the result sequence is implementation dependent.
84+
See [Wildcards](predicate#wildcards) for examples.
85+
86+
## `**` (Descendants)
87+
88+
This wildcard recursively selects the values of all the properties of the context object, and the properties of any objects contained within these values as it descends the hierarchy.
89+
See [Navigate arbitrary depths](predicate#navigate-arbitrary-depths).
90+
91+
## `%` (Parent)
92+
93+
This will select the 'parent' of the current context value. Here, we define 'parent' to be the enclosing object which has the property representing the context value.
94+
95+
This is the only operation which searches 'backwards' in the input data structure. It is implemented by static analysis of the expression at [compile time](https://docs.jsonata.org/embedding-extending#jsonatastr) and can only be used within expressions that navigate through that target parent value in the first place.
96+
If, for any reason, the parent location cannot be determined, then a static error (S0217) is thrown.
97+
98+
__Example__
99+
100+
```
101+
Account.Order.Product.{
102+
'Product': `Product Name`,
103+
'Order': %.OrderID,
104+
'Account': %.%.`Account Name`
105+
}
106+
```
107+
This returns an array of objects for each product in each order in each account. Information from the enclosing Order and Account objects can be accessed using the parent operator.
108+
The repeated combination of `%.%.` is used to access the grandparent and higher ancestors.
109+
110+
81111
## `#` (Positional variable binding)
82112

83113
This can be used to determine at which position in the sequence the current context item is. It can be used following any map, filter or order-by stage in the path.

src/parser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ const parser = (() => {
574574
});
575575

576576
// parent operator
577-
prefix('!', function () {
577+
prefix('%', function () {
578578
this.type = "parent";
579579
return this;
580580
});

test/test-suite/groups/parent-operator/errors.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[
22
{
3-
"expr": "{'hello': 'world'}.! ",
3+
"expr": "{'hello': 'world'}.% ",
44
"data": null,
55
"bindings": {},
66
"code": "S0217"
77
},
88
{
9-
"expr": "!",
9+
"expr": "%",
1010
"dataset": "library",
1111
"bindings": {},
1212
"code": "S0217"
1313
},
1414
{
15-
"expr": "library.loans.!.!.!",
15+
"expr": "library.loans.%.%.%",
1616
"dataset": "library",
1717
"bindings": {},
1818
"code": "S0217"

test/test-suite/groups/parent-operator/parent.json

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
]
5555
},
5656
{
57-
"expr": "Account.Order.Product.[`Product Name`, !.OrderID]",
57+
"expr": "Account.Order.Product.[`Product Name`, %.OrderID]",
5858
"dataset": "dataset5",
5959
"bindings": {},
6060
"result": [
@@ -69,7 +69,7 @@
6969
]
7070
},
7171
{
72-
"expr": "Account.Order.Product.{ `Product Name`: [Quantity, !.OrderID] }",
72+
"expr": "Account.Order.Product.{ `Product Name`: [Quantity, %.OrderID] }",
7373
"dataset": "dataset5",
7474
"bindings": {},
7575
"result": [
@@ -88,7 +88,7 @@
8888
]
8989
},
9090
{
91-
"expr": "Account.Order.Product.{ `Product Name`: [Quantity, (!.OrderID)] }",
91+
"expr": "Account.Order.Product.{ `Product Name`: [Quantity, (%.OrderID)] }",
9292
"dataset": "dataset5",
9393
"bindings": {},
9494
"result": [
@@ -107,7 +107,7 @@
107107
]
108108
},
109109
{
110-
"expr": "Account.Order.Product[!.OrderID='order104'].SKU",
110+
"expr": "Account.Order.Product[%.OrderID='order104'].SKU",
111111
"dataset": "dataset5",
112112
"bindings": {},
113113
"result": [
@@ -116,7 +116,7 @@
116116
]
117117
},
118118
{
119-
"expr": "Account.Order.Product[!.!.`Account Name`='Firefly'].SKU",
119+
"expr": "Account.Order.Product[%.%.`Account Name`='Firefly'].SKU",
120120
"dataset": "dataset5",
121121
"bindings": {},
122122
"result": [
@@ -127,7 +127,7 @@
127127
]
128128
},
129129
{
130-
"expr": "Account.Order.Product.Price[!.!.OrderID='order103']",
130+
"expr": "Account.Order.Product.Price[%.%.OrderID='order103']",
131131
"dataset": "dataset5",
132132
"bindings": {},
133133
"result": [
@@ -136,7 +136,7 @@
136136
]
137137
},
138138
{
139-
"expr": "Account.Order.Product.Price.![!.OrderID='order103'].SKU",
139+
"expr": "Account.Order.Product.Price.%[%.OrderID='order103'].SKU",
140140
"dataset": "dataset5",
141141
"bindings": {},
142142
"result": [
@@ -145,7 +145,7 @@
145145
]
146146
},
147147
{
148-
"expr": "Account.Order.Product[!.OrderID='order104'][!.!.`Account Name`='Firefly'].SKU",
148+
"expr": "Account.Order.Product[%.OrderID='order104'][%.%.`Account Name`='Firefly'].SKU",
149149
"dataset": "dataset5",
150150
"bindings": {},
151151
"result": [
@@ -154,7 +154,7 @@
154154
]
155155
},
156156
{
157-
"expr": "(Account.Order.Product)[!.OrderID='order104'].SKU",
157+
"expr": "(Account.Order.Product)[%.OrderID='order104'].SKU",
158158
"dataset": "dataset5",
159159
"bindings": {},
160160
"result": [
@@ -163,7 +163,7 @@
163163
]
164164
},
165165
{
166-
"expr": "Account.Order.Product.{ !.OrderID: Price * Quantity }",
166+
"expr": "Account.Order.Product.{ %.OrderID: Price * Quantity }",
167167
"dataset": "dataset5",
168168
"bindings": {},
169169
"result": [
@@ -182,7 +182,7 @@
182182
]
183183
},
184184
{
185-
"expr": "Account.Order.().!",
185+
"expr": "Account.Order.().%",
186186
"dataset": "dataset5",
187187
"bindings": {},
188188
"undefinedResult": true
@@ -323,7 +323,7 @@
323323
]
324324
},
325325
{
326-
"expr": "Account.Order.Product.SKU^(!.Price)",
326+
"expr": "Account.Order.Product.SKU^(%.Price)",
327327
"dataset": "dataset5",
328328
"bindings": {},
329329
"result": [
@@ -334,7 +334,7 @@
334334
]
335335
},
336336
{
337-
"expr": "Account.Order.Product.SKU^(!.Price, >!.!.OrderID)",
337+
"expr": "Account.Order.Product.SKU^(%.Price, >%.%.OrderID)",
338338
"dataset": "dataset5",
339339
"bindings": {},
340340
"result": [
@@ -345,7 +345,7 @@
345345
]
346346
},
347347
{
348-
"expr": "Account.Order.Product.Description.{ 'Colour': Colour, 'Total': !.Price * !.Quantity }",
348+
"expr": "Account.Order.Product.Description.{ 'Colour': Colour, 'Total': %.Price * %.Quantity }",
349349
"dataset": "dataset5",
350350
"bindings": {},
351351
"result": [
@@ -368,7 +368,7 @@
368368
]
369369
},
370370
{
371-
"expr": "Account.Order.Product.Description.{ 'Item': Colour & ' ' & !.`Product Name`, 'Discounted': (!.!.OrderID = 'order103') ? !.Price / 2 : !.Price }",
371+
"expr": "Account.Order.Product.Description.{ 'Item': Colour & ' ' & %.`Product Name`, 'Discounted': (%.%.OrderID = 'order103') ? %.Price / 2 : %.Price }",
372372
"dataset": "dataset5",
373373
"bindings": {},
374374
"result": [
@@ -391,7 +391,7 @@
391391
]
392392
},
393393
{
394-
"expr": "Account.Order.Product.( $parent := !; !.OrderID )",
394+
"expr": "Account.Order.Product.( $parent := %; %.OrderID )",
395395
"dataset": "dataset5",
396396
"bindings": {},
397397
"result": [
@@ -402,7 +402,7 @@
402402
]
403403
},
404404
{
405-
"expr": "Account.Order.Product.( $parent := !; $parent.OrderID )",
405+
"expr": "Account.Order.Product.( $parent := %; $parent.OrderID )",
406406
"dataset": "dataset5",
407407
"bindings": {},
408408
"result": [
@@ -413,7 +413,7 @@
413413
]
414414
},
415415
{
416-
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].{ 'book': $B.title, 'parent': $keys(!) }",
416+
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].{ 'book': $B.title, 'parent': $keys(%) }",
417417
"dataset": "library",
418418
"bindings": {},
419419
"result": [
@@ -444,7 +444,7 @@
444444
]
445445
},
446446
{
447-
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].customers[id=$L.customer].{ 'book': $B.title, 'customer': name, 'parent': $keys(!) }",
447+
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].customers[id=$L.customer].{ 'book': $B.title, 'customer': name, 'parent': $keys(%) }",
448448
"dataset": "library",
449449
"bindings": {},
450450
"result": [
@@ -478,7 +478,7 @@
478478
]
479479
},
480480
{
481-
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].customers[id=$L.customer].{ 'book': $B.title, 'customer': name, 'parent': $keys(!.!) }",
481+
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].customers[id=$L.customer].{ 'book': $B.title, 'customer': name, 'parent': $keys(%.%) }",
482482
"dataset": "library",
483483
"bindings": {},
484484
"result": [
@@ -512,7 +512,7 @@
512512
]
513513
},
514514
{
515-
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].customers@$C[$C.id=$L.customer].{ 'book': $B.title, 'customer': $C.name, 'grandparent': $keys(!.!) }",
515+
"expr": "library.loans@$L.books@$B[$L.isbn=$B.isbn].customers@$C[$C.id=$L.customer].{ 'book': $B.title, 'customer': $C.name, 'grandparent': $keys(%.%) }",
516516
"dataset": "library",
517517
"bindings": {},
518518
"result": [
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Account.Order.Product.{
2-
"order": !.OrderID,
2+
"order": %.OrderID,
33
"Product": `Product Name`,
44
"Weight": Description.Weight
55
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Account.(Order.Product).{
2-
"order": !.OrderID,
2+
"order": %.OrderID,
33
"Product": `Product Name`,
44
"Weight": Description.Weight
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Account.Order.Product.{
22
'Product': `Product Name`,
3-
'Order': !.OrderID,
4-
'Account': !.!.`Account Name`
3+
'Order': %.OrderID,
4+
'Account': %.%.`Account Name`
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Account.Order.(Product).{
22
'Product': `Product Name`,
3-
'Order': !.OrderID,
4-
'Account': !.!.`Account Name`
3+
'Order': %.OrderID,
4+
'Account': %.%.`Account Name`
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Account.(Order.(Product)).{
22
'Product': `Product Name`,
3-
'Order': !.OrderID,
4-
'Account': !.!.`Account Name`
3+
'Order': %.OrderID,
4+
'Account': %.%.`Account Name`
55
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Account.(Order).(Product).{
22
'Product': `Product Name`,
3-
'Order': !.OrderID,
4-
'Account': !.!.`Account Name`
3+
'Order': %.OrderID,
4+
'Account': %.%.`Account Name`
55
}

0 commit comments

Comments
 (0)