all: allow newlines around interpolations in single-line strings
The parser now accepts newlines between the \( and ) of a string
interpolation inside single-line string literals, just as it already
does inside multi-line string literals. This makes constructs like
x: "\(
expr)"
parse successfully.
The formatter then normalizes the surrounding whitespace according to
the kind of string literal:
* In single-line string literals, any newlines inside an interpolation
expression are collapsed, so the result stays on one line.
This aligns user code with how Swift interpolations work as well.
* In multi-line string literals, the newlines around each
interpolation expression are balanced so that they are either both
present or both absent; if only one of them is present, the
formatter inserts the other.
Fixes #309.
Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ifa40499f2e51f3ed99065d8aa2f28711487bec9c
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1228254
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>