From 18ac9168996026073ee16164fce108054b2a0ed7 Mon Sep 17 00:00:00 2001 From: Tony Garnock-Jones Date: Thu, 2 Sep 2021 12:05:55 +0200 Subject: [PATCH] preserves-path examples --- preserves-path.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/preserves-path.md b/preserves-path.md index bc3b50d..c3277a7 100644 --- a/preserves-path.md +++ b/preserves-path.md @@ -114,3 +114,32 @@ documents in the sequence. (A flattened set doesn't make sense for streaming since the input documents come in a sequence; if the inputs were treated as a set represented as a sequence, and outputs were buffered in a single large set, that could work out...) + +## Examples + +Consider the following Preserves Path selectors, intended to run +against the [Preserves codec test suite document](tests/samples.pr): + + - `.annotations ^ Documentation . 0 /` + + This selects each of the elements (mostly text strings) in the list + of the `Documentation` record annotating the test suite document + itself. + + First, `.annotations` focuses on the annotations of the document. + Then, `^ Documentation` selects only annotations that are records + with label `Documentation`. Then, `. 0` selects the first field in + each record. Finally, `/` replaces each selected value with a + sequence of its children. + + - `// [.^ [= Test + = NondeterministicTest]] [. 1 rec]` + + This selects every deterministic or nondeterministic test case + where the expected value is a record. + + First, `//` recursively selects *every* descendant subvalue of the + root (inclusive). Then, two filters are applied, one after the + other. The first, `[.^ [= Test + = NondeterministicTest]]`, selects + record labels, and then filters out all but `Test` and + `NondeterministicTest`. Then, the second, `[. 1 rec]`, filters out + all but those where the second field is a record.