...
This commit is contained in:
@@ -84,7 +84,6 @@ 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'")
|
||||
@@ -112,22 +111,6 @@ 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;
|
||||
@@ -924,21 +907,6 @@ public sealed class Parser
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private IntLiteralToken ExpectIntLiteral()
|
||||
{
|
||||
var token = ExpectToken();
|
||||
if (token is not IntLiteralToken identifier)
|
||||
{
|
||||
throw new ParseException(Diagnostic
|
||||
.Error($"Expected int literal, but found {token.GetType().Name}")
|
||||
.WithHelp("Provide a valid int literal")
|
||||
.At(token)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private bool TryExpectIntLiteral([NotNullWhen(true)] out IntLiteralToken? stringLiteral)
|
||||
{
|
||||
if (CurrentToken is IntLiteralToken token)
|
||||
@@ -952,36 +920,6 @@ public sealed class Parser
|
||||
return false;
|
||||
}
|
||||
|
||||
private FloatLiteralToken ExpectFloatLiteral()
|
||||
{
|
||||
var token = ExpectToken();
|
||||
if (token is not FloatLiteralToken identifier)
|
||||
{
|
||||
throw new ParseException(Diagnostic
|
||||
.Error($"Expected float literal, but found {token.GetType().Name}")
|
||||
.WithHelp("Provide a valid float literal")
|
||||
.At(token)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private BoolLiteralToken ExpectBoolLiteral()
|
||||
{
|
||||
var token = ExpectToken();
|
||||
if (token is not BoolLiteralToken identifier)
|
||||
{
|
||||
throw new ParseException(Diagnostic
|
||||
.Error($"Expected bool literal, but found {token.GetType().Name}")
|
||||
.WithHelp("Provide a valid bool literal")
|
||||
.At(token)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return identifier;
|
||||
}
|
||||
|
||||
private StringLiteralToken ExpectStringLiteral()
|
||||
{
|
||||
var token = ExpectToken();
|
||||
|
||||
Reference in New Issue
Block a user