@@ -347,20 +347,43 @@ Expr *struct_expr(Parser *parser) {
347347}
348348
349349// Named struct initialization: Point { x: 20, y: 50 }
350- // This is called from led() when we see '{' after an identifier
350+ // OR namespace::Point { x: 20, y: 50 }
351+ // This is called from led() when we see '{' after an identifier or member expr
351352Expr * named_struct_expr (Parser * parser , Expr * left , BindingPower bp ) {
352353 (void )bp ; // Unused parameter
353354
354- // left should be an identifier expression containing the struct name
355- if (left -> type != AST_EXPR_IDENTIFIER ) {
355+ char * struct_name = NULL ;
356+
357+ // Handle both identifier and member expressions
358+ if (left -> type == AST_EXPR_IDENTIFIER ) {
359+ // Simple case: Point { ... }
360+ struct_name = left -> expr .identifier .name ;
361+ } else if (left -> type == AST_EXPR_MEMBER ) {
362+ // Namespace resolution: namespace::Point { ... }
363+ // Build the full qualified name from the member expression
364+
365+ // For now, we'll extract the name from the member expression
366+ // This assumes the member expression represents something like
367+ // "namespace::Point" You might need to adjust this based on how your AST
368+ // represents member expressions
369+
370+ // Get the member name (the rightmost part, e.g., "Point" in
371+ // "namespace::Point")
372+ struct_name = left -> expr .member .member ;
373+
374+ // Note: If you need the full qualified name, you'll need to traverse
375+ // the member expression tree and build the complete path
376+ // For example: if left->expr.member.object is also a member expr,
377+ // you'd need to recursively build the name
378+ } else {
356379 parser_error (parser , "SyntaxError" , parser -> file_path ,
357- "Expected identifier before '{' for named struct" ,
380+ "Expected identifier or namespace resolution before '{' for "
381+ "named struct" ,
358382 p_current (parser ).line , p_current (parser ).col ,
359383 p_current (parser ).length );
360384 return NULL ;
361385 }
362386
363- char * struct_name = left -> expr .identifier .name ;
364387 int line = p_current (parser ).line ;
365388 int col = p_current (parser ).col ;
366389
@@ -425,7 +448,8 @@ Expr *named_struct_expr(Parser *parser, Expr *left, BindingPower bp) {
425448
426449 p_consume (parser , TOK_RBRACE , "Expected '}' to close struct expression" );
427450
428- // Named struct
451+ // Store the full expression (identifier or member) for later use
452+ // This allows the semantic analyzer to resolve the namespace properly
429453 return create_struct_expr (
430454 parser -> arena , struct_name , (char * * )field_names .data ,
431455 (AstNode * * )field_values .data , field_names .count , line , col );
@@ -483,20 +507,26 @@ Expr *free_expr(Parser *parser) {
483507
484508// cast<TYPE>(value);
485509Expr * cast_expr (Parser * parser ) {
486- p_advance (parser ); // Advance past the cast
487510 int line = p_current (parser ).line ;
488511 int col = p_current (parser ).col ;
512+
513+ p_advance (parser ); // Advance past 'cast'
489514
490515 p_consume (parser , TOK_LT ,
491- "Expected a '<' before you declare the type you want to cast too." );
516+ "Expected a '<' before you declare the type you want to cast to." );
517+
492518 Type * cast_type = parse_type (parser );
493- p_advance (parser );
519+ // parse_type() has already advanced past the type
520+
494521 p_consume (parser , TOK_GT ,
495- "Expected a '>' after defining the type you want to cast too , but "
522+ "Expected a '>' after defining the type you want to cast to , but "
496523 "before defining what you are casting" );
524+
497525 p_consume (parser , TOK_LPAREN ,
498526 "Expected a '(' before defining what you are casting" );
527+
499528 Expr * castee = parse_expr (parser , BP_NONE );
529+
500530 p_consume (parser , TOK_RPAREN ,
501531 "Expected a ')' after defining what you are casting" );
502532
@@ -505,22 +535,27 @@ Expr *cast_expr(Parser *parser) {
505535
506536// input<TYPE>(msg);
507537Expr * input_expr (Parser * parser ) {
508- p_advance (parser ); // Advance past the cast
509538 int line = p_current (parser ).line ;
510539 int col = p_current (parser ).col ;
540+
541+ p_advance (parser ); // Advance past 'input'
511542
512543 p_consume (parser , TOK_LT ,
513- "Expected a '<' before you declare the type you want to cast too." );
544+ "Expected a '<' before you declare the type you want to input." );
545+
514546 Type * type = parse_type (parser );
515- p_advance (parser );
547+ // parse_type() has already advanced past the type
548+
516549 p_consume (parser , TOK_GT ,
517- "Expected a '>' after defining the type you want to cast too, but "
518- "before defining what you are casting" );
550+ "Expected a '>' after defining the type you want to input" );
551+
519552 p_consume (parser , TOK_LPAREN ,
520- "Expected a '(' before defining what you are casting" );
553+ "Expected a '(' before defining the input message" );
554+
521555 Expr * msg = parse_expr (parser , BP_NONE );
556+
522557 p_consume (parser , TOK_RPAREN ,
523- "Expected a ')' after defining what you are casting " );
558+ "Expected a ')' after defining the input message " );
524559
525560 return create_input_expr (parser -> arena , type , msg , line , col );
526561}
@@ -585,23 +620,30 @@ Expr *syscall_expr(Parser *parser) {
585620// sizeof<[n]int> Runtime when n is variable
586621// sizeof<MyStruct> Compile-time constant
587622Expr * sizeof_expr (Parser * parser ) {
588- p_advance (parser ); // Advance past the sizeof
589623 int line = p_current (parser ).line ;
590624 int col = p_current (parser ).col ;
591- AstNode * object = NULL ;
592- bool is_type = false;
593-
625+
626+ p_advance ( parser ); // Advance past 'sizeof'
627+
594628 p_consume (parser , TOK_LT ,
595629 "Expected a '<' before defining the var or type you want to get "
596630 "the size of." );
597- if (parse_type (parser ) != NULL ) {
598- ;
599- object = parse_type (parser );
600- p_advance (parser );
631+
632+ AstNode * object = NULL ;
633+ bool is_type = false;
634+
635+ // Try to parse as a type first
636+ Type * type_result = parse_type (parser );
637+ if (type_result != NULL ) {
638+ object = (AstNode * )type_result ;
601639 is_type = true;
640+ // parse_type() has already advanced past the type
602641 } else {
603- object = parse_expr (parser , BP_NONE );
642+ // Not a type, parse as an expression
643+ object = (AstNode * )parse_expr (parser , BP_NONE );
644+ is_type = false;
604645 }
646+
605647 p_consume (parser , TOK_GT ,
606648 "Expected a '>' after defining the var or type you want to get the "
607649 "size of." );
0 commit comments