Skip to content

Commit

Permalink
Parser recovery improvements
Browse files Browse the repository at this point in the history
Enhancements:
- Better parser error recovery for incomplete and garbled class, method and property definitions (see #1086)

Technical:
- Rewrite the tokenizer lookahead mechanism so it reliably supports multiple levels of speculation
- Replace use of string concatenation with interpolation throughout the compiler source
  • Loading branch information
degory committed Feb 26, 2024
1 parent 43003e8 commit fb17503
Show file tree
Hide file tree
Showing 198 changed files with 2,057 additions and 1,378 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.13",
"version": "0.8.1",
"commands": [
"ghul-compiler"
]
Expand Down
4 changes: 3 additions & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,6 @@

*.png binary
*.exe binary
*.dll binary
*.dll binary

integration-tests/parse/carriage-returns/test.ghul eol=crlf
34 changes: 17 additions & 17 deletions .github/workflows/dependabot-manual-trigger.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
name: Trigger Dependabot

on:
workflow_dispatch:

jobs:
trigger-dependabot:
runs-on: ubuntu-latest
steps:
- name: Trigger Dependabot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-d '{"event_type": "trigger-dependabot"}'
name: Trigger Dependabot

on:
workflow_dispatch:

jobs:
trigger-dependabot:
runs-on: ubuntu-latest
steps:
- name: Trigger Dependabot
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
curl -X POST -H "Authorization: token $GITHUB_TOKEN" \
-H "Accept: application/vnd.github.v3+json" \
https://api.github.com/repos/${{ github.repository }}/dispatches \
-d '{"event_type": "trigger-dependabot"}'
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<Project>
<PropertyGroup>
<Version>0.7.13-alpha.2</Version>
<Version>0.8.2-alpha.127</Version>
<NoWarn>$(NoWarn);NU1507</NoWarn>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="ghul.runtime" />
</ItemGroup>
</Project>
</Project>
10 changes: 5 additions & 5 deletions integration-tests/parse/carriage-returns/test.ghul
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
namespace Test is
use Std = IO.Std;
class Main is
entry() static is
namespace Test is
use Std = IO.Std;

class Main is
entry() static is
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
}
}
]
}
2 changes: 2 additions & 0 deletions integration-tests/parse/function-nesting-error-1/err.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
test.ghul: 13,13..13,28: error: expected function literal formal arguments
test.ghul: 15,24..15,29: error: cannot return value of type Ghul.int from function of type Test.IncompleteFunction.Test
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions integration-tests/parse/function-nesting-error-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/function-nesting-error-1/ghulflags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
38 changes: 38 additions & 0 deletions integration-tests/parse/function-nesting-error-1/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
namespace Test.IncompleteFunction is
class Test is
count: int;

f(i: int) -> int is
return 0
si

g(i:int) -> int is
count = count - 1;
return 0;

"asdf" (i: int) -> Test is
count = count - 1;
return count;
si

si

i(i: int) -> Test is
let x = if count > 0 then
"count is {count}"
else
"count is 0"
fi;

if count > 0 then
return null
else
return null
fi
si

j(i: int) -> int is
return count
si
si
si
Empty file.
2 changes: 0 additions & 2 deletions integration-tests/parse/incomplete-class-14/err.expected
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
test.ghul: 38,15..38,17: error: in definition: expected @, [, class, enum, identifier, namespace, operator, struct, trait or use but found is
test.ghul: 38,15..38,17: error: in member: expected :, ;, = or => but found is
test.ghul: 38,5..38,14: error: syntax error: expected is but found identifier ICS_STATE
4 changes: 4 additions & 0 deletions integration-tests/parse/incomplete-class-14/test.ghul
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,8 @@ namespace Test is
return diagnostics_for_path;
si
si

class CHECK is

si
si
15 changes: 0 additions & 15 deletions integration-tests/parse/incomplete-class-14/test.ghulproj

This file was deleted.

23 changes: 23 additions & 0 deletions integration-tests/parse/incomplete-function-10/.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
}
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 13,13..13,22: error: nested function definition
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions integration-tests/parse/incomplete-function-10/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/incomplete-function-10/ghulflags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
47 changes: 47 additions & 0 deletions integration-tests/parse/incomplete-function-10/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
namespace Test.IncompleteFunction is
class Test is
count: int;

f(i: int) -> int is
return 0
si

g(i:int) -> int is
count = count - 1;
return 0;

h(i: int) -> Test is
// let x = if count > 0 then
// "count is {count}"
// else
// "count is 0"
// fi;

if count > 0 then
return null
else
return null
fi
si

si

i(i: int) -> Test is
let x = if count > 0 then
"count is {count}"
else
"count is 0"
fi;

if count > 0 then
return null
else
return null
fi
si

j(i: int) -> int is
return count
si
si
si
Empty file.
23 changes: 23 additions & 0 deletions integration-tests/parse/incomplete-function-9/.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/incomplete-function-9/err.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test.ghul: 13,9..13,18: error: expected 'si' after member definition
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

6 changes: 6 additions & 0 deletions integration-tests/parse/incomplete-function-9/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/incomplete-function-9/ghulflags
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--type-check
Empty file.
45 changes: 45 additions & 0 deletions integration-tests/parse/incomplete-function-9/test.ghul
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
namespace Test.IncompleteFunction is
class Test is
count: int;

f(i: int) -> int is
return 0
si

g(i:int) -> int is
count = count - 1;
return 0;

h(i: int) -> Test is
// let x = if count > 0 then
// "count is {count}"
// else
// "count is 0"
// fi;

if count > 0 then
return null
else
return null
fi
si

i(i: int) -> Test is
let x = if count > 0 then
"count is {count}"
else
"count is 0"
fi;

if count > 0 then
return null
else
return null
fi
si

j(i: int) -> int is
return count
si
si
si
Empty file.
Loading

0 comments on commit fb17503

Please sign in to comment.