You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've been playing with something akin to the collapse_transformer() example, but I'd like to be able to include # in one-line input strings.
What I want to do is essentially the following, where I would parse the template string in the transformer, but unfortunately it doesn't make it past the parser.
glue::glue("{#b a}")
# no output due to #b
Here are a few examples using an identity transformer that just returns the text that reaches the transformer.
identity<-function(x, ...) xglue::glue("{a}", .transformer=identity)
#> a
"{a*}" works and the transformer receives "a*", but "{a#}" does not work: the transformer isn’t called …
a<-"apple"glue::glue("{a#}")
glue::glue("{a#\n}")
#> apple
I can see where problems could arise with incomplete expressions due to comments, but it also makes sense that such problems would throw parsing errors.
glue::glue("{c(a,#\na)}")
#> apple#> appleglue::glue("{c(a,#a)}")
glue::glue("{c(a,#a)\n}")
#> Error in parse(text = text, keep.source = FALSE): <text>:3:0: unexpected end of input#> 1: c(a,#a)#> 2: #> ^
That said, one place where changing the parser might break current behavior is that currently empty expressions cause the entire result to be zero-length. Except for the last, the following all return character(0).
I've been playing with something akin to the collapse_transformer() example, but I'd like to be able to include
#
in one-line input strings.What I want to do is essentially the following, where I would parse the template string in the transformer, but unfortunately it doesn't make it past the parser.
Here are a few examples using an identity transformer that just returns the text that reaches the transformer.
"{a*}"
works and the transformer receives"a*"
, but"{a#}"
does not work: the transformer isn’t called ……unless the
#
is followed by a new line.Another example without the identity transformer.
I can see where problems could arise with incomplete expressions due to comments, but it also makes sense that such problems would throw parsing errors.
That said, one place where changing the parser might break current behavior is that currently empty expressions cause the entire result to be zero-length. Except for the last, the following all return
character(0)
.Created on 2020-06-04 by the reprex package (v0.3.0)
The text was updated successfully, but these errors were encountered: