lang: Improve string interpolation

The original string interpolation was based on hil which didn't allow
proper escaping, since they used a different escape pattern. Secondly,
the golang Unquote function didn't deal with the variable substitution,
which meant it had to be performed in a second step.

Most importantly, because we did this partial job in Unquote (the fact
that is strips the leading and trailing quotes tricked me into thinking
I was done with interpolation!) it was impossible to remedy the
remaining parts in a second pass with hil. Both operations needs to be
done in a single step. This is logical when you aren't tunnel visioned.

This patch replaces both of these so that string interpolation works
properly. This removes the ability to allow inline function calls in a
string, however this was an incidental feature, and it's not clear that
having it is a good idea. It also requires you wrap the var name with
curly braces. (They are not optional.)

This comes with a load of tests, but I think I got some of it wrong,
since I'm quite new at ragel. If you find something, please say so =D In
any case, this is much better than the original hil implementation, and
easy for a new contributor to patch to make the necessary fixes.
This commit is contained in:
James Shubin
2020-01-31 11:47:06 -05:00
parent 5257496214
commit 400b58c0e9
36 changed files with 779 additions and 75 deletions

View File

@@ -50,6 +50,7 @@ if [ -n "$YUM" ]; then
$sudo_command $YUM install -y augeas-devel
$sudo_command $YUM install -y ruby-devel rubygems
$sudo_command $YUM install -y time
$sudo_command $YUM install -y ragel
# dependencies for building packages with fpm
$sudo_command $YUM install -y gcc make rpm-build libffi-devel bsdtar mkosi || true
$sudo_command $YUM install -y graphviz || true # for debugging
@@ -59,6 +60,7 @@ if [ -n "$APT" ]; then
$sudo_command $APT install -y libaugeas-dev || true
$sudo_command $APT install -y ruby ruby-dev || true
$sudo_command $APT install -y libpcap0.8-dev || true
$sudo_command $APT install -y ragel || true
# dependencies for building packages with fpm
$sudo_command $APT install -y build-essential rpm bsdtar || true
# `realpath` is a more universal alternative to `readlink -f` for absolute path resolution
@@ -73,11 +75,11 @@ fi
# Prevent linuxbrew installing redundant deps in CI
if [ -n "$BREW" -a "$RUNNER_OS" != "Linux" ]; then
# coreutils contains gtimeout, gstat, etc
$BREW install pkg-config libvirt augeas coreutils || true
$BREW install pkg-config libvirt augeas coreutils ragel || true
fi
if [ -n "$PACMAN" ]; then
$sudo_command $PACMAN -S --noconfirm --asdeps --needed libvirt augeas rubygems libpcap
$sudo_command $PACMAN -S --noconfirm --asdeps --needed libvirt augeas rubygems libpcap ragel
fi
fold_end "Install dependencies"
@@ -104,6 +106,24 @@ if ! in_ci; then
fi
fi
if in_ci; then
# TODO: consider bumping to new package manager version
RAGEL_VERSION='6.10' # current stable version
RAGEL_TMP='/tmp/ragel/'
RAGEL_FILE="${RAGEL_TMP}ragel-${RAGEL_VERSION}.tar.gz"
RAGEL_DIR="${RAGEL_TMP}ragel-${RAGEL_VERSION}/"
mkdir -p "$RAGEL_TMP"
cd "$RAGEL_TMP"
wget "https://www.colm.net/files/ragel/ragel-${RAGEL_VERSION}.tar.gz" -O "$RAGEL_FILE"
tar -xvf "$RAGEL_FILE"
cd -
cd "$RAGEL_DIR"
./configure --prefix=/usr/local --disable-manual
make
sudo make install
cd -
fi
# attempt to workaround old ubuntu
if [ -n "$APT" -a "$goversion" -lt "$mingoversion" ]; then
echo "install golang from a ppa."