Skip to content

Commit

Permalink
String interpolation (#1078)
Browse files Browse the repository at this point in the history
Enhancements:
- Add initial support for string interpolation (see #1071)

Bugs fixed:
- Can't use ref struct types (partial fix only #1077)
  • Loading branch information
degory authored Feb 20, 2024
1 parent 8c9df61 commit 700e3c4
Show file tree
Hide file tree
Showing 117 changed files with 822 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
]
},
"ghul.compiler": {
"version": "0.7.9",
"version": "0.7.10",
"commands": [
"ghul-compiler"
]
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<Version>0.7.9-alpha.74</Version>
<Version>0.7.11-alpha.19</Version>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Empty file.
6 changes: 6 additions & 0 deletions integration-tests/execution/string-interpolation-1/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interpolate 30 and -10 together
20 at the beginning and 0 in the middle
now 40 in the middle and end with 40
13-5
15 changes: 15 additions & 0 deletions integration-tests/execution/string-interpolation-1/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use IO.Std.write_line;

entry() is
let x = 10;
let y = 20;

write_line({interpolate {x+y} and {x-y} together});

write_line({{x+x} at the beginning and {y-y} in the middle});

write_line({now {x+y+x} in the middle and end with {x + x + y}});

write_line({{x + 3}{x - y + 5}});
si

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Empty file.
6 changes: 6 additions & 0 deletions integration-tests/execution/string-interpolation-2/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
interpolate 132 and -209 together
220 at the beginning and 0 in the middle
now 242 in the middle and end with 341
41-204
17 changes: 17 additions & 0 deletions integration-tests/execution/string-interpolation-2/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use IO.Std.write_line;

test(x: int) -> int => x * 10;

entry() is
let x = 11;
let y = 22;

write_line({interpolate {test(x)+y} and {x-test(y)} together});

write_line({{test(x)+test(x)} at the beginning and {test(y-y)} in the middle});

write_line({now {x+test(y)+x} in the middle and end with {test(x) + x + test(y)}});

write_line({{x + test(3)}{x - test(y) + 5}});
si

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Empty file.
6 changes: 6 additions & 0 deletions integration-tests/execution/string-interpolation-3/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Empty file.
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
interpolate /interpolate x: 11/ and /interpolate y: 22/ together
13 changes: 13 additions & 0 deletions integration-tests/execution/string-interpolation-3/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
use IO.Std.write_line;

test(x: string) -> string => {/{x}/};

entry() is
let x = 11;
let y = 22;

test("hello");

write_line({interpolate {test({interpolate x: {x}})} and {test({interpolate y: {y}})} together});
si

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions integration-tests/execution/string-interpolation-4/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
15 changes: 15 additions & 0 deletions integration-tests/execution/string-interpolation-4/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use IO.Std.write_line;

entry() is
let x = 10;
let y = 20;

write_line({interpolate {x+y} and {x-y} together});

write_line({{x+x} at the beginning and {y-y} in the middle});

write_line({now {x+y+x} in the middle and end with {x + x + y}});

write_line({{x + 3}{x - y + 5}});
si

Empty file.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test.ghul: 11,37..11,39: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found []
test.ghul: 11,37..11,39: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found []
test.ghul: 11,37..11,39: error: syntax error: expected ; but found []
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test.ghul: 15,37..15,39: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found []
test.ghul: 15,37..15,39: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found []
test.ghul: 15,37..15,39: error: syntax error: expected ; but found []
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-call-1/err.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
test.ghul: 7,13..7,17: error: symbol not found: blah
test.ghul: 8,9..8,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 8,9..8,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
test.ghul: 8,9..8,11: error: in secondary expression: expected ) but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-enum-6/err.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test.ghul: 8,1..8,2: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 8,1..8,2: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-for-10/err.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test.ghul: 2,14..2,16: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found do
test.ghul: 2,14..2,16: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found do
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-for-3/err.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test.ghul: 4,1..4,3: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 4,1..4,3: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
4 changes: 2 additions & 2 deletions integration-tests/parse/incomplete-for-4/err.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test.ghul: 4,1..4,3: error: in for statement: expected do but found si
test.ghul: 4,1..4,3: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 3,1..3,3: error: in for statement: expected do but found si
test.ghul: 3,1..3,3: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
2 changes: 0 additions & 2 deletions integration-tests/parse/incomplete-for-4/test.ghul
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@

variable_in_and_half_a_range() is
for i in 0..
si

2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-if-1/err.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test.ghul: 8,9..8,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 8,9..8,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test.ghul: 5,5..5,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 5,5..5,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
test.ghul: 5,5..5,7: error: syntax error: expected ; but found si
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test.ghul: 6,5..6,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 6,5..6,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
test.ghul: 6,5..6,7: error: syntax error: expected ; but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-property-3/err.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test.ghul: 5,5..5,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 5,5..5,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
test.ghul: 5,5..5,7: error: syntax error: expected ; but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-property-4/err.expected
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
test.ghul: 6,5..6,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 6,5..6,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
test.ghul: 6,5..6,7: error: syntax error: expected ; but found si
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 6,5..7,1: error: newline in interpolation
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

entry() is
let x = 10;
let y = 20;

{interpolate
si

Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"version": "2.0.0",
"tasks": [
{
"label": "Run test",
"command": "dotnet ghul-test \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "test",
"isDefault": true
}
},
{
"label": "Capture test expectation",
"command": "../../../tasks/capture.sh \"${workspaceFolder}\"",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test.ghul: 7,19..8,1: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found cancel string
test.ghul: 7,19..8,1: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found cancel string
test.ghul: 7,19..8,1: error: newline in interpolation
test.ghul: 7,19..8,1: error: syntax error: expected ; but found cancel string
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

entry() is
let x = 10;
let y = 20;

// FIXME we need better error recovery here
{interpolate {}
si

Empty file.
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-5/err.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test.ghul: 7,9..7,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 7,9..7,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-6/err.expected
Original file line number Diff line number Diff line change
@@ -1 +1 @@
test.ghul: 7,9..7,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 7,9..7,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, if, int literal, isa, new, null, self, string literal, super, true, typeof or { but found si
Loading

0 comments on commit 700e3c4

Please sign in to comment.