From 42a67831bfd99d3e85ccdbc402a537dce4e0992c Mon Sep 17 00:00:00 2001 From: yuyi Date: Tue, 29 Mar 2022 23:06:11 +0800 Subject: [PATCH] parser: fix printing slice of multiline raw string (#13856) --- vlib/v/parser/expr.v | 4 +++- .../v/tests/inout/printing_slice_of_multiline_raw_string.out | 3 +++ vlib/v/tests/inout/printing_slice_of_multiline_raw_string.vv | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 vlib/v/tests/inout/printing_slice_of_multiline_raw_string.out create mode 100644 vlib/v/tests/inout/printing_slice_of_multiline_raw_string.vv diff --git a/vlib/v/parser/expr.v b/vlib/v/parser/expr.v index 6b5d793c99..6738491ee4 100644 --- a/vlib/v/parser/expr.v +++ b/vlib/v/parser/expr.v @@ -372,7 +372,9 @@ pub fn (mut p Parser) expr_with_left(left ast.Expr, precedence int, is_stmt_iden return node } p.is_stmt_ident = is_stmt_ident - } else if p.tok.kind in [.lsbr, .nilsbr] && p.tok.line_nr == p.prev_tok.line_nr { + } else if p.tok.kind in [.lsbr, .nilsbr] && (p.tok.line_nr == p.prev_tok.line_nr + || (p.prev_tok.kind == .string + && p.tok.line_nr == p.prev_tok.line_nr + p.prev_tok.lit.count('\n'))) { if p.tok.kind == .nilsbr { node = p.index_expr(node, true) } else { diff --git a/vlib/v/tests/inout/printing_slice_of_multiline_raw_string.out b/vlib/v/tests/inout/printing_slice_of_multiline_raw_string.out new file mode 100644 index 0000000000..8aa8665b45 --- /dev/null +++ b/vlib/v/tests/inout/printing_slice_of_multiline_raw_string.out @@ -0,0 +1,3 @@ +foo +bar +hi diff --git a/vlib/v/tests/inout/printing_slice_of_multiline_raw_string.vv b/vlib/v/tests/inout/printing_slice_of_multiline_raw_string.vv new file mode 100644 index 0000000000..4736adfe9f --- /dev/null +++ b/vlib/v/tests/inout/printing_slice_of_multiline_raw_string.vv @@ -0,0 +1,5 @@ +fn main() { + println(r'foo +bar +hi'[..]) +}