From 71c8a3456e643367f27f1ada3028c07e8b38549f Mon Sep 17 00:00:00 2001 From: gingerBill Date: Wed, 27 Nov 2019 15:23:54 +0000 Subject: [PATCH] Update package odin/parser for #soa and #vector --- core/odin/ast/ast.odin | 2 ++ core/odin/parser/parser.odin | 17 ++++++++++++++++- src/parser.cpp | 7 ++++--- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/odin/ast/ast.odin b/core/odin/ast/ast.odin index 52845ea4e..afc92e345 100644 --- a/core/odin/ast/ast.odin +++ b/core/odin/ast/ast.odin @@ -554,6 +554,7 @@ Pointer_Type :: struct { Array_Type :: struct { using node: Expr, open: tokenizer.Pos, + tag: ^Expr, len: ^Expr, // Ellipsis node for [?]T arrray types, nil for slice types close: tokenizer.Pos, elem: ^Expr, @@ -561,6 +562,7 @@ Array_Type :: struct { Dynamic_Array_Type :: struct { using node: Expr, + tag: ^Expr, open: tokenizer.Pos, dynamic_pos: tokenizer.Pos, close: tokenizer.Pos, diff --git a/core/odin/parser/parser.odin b/core/odin/parser/parser.odin index 7da4a0b44..a233db068 100644 --- a/core/odin/parser/parser.odin +++ b/core/odin/parser/parser.odin @@ -1916,6 +1916,21 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr { bd.tok = tok; bd.name = name.text; return parse_call_expr(p, bd); + + + case "soa", "vector": + bd := ast.new(ast.Basic_Directive, tok.pos, end_pos(name)); + bd.tok = tok; + bd.name = name.text; + original_type := parse_type(p); + type := ast.unparen_expr(original_type); + switch t in &type.derived { + case ast.Array_Type: t.tag = bd; + case ast.Dynamic_Array_Type: t.tag = bd; + case: + error(p, original_type.pos, "expected an array type after #%s"); + } + return original_type; case: expr := parse_expr(p, lhs); te := ast.new(ast.Tag_Expr, tok.pos, expr.pos); @@ -2394,7 +2409,7 @@ parse_value :: proc(p: ^Parser) -> ^ast.Expr { if p.curr_tok.kind == .Open_Brace { return parse_literal_value(p, nil); } - prev_allow_range = p.allow_range; + prev_allow_range := p.allow_range; defer p.allow_range = prev_allow_range; p.allow_range = true; return parse_expr(p, false); diff --git a/src/parser.cpp b/src/parser.cpp index 732c366ee..cfa6d7981 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -1760,15 +1760,16 @@ Ast *parse_operand(AstFile *f, bool lhs) { return parse_call_expr(f, tag); } else if (name.string == "soa" || name.string == "vector") { Ast *tag = ast_basic_directive(f, token, name.string); - Ast *type = parse_type(f); + Ast *original_type = parse_type(f); + Ast *type = unparen_expr(original_type); switch (type->kind) { case Ast_ArrayType: type->ArrayType.tag = tag; break; case Ast_DynamicArrayType: type->DynamicArrayType.tag = tag; break; - default: + default: syntax_error(type, "Expected an array type after #%.*s, got %.*s", LIT(name.string), LIT(ast_strings[type->kind])); break; } - return type; + return original_type; } else { operand = ast_tag_expr(f, token, name, parse_expr(f, false)); }