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

Consider using doubling for escaping in .literal = TRUE #259

Closed
gaborcsardi opened this issue Feb 10, 2022 · 3 comments
Closed

Consider using doubling for escaping in .literal = TRUE #259

gaborcsardi opened this issue Feb 10, 2022 · 3 comments
Labels
feature a feature request or enhancement

Comments

@gaborcsardi
Copy link
Member

gaborcsardi commented Feb 10, 2022

I am wondering if .literal = TRUE should still allow double delimiters for escaping. I.e. this currently fails:

glue::glue("{'{'}", .literal = TRUE)
Error in glue_data(.x = NULL, ..., .sep = .sep, .envir = .envir, .open = .open,  :
  Expecting '}'

and AFAICT there is no easy way of writing a (non well formed) literal brace in a glue string, apart from using substitution:

glue::glue("{'{{'}", .literal = TRUE)
Error in glue_data(.x = NULL, ..., .sep = .sep, .envir = .envir, .open = .open,  :
  Expecting '}'

As you might suspect this affects cli, because cli uses doubling as escaping currently, so it cannot switch to .literal = TRUE. On the other hand .literal = TRUE would be much better for the cases when people include literal quotes in the string, e.g. r-lib/cli#370

If doubling is still accepted for escaping, then .literal = TRUE does not break cli, and I think it is also beneficial in general to be able to escape the delimiter.

@jennybc
Copy link
Member

jennybc commented Feb 10, 2022

Can you point me to some of the cli revdep failures that inspired this? I realize you've given minimal examples above, but some even more realistic ones would be helpful for tackling this. So what sort of glue expressions are we talking about?

@gaborcsardi
Copy link
Member Author

It is this from rlang:

mark_emph("{foo {}")
#> [1] "{.emph {\"{foo {}\"}}"

cli::format_message(mark_emph("{foo {}"))
#> Error in glue_data(.x = NULL, ..., .sep = .sep, .envir = .envir, .open = .open,  :
#>   Expecting '}'

But I am not concerned about the revdep failures too much. I am more concerned that with .literal = TRUE we cannot write (non well-formed) brace literals any more.

@hadley hadley added the feature a feature request or enhancement label Jan 25, 2023
@hadley
Copy link
Member

hadley commented Jan 26, 2023

Closing since it looks like you handled this in cli.

@hadley hadley closed this as completed Jan 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

3 participants