Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

String interpolation new #729

Merged
merged 9 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/checks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Install deps
run: sudo apt-get -qy update && sudo apt-get install -y libssl1.0-dev libssl1.0
run: sudo apt-get -qy update && sudo apt-get install -y libssl-dev libssl1.1
- uses: actions-rs/toolchain@v1
with:
override: true
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/eqc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1.0.0
- uses: gleam-lang/setup-erlang@v1.0.0
- uses: gleam-lang/setup-erlang@v1.1.2
with:
otp-version: 22.1
otp-version: 23.1
- name: Install deps
run: sudo apt-get -qy update && sudo apt-get install -y libssl1.0-dev libssl1.0
run: sudo apt-get -qy update && sudo apt-get install -y libssl-dev libssl1.1
- name: Install yaml2json
run: go get github.com/bronze1man/yaml2json
- name: install EQC
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- uses: actions/checkout@v1
- name: Install deps
if: matrix.os == 'ubuntu-latest'
run: sudo apt-get -qy update && sudo apt-get install -y libssl1.0-dev libssl1.0
run: sudo apt-get -qy update && sudo apt-get install -y libssl-dev libssl1.1
- uses: actions-rs/toolchain@v1
with:
override: true
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install deps [Linux]
run: sudo apt-get -qy update && sudo apt-get install -y libssl1.0-dev libssl1.0
run: sudo apt-get -qy update && sudo apt-get install -y libssl-dev libssl1.1
- uses: actions-rs/toolchain@v1
with:
override: true
Expand All @@ -24,7 +24,7 @@ jobs:
steps:
- uses: actions/checkout@v2
- name: Install deps
run: sudo apt-get -qy update && sudo apt-get install -y libssl1.0-dev libssl1.0
run: sudo apt-get -qy update && sudo apt-get install -y libssl-dev libssl1.1
- uses: actions-rs/toolchain@v1
with:
override: true
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

## Latest

### Breaking Changes

* String interpolation is now done via `#{..}` instead of `{}`. `{` no longer needs to be escaped, but `\#{` needs an escape for literal `#{`.

### New features

* Default to thin-lto for all builds (prior this was only done in docker)
Expand All @@ -11,6 +15,8 @@
* Statically link openssl
* elastic sink now supports linked transports [#715](https://github.com/tremor-rs/tremor-runtime/pull/715)

### Fixes
* rewrite string interpolation to fix [#726](https://github.com/tremor-rs/tremor-runtime/issues/726)
## 0.9.4

### New features
Expand Down
2 changes: 1 addition & 1 deletion tests/queries/state/query.trickle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ script
let state.count = state.count + 1
end;

{ "e": event, "{args.name}": state.count }
{ "e": event, "#{args.name}": state.count }
end;

create script seq1 from countable with name = "s1" end;
Expand Down
6 changes: 6 additions & 0 deletions tests/script.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,12 @@ test_cases!(
// TODO
// const_in_const_lookup,
// INSERT
string_interpolation_nested,
string_interpolation_escaped_hash,
string_interpolation_escaped,
string_interpolation_simple,
string_interpolation_tailing,
string_interpolation_regexp,
binary_binary,
binary_binary_string,
binary_string_binary,
Expand Down
1 change: 1 addition & 0 deletions tests/script_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ test_cases!(
pp_cyclic,
pp_nest_cyclic,
//INSERT
string_interpolation_empty,
fn_bad_recur,
script_without_newline,
lexer_invalid_hex2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error:
1 | let heredoc = """
2 | { | }
| ^^^ It looks like you forgot to terminate an extractor with a closing '|'
2 | #{ | }
| ^^^ It looks like you forgot to terminate an extractor with a closing '|'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
let heredoc = """
{ | }
#{ | }
""";
4 changes: 2 additions & 2 deletions tests/script_errors/heredoc_interpolation_ident/error.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error:
1 | """
2 | before { `ident unfinished } after
| ^^^^^^^^^^^^^^^^^^^^^^^^^ It looks like you forgot to terminate an ident with a closing '`'
2 | before #{ `ident unfinished } after
| ^^^^^^^^^^^^^^^^^^^^^^^^^ It looks like you forgot to terminate an ident with a closing '`'
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
"""
before { `ident unfinished } after
before #{ `ident unfinished } after
"""
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error:
1 | """
2 | { "
| ^ It looks like you forgot to terminate a string with a closing '"'
2 | #{ "
| ^ It looks like you forgot to terminate a string with a closing '"'
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
{ "
#{ "

}
"""
6 changes: 3 additions & 3 deletions tests/script_errors/lexer_heredoc_interpolation/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Error:
1 | """
2 | {
| ^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '{' ? Escape it as '\{' or '{{'.
2 | #{
| ^^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '#{'? Escape it as '\#{'.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""
{
#{
6 changes: 3 additions & 3 deletions tests/script_errors/lexer_heredoc_interpolation2/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Error:
1 | """
2 | {"""
| ^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '{' ? Escape it as '\{' or '{{'.
2 | #{"""
| ^^^^^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '#{'? Escape it as '\#{'.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""
{"""
#{"""
6 changes: 3 additions & 3 deletions tests/script_errors/lexer_heredoc_interpolation3/error.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Error:
2 | let x = """
3 | {""";
| ^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '{' ? Escape it as '\{' or '{{'.
3 | #{""";
| ^^^^^^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '#{'? Escape it as '\#{'.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
use std::string;
let x = """
{""";
#{""";
6 changes: 3 additions & 3 deletions tests/script_errors/lexer_string_interpolation/error.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error:
1 | "{"
| ^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '{' ? Escape it as '\{' or '{{'.
1 | "#{"
| ^^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '#{'? Escape it as '\#{'.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
"{"
"#{"
6 changes: 3 additions & 3 deletions tests/script_errors/lexer_string_interpolation2/error.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error:
1 | let x = "before { { {}";
| ^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '{' ? Escape it as '\{' or '{{'.
1 | let x = "before #{ { {}";
| ^^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '#{'? Escape it as '\#{'.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
let x = "before { { {}";
let x = "before #{ { {}";

4 changes: 2 additions & 2 deletions tests/script_errors/lexer_string_interpolation3/error.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error:
1 | use std::string;
2 | let e = "\u0065 { `unterminated_ident } \u0076 {2} \u0080";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It looks like you forgot to terminate an ident with a closing '`'
2 | let e = "\u0065 #{ `unterminated_ident } \u0076 #{2} \u0080";
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ It looks like you forgot to terminate an ident with a closing '`'
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
use std::string;
let e = "\u0065 { `unterminated_ident } \u0076 {2} \u0080";
let e = "\u0065 #{ `unterminated_ident } \u0076 #{2} \u0080";
5 changes: 5 additions & 0 deletions tests/script_errors/new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,8 @@ git add ${TARGET}

sed -e '/^ \/\/INSERT/a\
'"${NAME}," ${BASEDIR}/../script_error.rs > ${BASEDIR}/tmp && mv ${BASEDIR}/tmp ${BASEDIR}/../script_error.rs

for f in ${TARGET}/*
do
echo "$f"
done
4 changes: 4 additions & 0 deletions tests/script_errors/string_interpolation_empty/error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Error:
1 | "#{}"
| ^^^ You have an interpolation without content.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😻

| NOTE: Did you mean to write a literal '#{'? Escape it as '\#{'.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"#{}"
6 changes: 3 additions & 3 deletions tests/script_errors/string_interpolation_eof/error.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Error:
1 | let si = "before {
| ^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '{' ? Escape it as '\{' or '{{'.
1 | let si = "before #{
| ^^ It looks like you forgot to terminate a string interpolation with a closing '}'
| NOTE: Did you mean to write a literal '#{'? Escape it as '\#{'.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let si = "before {
let si = "before #{
4 changes: 2 additions & 2 deletions tests/script_errors/string_interpolation_escape/error.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Error:
1 | let escape = " { "\z" } ";
| ^^ An unexpected escape code 'z' was found
1 | let escape = " #{ "\z" } ";
| ^^ An unexpected escape code 'z' was found
Original file line number Diff line number Diff line change
@@ -1 +1 @@
let escape = " { "\z" } ";
let escape = " #{ "\z" } ";
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Error:
1 | " { | } "
| ^^^^^ It looks like you forgot to terminate an extractor with a closing '|'
1 | " #{ | } "
| ^^^^^ It looks like you forgot to terminate an extractor with a closing '|'
Original file line number Diff line number Diff line change
@@ -1 +1 @@
" { | } "
" #{ | } "
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
Error:
1 | " { " \u666G " } "
| ^^^^^^ An invalid UTF8 escape sequence was found
1 | " #{ " \u666G " } "
| ^^^^^^ An invalid UTF8 escape sequence was found
Original file line number Diff line number Diff line change
@@ -1 +1 @@
" { " \u666G " } "
" #{ " \u666G " } "
1 change: 1 addition & 0 deletions tests/script_runtime_error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ test_cases!(
subslice_no_arr,
subslice_out_of_bounds,
undefined_local,
recursion_limit,
);

// There errors on thise are not optimal
Expand Down
2 changes: 2 additions & 0 deletions tests/script_runtime_errors/function_error_1/error.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Error:
2 |
3 | let a = 7;
4 | record::from_array(a)
| ^^^^^^^^^^^^^^^^^^^^^ Bad type passed to function record::from_array/1
2 changes: 2 additions & 0 deletions tests/script_runtime_errors/function_error_2/error.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Error:
1 | use std::math;
2 | let a = 7;
3 | math::max("snot", a)
| ^^^^^^^^^^^^^^^^^^^^ Bad type passed to function math::max/2
4 changes: 3 additions & 1 deletion tests/script_runtime_errors/function_error_3/error.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Error:
1 | use std::string;
2 | let a = 7;
3 | string::format(a, "snot", "badger")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Runtime error in function string::format/3: expected 1st parameter to format to be a format specifier e.g. to print a number use `string::format("{}", 1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Runtime error in function string::format/3: expected 1st parameter to format to be a format specifier e.g. to print a number use `string::format("{}", 1)`
4 changes: 3 additions & 1 deletion tests/script_runtime_errors/function_error_n/error.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Error:
1 | use std::string;
2 | let a = 7;
3 | string::format(a, "snot", "badger", "cake")
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Runtime error in function string::format/4: expected 1st parameter to format to be a format specifier e.g. to print a number use `string::format("{}", 1)`
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Runtime error in function string::format/4: expected 1st parameter to format to be a format specifier e.g. to print a number use `string::format("{}", 1)`
5 changes: 5 additions & 0 deletions tests/script_runtime_errors/recursion_limit/error.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Error:
4 | end;
5 |
6 | boom(1)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💥

| ^^^^^^^ Recursion limit Reached
Binary file not shown.
6 changes: 6 additions & 0 deletions tests/script_runtime_errors/recursion_limit/script.tremor
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
fn boom(x) with
let x = x + 1;
recur(x)
end;

boom(1)
2 changes: 1 addition & 1 deletion tests/scripts/const_of_const/script.tremor
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const a = "snot";
const b = ( a + " badger" );

"{b}: {event}!"
"#{b}: #{event}!"
2 changes: 1 addition & 1 deletion tests/scripts/fn_extractors/script.tremor
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::type;
fn snottify(s) of
case ("badger") => "snot badger, hell yea!"
case (~ json||) => let s.snot = true, s
case (s) when type::is_string(s) => "snot {s}"
case (s) when type::is_string(s) => "snot #{s}"
default => "snot caller, you can't snottify that!"
end;

Expand Down
6 changes: 3 additions & 3 deletions tests/scripts/fn_nest2_abs_fib/script.tremor
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
mod b with
fn snot(n) with
"cake {n}"
"cake #{n}"
end;
end;

mod a with
mod b with
fn snot(n) with "snot {n}" end
fn snot(n) with "snot #{n}" end
end;
fn badger(n) with "{b::snot(n)} badger {n}" end
fn badger(n) with "#{b::snot(n)} badger #{n}" end
end;

[a::badger(event), b::snot(event)]
4 changes: 2 additions & 2 deletions tests/scripts/fn_nest2_fib/script.tremor
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
mod a with
mod b with
fn snot(n) with "snot {n}" end
fn snot(n) with "snot #{n}" end
end;
fn badger(n) with "{b::snot(n)} badger {n}" end
fn badger(n) with "#{b::snot(n)} badger #{n}" end
end;

a::badger(event)
Loading