-
Notifications
You must be signed in to change notification settings - Fork 6
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
Proposal: support string interpolation in River #15
Comments
String interpolation as proposed here is mentioned in grafana/agent#2690. |
I think it might be better to have a special
This has a few advantages over
Disclaimer: my suggestion is inspired by Rust's format macro :) Btw PowerShell also uses the |
@erikbaranowski pointed out to me that we already have a format function. I'd personally be in favour of adding a string interpolation feature to it, similar to what was described in the comment above. |
I'm going to close this for now; it's not clear how necessary this is, especially given the format function exists in the stdlib. We can return to this in the future with a more fleshed out proposal if string interpolation is required. |
I'd like to see support for string interpolation added to River.
String interpolation is a quality-of-life feature which will make it easier to write expressions which return a string.
For example, this expression:
could be replaced with the following interpolated string:
Syntax
String interpolation is initiated by placing
${EXPR}
into a string. String interpolation can be escaped by escaping the dollar sign:\${EXPR}
returns the literal string${EXPR}
.This syntax matches the string interpolation syntax used by HCL.
The parser must keep track of pairs of curly braces to ensure that parsing the inner string does not end early;
${{a=5}}
should be parsed as the expression{a=5}
and not{a=5
.Evaluation
Each EXPR instead of
${EXPR}
will be evaluated, converted to a string, and injected into the resulting output.For example:
evaluates to
"3 + 5 is 8"
.Each expression in an interpolated string should be converted into a string form which best represents that value. The representation for types should match the form of that value written in River. Functions and capsules should be converted to some description of the type of the function or capsule, similar to the description which displays in the UI.
Considerations
This would be a breaking change for users who are using some form of
${EXPR}
in their configuration files already. I'm not sure if any of our existing Flow components would lead to someone using${EXPR}
inside of a string.If this is going to be an issue, we can change the syntax used to denote a string that supports interpolation, such as any of the following:
$"3 + 5 is {3 + 5}"
`3 + 5 is ${3 + 5}`
The text was updated successfully, but these errors were encountered: