This commit is contained in:
nub31
2025-09-29 16:23:39 +02:00
parent 933c52ac1e
commit 428d69d242
13 changed files with 568 additions and 474 deletions

View File

@@ -86,6 +86,7 @@ public sealed class Parser
{
Symbol.Func => ParseFunc(startIndex, exported, null),
Symbol.Struct => ParseStruct(startIndex, exported),
Symbol.Let => ParseGlobalVariable(startIndex, exported),
_ => throw new ParseException(Diagnostic
.Error($"Expected 'func' or 'struct' but found '{keyword.Symbol}'")
.WithHelp("Valid definition keywords are 'func' and 'struct'")
@@ -113,6 +114,22 @@ public sealed class Parser
return definitions;
}
private GlobalVariableSyntax ParseGlobalVariable(int startIndex, bool exported)
{
var name = ExpectIdentifier();
TypeSyntax? type = null;
if (TryExpectSymbol(Symbol.Colon))
{
type = ParseType();
}
ExpectSymbol(Symbol.Assign);
var value = ParseExpression();
return new GlobalVariableSyntax(GetTokens(startIndex), name.Value, exported, type, value);
}
private FuncSignatureSyntax ParseFuncSignature()
{
var startIndex = _tokenIndex;