Allow for short variable assignment

This commit is contained in:
nub31
2025-05-27 15:21:41 +02:00
parent 6a3dcd411c
commit 3fe47a0ed0
2 changed files with 26 additions and 7 deletions

View File

@@ -216,6 +216,17 @@ public class Parser
private StatementNode ParseStatementIdentifier(int startIndex, IdentifierToken identifier)
{
var symbol = ExpectSymbol();
if (TryGetBinaryOperator(symbol.Symbol, out var binaryOperator) && Peek().TryGetValue(out var next) && next is SymbolToken { Symbol: Symbol.Assign })
{
Next();
var left = new IdentifierNode(GetTokensForNode(startIndex), identifier.Value);
var right = ParseExpression();
var binOp = new BinaryExpressionNode(GetTokensForNode(startIndex), left, binaryOperator.Value, right);
return new VariableAssignmentNode(GetTokensForNode(startIndex), identifier.Value, binOp);
}
switch (symbol.Symbol)
{
case Symbol.DoubleColon:
@@ -286,7 +297,7 @@ public class Parser
{
value = ParseExpression();
}
return new VariableDeclarationNode(GetTokensForNode(startIndex), name, type, value);
}
@@ -643,6 +654,7 @@ public class Parser
{
@namespace = ExpectIdentifier().Value;
}
return new NubStructType(@namespace, name);
}
}