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

Fix empty braced object blocks and add null object statements #2175

Merged
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
3 changes: 3 additions & 0 deletions DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ public abstract class DMASTStatement(Location location) : DMASTNode(location);
/// <remarks>Emit an error code before creating!</remarks>
public sealed class DMASTInvalidStatement(Location location) : DMASTStatement(location);

/// Lone semicolon, statement containing nothing
public sealed class DMASTNullStatement(Location location) : DMASTStatement(location);

public sealed class DMASTObjectDefinition(Location location, DreamPath path, DMASTBlockInner? innerBlock)
: DMASTStatement(location) {
/// <summary> Unlike other Path variables stored by AST nodes, this path is guaranteed to be the real, absolute path of this object definition block. <br/>
Expand Down
7 changes: 6 additions & 1 deletion DMCompiler/Compiler/DM/DMParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,11 @@ public DMASTFile File() {
protected DMASTStatement? Statement() {
var loc = CurrentLoc;

if (Current().Type == TokenType.DM_Semicolon) { // A lone semicolon creates a "null statement" (like C)
// Note that we do not consume the semicolon here
return new DMASTNullStatement(loc);
}

DMASTPath? path = Path();
if (path is null)
return null;
Expand Down Expand Up @@ -536,7 +541,7 @@ public DMASTFile File() {
Newline();
Consume(TokenType.DM_RightCurlyBracket, "Expected '}'");

return new DMASTBlockInner(loc, blockInner.ToArray());
return new DMASTBlockInner(loc, blockInner?.ToArray() ?? []);
}

return null;
Expand Down
5 changes: 3 additions & 2 deletions DMCompiler/DM/Builders/DMCodeTreeBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ private void ProcessStatement(DMASTStatement statement, DreamPath currentType) {
}

switch (statement) {
case DMASTInvalidStatement:
break; // An error should have been emitted by whatever made this
case DMASTInvalidStatement: // An error should have been emitted by whatever made this
case DMASTNullStatement:
break;
case DMASTObjectDefinition objectDefinition:
CodeTree.AddType(objectDefinition.Path);
if (objectDefinition.InnerBlock != null)
Expand Down
Loading