V: raw strings do not work with trailing backslash

Created on 24 Jul 2020  路  6Comments  路  Source: vlang/v

V version: V 0.1.29 0ba5544
OS: Manjaro

What did you do?

s := r'\'
println(s)

What did you expect to see?
Output of \

What did you see instead?

testy.v:3:1: error: unfinished string literal
    1 | s := r'\'
    2 | println(s)
Bug Confirmed

All 6 comments

Did you try it with `\\` ?

It works but it does not fix the error with raw strings.

Actually, it does "fix it". If doubling the backslash works, it means that "raw" strings still pay attention to escaped characters, and your original is just eating the trailing backslash. Doubling the backslash just gives a single backslash in the output, which is what you wanted.

So this becomes a matter of clarifying whether "raw" strings are supposed to be truly "raw" (as in no manipulation, no escaping AT ALL), or whether minimal manipulation (such as handling escaped characters) is expected.

@medvednikov which should it be?

I think this should given an error as it expected EOL while scanning. What you guys think?

I think we need to clarify how raw strings are supposed to work, first.

Ok, clarification from the docs:


For raw strings, prepend r. Raw strings are not escaped:

s := r'hello\nworld'

println(s) // "hello\nworld"

So this issue is a bug report - it should be printing a backslash instead of failing as it does now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

radare picture radare  路  3Comments

XVilka picture XVilka  路  3Comments

choleraehyq picture choleraehyq  路  3Comments

shouji-kazuo picture shouji-kazuo  路  3Comments

cjmxp picture cjmxp  路  3Comments