Skip to content

Commit 75b5cf2

Browse files
authored
Fix empty braced object blocks and add null object statements (#2175)
1 parent 487a30c commit 75b5cf2

File tree

3 files changed

+12
-3
lines changed

3 files changed

+12
-3
lines changed

DMCompiler/Compiler/DM/AST/DMAST.ObjectStatements.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ public abstract class DMASTStatement(Location location) : DMASTNode(location);
1313
/// <remarks>Emit an error code before creating!</remarks>
1414
public sealed class DMASTInvalidStatement(Location location) : DMASTStatement(location);
1515

16+
/// Lone semicolon, statement containing nothing
17+
public sealed class DMASTNullStatement(Location location) : DMASTStatement(location);
18+
1619
public sealed class DMASTObjectDefinition(Location location, DreamPath path, DMASTBlockInner? innerBlock)
1720
: DMASTStatement(location) {
1821
/// <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/>

DMCompiler/Compiler/DM/DMParser.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,11 @@ public DMASTFile File() {
203203
protected DMASTStatement? Statement() {
204204
var loc = CurrentLoc;
205205

206+
if (Current().Type == TokenType.DM_Semicolon) { // A lone semicolon creates a "null statement" (like C)
207+
// Note that we do not consume the semicolon here
208+
return new DMASTNullStatement(loc);
209+
}
210+
206211
DMASTPath? path = Path();
207212
if (path is null)
208213
return null;
@@ -536,7 +541,7 @@ public DMASTFile File() {
536541
Newline();
537542
Consume(TokenType.DM_RightCurlyBracket, "Expected '}'");
538543

539-
return new DMASTBlockInner(loc, blockInner.ToArray());
544+
return new DMASTBlockInner(loc, blockInner?.ToArray() ?? []);
540545
}
541546

542547
return null;

DMCompiler/DM/Builders/DMCodeTreeBuilder.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,9 @@ private void ProcessStatement(DMASTStatement statement, DreamPath currentType) {
4040
}
4141

4242
switch (statement) {
43-
case DMASTInvalidStatement:
44-
break; // An error should have been emitted by whatever made this
43+
case DMASTInvalidStatement: // An error should have been emitted by whatever made this
44+
case DMASTNullStatement:
45+
break;
4546
case DMASTObjectDefinition objectDefinition:
4647
CodeTree.AddType(objectDefinition.Path);
4748
if (objectDefinition.InnerBlock != null)

0 commit comments

Comments
 (0)