Skip to content

Commit

Permalink
Allow trailing semicolon
Browse files Browse the repository at this point in the history
  • Loading branch information
PaddiM8 committed Dec 22, 2024
1 parent 4edfd9a commit 28c978f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
1 change: 1 addition & 0 deletions generators/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,3 +49,4 @@
},
}
}

16 changes: 14 additions & 2 deletions src/Parsing/Parser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using Elk.Exceptions;
using Elk.Lexing;
using Elk.Parsing;
using Elk.Scoping;
using Elk.Std.Bindings;
using Elk.Std.DataTypes;
Expand Down Expand Up @@ -106,6 +108,9 @@ public static (Ast ast, List<DiagnosticMessage> diagnostics) Parse(
return null;

var expr = ParseExprOrDecl();
if (expr == null)
return null;

expr.IsRoot = true;
SkipWhiteSpace();

Expand Down Expand Up @@ -250,13 +255,16 @@ private ModuleScope ImportUserModule(string path, string moduleName, TextPos pos
return importScope;
}

private Expr ParseExprOrDecl()
private Expr? ParseExprOrDecl()
{
SkipWhiteSpace();

while (AdvanceIf(TokenKind.Semicolon))
SkipWhiteSpace();

if (ReachedEnd)
return null;

if (AdvanceIf(TokenKind.Pub))
{
SkipWhiteSpace();
Expand Down Expand Up @@ -1215,7 +1223,11 @@ private Expr ParseBlock(
{
try
{
expressions.Add(ParseExprOrDecl());
var expr = ParseExprOrDecl();
if (expr == null)
continue;

expressions.Add(expr);
if (!orAsOtherStructure)
continue;

Expand Down
2 changes: 1 addition & 1 deletion src/ShellSession.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,4 +284,4 @@ void CallOnExit()

CallOnExit();
}
}
}
1 change: 1 addition & 0 deletions src/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,4 @@
},
}
}

0 comments on commit 28c978f

Please sign in to comment.