Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

builtin: add support for CUE path-related functions #3126

Open
myitcv opened this issue May 8, 2024 · 1 comment
Open

builtin: add support for CUE path-related functions #3126

myitcv opened this issue May 8, 2024 · 1 comment
Labels
FeatureRequest New feature or request

Comments

@myitcv
Copy link
Member

myitcv commented May 8, 2024

Is your feature request related to a problem? Please describe.

Consider:

import "strings"

data: {
	a: b: c: 5
	d: ee: 4
}

vals: [x=string]: {
	let refs = strings.Split(x, ".")
	y: *[for i, v in refs {(*y[i-1] | data)[v]}] | "error"
	z: *y[2] | "error"
}
vals: "a.b.c": _
vals: "d.e":   _

Manual parsing of string-encoded paths is required, which is error prone. e.g. this does not handle spaces, definitions etc.

Describe the solution you'd like

Some CUE path-related builtins, e.g. a builtin equivalent of cue.ParsePath(). Indexing could be done via a builtin, or supported via [] if a cue.Path value is the index value.

Describe alternatives you've considered

Manual parsing and handling of paths via regular string indexing, as above. Which doesn't work in all cases because you cannot index a definition in this way at least.

Additional context

n/a

@myitcv myitcv added the FeatureRequest New feature or request label May 8, 2024
@rogpeppe
Copy link
Member

rogpeppe commented May 8, 2024

Some consideration for such a piece of functionality:

  • currently AFAIK there is no way from CUE itself to programmatically construct a reference to a definition - that is, if there are no mentions of a particular definition name in the code, and in the absence of external references, we can know for sure that a definition with that name is unused. Allowing programmatic construction of a definition name alters this invariant - something to bear in mind at least.
  • some decision needed about internal (underscore-prefixed) names. Probably disallow them, as they have no universal meaning. Alternatively, could provide some way to mention the package in which such names are to be interpreted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FeatureRequest New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants