From f362105a11797cd4b0a5a1893da95c4cd9bc6475 Mon Sep 17 00:00:00 2001 From: nub31 Date: Sat, 17 May 2025 22:48:08 +0200 Subject: [PATCH] cast syntax change --- example/program.nub | 2 +- .../Nub.Lang/Frontend/Parsing/Parser.cs | 37 ++++++++++--------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/example/program.nub b/example/program.nub index 2d0da97..aa95c8a 100644 --- a/example/program.nub +++ b/example/program.nub @@ -19,5 +19,5 @@ global func main(argc: i64, argv: i64) { parent = &parent } - printf("%s\n", (&test)^.parent^.name^) + printf("%s\n", (test.parent^.name^)) } \ No newline at end of file diff --git a/src/compiler/Nub.Lang/Frontend/Parsing/Parser.cs b/src/compiler/Nub.Lang/Frontend/Parsing/Parser.cs index 88249f2..1698e13 100644 --- a/src/compiler/Nub.Lang/Frontend/Parsing/Parser.cs +++ b/src/compiler/Nub.Lang/Frontend/Parsing/Parser.cs @@ -307,9 +307,9 @@ public class Parser private ExpressionNode ParsePrimaryExpression() { - var token = ExpectToken(); ExpressionNode expr; + var token = ExpectToken(); switch (token) { case LiteralToken literal: @@ -349,28 +349,21 @@ public class Parser { case Symbol.OpenParen: { - // This is ugly - var nextToken = Peek(); - if (nextToken is { Value: IdentifierToken or SymbolToken { Symbol: Symbol.Caret } }) - { - var startIndex = _index; - var type = ParseType(); - - if (TryExpectSymbol(Symbol.CloseParen)) - { - var expressionToCast = ParseExpression(); - expr = new CastNode(type, expressionToCast); - break; - } - - _index = startIndex; - } - var expression = ParseExpression(); ExpectSymbol(Symbol.CloseParen); expr = expression; break; } + case Symbol.LessThan: + { + var type = ParseType(); + ExpectSymbol(Symbol.GreaterThan); + ExpectSymbol(Symbol.OpenParen); + var expressionToCast = ParseExpression(); + ExpectSymbol(Symbol.CloseParen); + expr = new CastNode(type, expressionToCast); + break; + } case Symbol.New: { var type = ParseType(); @@ -438,6 +431,14 @@ public class Parser continue; } + // if (TryExpectSymbol(Symbol.OpenBracket)) + // { + // var index = ParseExpression(); + // ExpectSymbol(Symbol.CloseBracket); + // expr = new ArrayIndexNode(expr, index); + // continue; + // } + break; }