From d6d17fe3f2cc38cf43e9aabb38928aef971dc646 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20B=C3=B6ttcher?= <34623283+spacesinmotion@users.noreply.github.com> Date: Fri, 16 Aug 2019 16:06:27 +0200 Subject: [PATCH] scanner: string interpolation with $var at the end --- compiler/main.v | 2 +- compiler/scanner.v | 2 +- compiler/tests/string_interpolation_test.v | 12 ++++++++++++ 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/compiler/main.v b/compiler/main.v index 5344de578f..b66b2d52ec 100644 --- a/compiler/main.v +++ b/compiler/main.v @@ -875,7 +875,7 @@ mut args := '' //'$fast_clang $args' //} //else { - mut cmd := 'cc $args' + mut cmd := ('cc $args') // TODO fix $if after 'string' //} $if windows { cmd = 'gcc $args' diff --git a/compiler/scanner.v b/compiler/scanner.v index 9b93be354f..c259a92a80 100644 --- a/compiler/scanner.v +++ b/compiler/scanner.v @@ -264,7 +264,7 @@ fn (s mut Scanner) scan() ScanRes { // at the next ', skip it if s.inside_string { if next_char == `\'` { - s.pos++ + s.dollar_end = true s.dollar_start = false s.inside_string = false } diff --git a/compiler/tests/string_interpolation_test.v b/compiler/tests/string_interpolation_test.v index cda819000f..d939d244dd 100644 --- a/compiler/tests/string_interpolation_test.v +++ b/compiler/tests/string_interpolation_test.v @@ -15,3 +15,15 @@ fn test_excape_dollar_in_string() { assert !'(\\\\${i})'.contains('i') && '(\\\\${i})'.contains('42') && '(\\\\${i})'.contains('\\\\') assert i==42 } + +fn test_implicit_str() { + i := 42 + assert 'int $i' == 'int 42' + assert '$i' == '42' + + check := '$i' == '42' + assert check + + text := '$i' + '42' + assert text == '4242' +}