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

Experimental support for if expressions #1069

Merged
merged 1 commit into from
Feb 17, 2024
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 .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.6",
"version": "0.7.7",
"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.7-alpha.25</Version>
<Version>0.7.8-alpha.58</Version>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace Test is
si

run() is

var buffer: System.Text.StringBuilder = null;
let buffer: System.Text.StringBuilder = null;

let c = next_char();

Expand Down
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, 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 or typeof 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, 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 or typeof but found []
test.ghul: 15,37..15,39: error: syntax error: expected ; but found []
3 changes: 1 addition & 2 deletions integration-tests/parse/incomplete-call-1/err.expected
Original file line number Diff line number Diff line change
@@ -1,4 +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, 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 or typeof but found si
test.ghul: 8,9..8,11: error: in secondary expression: expected ) but found si
test.ghul: 8,9..8,11: error: syntax error: 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, 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 or typeof 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, 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 or typeof 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, 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 or typeof but found si
2 changes: 1 addition & 1 deletion 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, 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 or typeof but found 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,2 +1,2 @@
test.ghul: 8,9..8,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, 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 or typeof but found si
test.ghul: 8,9..8,11: error: syntax error: expected then but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-if-1/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Test.ParseIncompleteIf is

class Test is
test() is
var x: int;
let x: int;

if
si
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-if-2/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Test.ParseUnary is

class Test is
test() is
var x: int;
let x: int;

if 1 == 1
si
Expand Down
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-if-3/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Test.ParseUnary is

class Test is
test() is
var x: int;
let x: int;

if 1 == 1 then
si
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 3,1..3,3: error: syntax error: expected ; but found si
test.ghul: 3,1..3,3: error: syntax error: expected identifier 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, 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 or typeof 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, 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 or typeof 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
@@ -1,2 +1,2 @@
test.ghul: 5,5..5,7: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, 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 or typeof 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, 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 or typeof 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
@@ -1,2 +1 @@
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
test.ghul: 7,9..7,11: error: syntax error: expected identifier but found si
Empty file.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 6,25..6,27: error: in type expression: expected ( or identifier but found in
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
Empty file.
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-10/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Test.ParseUnary is

class Test is
function() is
var x: List[in
let x: List[in
si
si
si
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 6,17..6,18: error: variable must have explict type or initializer
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
Empty file.
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-2/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Test.ParseUnary is

class Test is
function() is
let x
let x // no longer a syntax error now ; is a separator not a terminator
si
si
si
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
Empty file.
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-3/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Test.ParseUnary is

class Test is
function() is
let x: int
let x: int // no longer a syntax error now ; is a separator not a terminator
si
si
si
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 7,9..7,11: error: in type expression: expected ( or identifier but found si
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
Empty file.
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 7,9..7,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 7,9..7,11: error: syntax error: expected ; 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 or typeof but found si
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 7,9..7,11: error: in primary expression: expected (, [, cast, char literal, false, float literal, identifier, int literal, isa, new, null, self, string literal, super, true or typeof but found si
test.ghul: 7,9..7,11: error: syntax error: expected ; 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 or typeof but found si
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-6/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,6 @@ namespace Test.ParseIncompleteVariable is
class Test is
function() is
let x = 123 +
si
si
si
si
Original file line number Diff line number Diff line change
@@ -1 +0,0 @@
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
Empty file.
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-7/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Test.ParseUnary is

class Test is
function() is
let x = 123 + 456
let x = 123 + 456 // no longer a syntax error now ; is a separator not a terminator
si
si
si
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 7,9..7,11: error: in type expression: expected ( or identifier but found si
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
Empty file.
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-8/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Test.ParseUnary is

class Test is
function() is
var x:
let x:
si
si
si
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
test.ghul: 6,20..6,22: error: in type expression: expected ( or identifier but found in
test.ghul: 7,9..7,11: error: syntax error: expected ; but found si
Empty file.
2 changes: 1 addition & 1 deletion integration-tests/parse/incomplete-variable-9/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Test.ParseUnary is

class Test is
function() is
var x: in
let x: in
si
si
si
23 changes: 23 additions & 0 deletions integration-tests/parse/return-expression-1/.vscode/tasks.json
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
}
}
]
}
1 change: 1 addition & 0 deletions integration-tests/parse/return-expression-1/err.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 113,16..113,22: error: syntax error: expected ; but found return
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions integration-tests/parse/return-expression-1/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
1 change: 1 addition & 0 deletions integration-tests/parse/return-expression-1/ghulflags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
115 changes: 115 additions & 0 deletions integration-tests/parse/return-expression-1/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
namespace Test.ReturnExpression is

// these are all valid return expression initial tokens
/*
Lexical.TOKEN.IDENTIFIER,
Lexical.TOKEN.SQUARE_OPEN,
Lexical.TOKEN.PAREN_OPEN,
Lexical.TOKEN.NEW,
Lexical.TOKEN.CAST,
Lexical.TOKEN.ISA,
Lexical.TOKEN.TYPEOF,
Lexical.TOKEN.INT_LITERAL,
Lexical.TOKEN.FLOAT_LITERAL,
Lexical.TOKEN.STRING_LITERAL,
Lexical.TOKEN.CHAR_LITERAL,
Lexical.TOKEN.TRUE,
Lexical.TOKEN.FALSE,
Lexical.TOKEN.NULL,
Lexical.TOKEN.SELF,
Lexical.TOKEN.SUPER,
Lexical.TOKEN.IF,
Lexical.TOKEN.OPERATOR
*/

blah: int;

test_identifier() -> int is
return blah
si

test_square_open() -> int[] is
return [1, 2, 3]
si

test_paren_open() -> int is
return (1 + 2)
si

test_new() -> object is
return new object()
si

test_cast() -> int is
return cast int(1.0)
si

test_isa() -> bool is
return isa int(1.0)
si

test_typeof() -> System.Type2 is
return typeof int
si

test_int_literal() -> int is
return 1
si

test_float_literal() -> single is
return 1.0
si

test_string_literal() -> string is
return "hello"
si

test_char_literal() -> char is
return 'a'
si

test_true() -> bool is
return true
si

test_false() -> bool is
return false
si

test_null() -> object is
return null
si

class Test is
test_self() -> object is
return self
si
si

class Test2 is
test_super() -> object is
return super
si
si

test_if() -> int is
return
if true then
1
else
2
fi
si

test_operator_1() -> bool is
return !true
si

test_operator_2() -> int is
return -1234
si

test_fail() is
return return // have at least one failure so we know the test compiled at all
si
si
Empty file.
23 changes: 23 additions & 0 deletions integration-tests/parse/return-expression-2/.vscode/tasks.json
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
}
}
]
}
1 change: 1 addition & 0 deletions integration-tests/parse/return-expression-2/err.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 113,16..113,22: error: syntax error: expected ; but found return
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions integration-tests/parse/return-expression-2/ghul.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"compiler": "dotnet ../../../publish/ghul.dll",
"source": [
"."
]
}
1 change: 1 addition & 0 deletions integration-tests/parse/return-expression-2/ghulflags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
Loading
Loading