...
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user