cue: support iteration over pattern constraints
This makes it possible to inspect pattern constraints over struct
values. We add a new option, `Patterns`, which causes the iterator
returned by `Value.Fields` to produce pattern constraints as well as
other fields.
We introduce a new selector type, `patternSelector` which represents
the pattern, and add `Selector.Pattern` to return the actual pattern
value. We don't need to add a new selector type because the type used
by `AnyString` (`StringLabel | PatternConstraint`) already seems
appropriate, and `AnyString` is never produced by field iteration.
We don't add functionality for looking up by a pattern constraint
selector because it's not entirely clear what the semantics should be
(what does it mean for one noncrete value to equal another?)
Note: it would be nicer if `AnyString.Pattern` could return `_` but
that's unfortunately not possible because there's no way for it to
obtain a context. All the alternatives (for example adding a selector
type that only _indicates_ that it's a pattern constraint rather than
containing the pattern value) seem worse. A future API where `Value`
is not bound so tightly to a given `Context` would address this
concern (and many others besides).
Fixes #3684
Signed-off-by: Roger Peppe <rogpeppe@gmail.com>
Change-Id: I826f8ba1aef6ceedbf0d058b25c6184682da88c3
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1224468
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Marcel van Lohuizen <mpvl@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>