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

add support for raw string using backticks #26

Merged
merged 6 commits into from
Oct 20, 2023
Merged

Conversation

erikbaranowski
Copy link
Contributor

@erikbaranowski erikbaranowski commented Oct 3, 2023

Closes #24

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
@erikbaranowski erikbaranowski marked this pull request as ready for review October 3, 2023 21:36
Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a test case to the printer package to see what it does with the raw string?

@rfratto
Copy link
Member

rfratto commented Oct 3, 2023

Ditto with making sure that a test case in the printer package handles multiline raw strings properly.

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
@@ -0,0 +1,11 @@
block "label" {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

labels get printed out with double quotes instead of the original backticks. I think that's probably fine for labels but I wanted to call attention to it.

@erikbaranowski erikbaranowski changed the title add support for raw string using ` add support for raw string using backticks Oct 12, 2023
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Comment on lines 1 to 3
block `label` {
attr = `'\"attr`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm, I wonder if we should even support this for labels, or if labels should require the double quoted syntax to start with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the parser should reject using raw strings for block labels for now.

Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly LGTM, just one final comment about block labels. There will be a few things to clean up after this gets merged:

  1. We should probably cut a 0.2.0.
  2. Update the grammar used in grafana.com/docs to include knowledge of raw strings.
  3. Update the grammar in rfratto/vscode-river and rfratto/vim-river (I really need to move those repos still) to support raw strings.
  4. Bump the dependency in the agent and document the new string form.
  5. We should open a feature enhancement in the agent for the UI to support raw strings and render a string as a raw string whenever it's appropriate (like if it has a newline character).

Thanks for working on this! This will save a lot of people headaches.

Comment on lines 1 to 3
block `label` {
attr = `'\"attr`
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO the parser should reject using raw strings for block labels for now.

add testing pattern for parsing river with errors

Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
Signed-off-by: erikbaranowski <39704712+erikbaranowski@users.noreply.github.com>
f, err := parser.ParseFile(t.Name()+".rvr", inputBB)
if expectedError := getExpectedErrorMessage(t, expectErrorFile); expectedError != "" {
require.Error(t, err)
require.Contains(t, err.Error(), expectedError)
Copy link
Contributor Author

@erikbaranowski erikbaranowski Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doing a contains for now so we can test the interesting part of the error. This could become an Equal at the expense of the tests being a little more brittle.

require.Equal(t, trimmed, buf.String(), "%s", buf.String())
}

// getExpectedErrorMessage will retrieve an optional expected error message for the test.
func getExpectedErrorMessage(t *testing.T, errorFile string) string {
Copy link
Contributor Author

@erikbaranowski erikbaranowski Oct 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Current implementation of diag.Diagnostics prints out (and %d more diagnostics) so for this testing we are able to validate the first Diagnostic only. This is why this returns string instead of []string like the agent converter tests with an error message per line in the testdata file.

Copy link
Member

@rfratto rfratto left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@erikbaranowski erikbaranowski merged commit 61e5422 into main Oct 20, 2023
3 checks passed
@rfratto rfratto deleted the raw-string-support branch October 20, 2023 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support raw strings where characters don't have to be escaped
2 participants