mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 15:18:49 +00:00
Update package odin/parser for #soa and #vector
This commit is contained in:
@@ -554,6 +554,7 @@ Pointer_Type :: struct {
|
|||||||
Array_Type :: struct {
|
Array_Type :: struct {
|
||||||
using node: Expr,
|
using node: Expr,
|
||||||
open: tokenizer.Pos,
|
open: tokenizer.Pos,
|
||||||
|
tag: ^Expr,
|
||||||
len: ^Expr, // Ellipsis node for [?]T arrray types, nil for slice types
|
len: ^Expr, // Ellipsis node for [?]T arrray types, nil for slice types
|
||||||
close: tokenizer.Pos,
|
close: tokenizer.Pos,
|
||||||
elem: ^Expr,
|
elem: ^Expr,
|
||||||
@@ -561,6 +562,7 @@ Array_Type :: struct {
|
|||||||
|
|
||||||
Dynamic_Array_Type :: struct {
|
Dynamic_Array_Type :: struct {
|
||||||
using node: Expr,
|
using node: Expr,
|
||||||
|
tag: ^Expr,
|
||||||
open: tokenizer.Pos,
|
open: tokenizer.Pos,
|
||||||
dynamic_pos: tokenizer.Pos,
|
dynamic_pos: tokenizer.Pos,
|
||||||
close: tokenizer.Pos,
|
close: tokenizer.Pos,
|
||||||
|
|||||||
@@ -1916,6 +1916,21 @@ parse_operand :: proc(p: ^Parser, lhs: bool) -> ^ast.Expr {
|
|||||||
bd.tok = tok;
|
bd.tok = tok;
|
||||||
bd.name = name.text;
|
bd.name = name.text;
|
||||||
return parse_call_expr(p, bd);
|
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:
|
case:
|
||||||
expr := parse_expr(p, lhs);
|
expr := parse_expr(p, lhs);
|
||||||
te := ast.new(ast.Tag_Expr, tok.pos, expr.pos);
|
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 {
|
if p.curr_tok.kind == .Open_Brace {
|
||||||
return parse_literal_value(p, nil);
|
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;
|
defer p.allow_range = prev_allow_range;
|
||||||
p.allow_range = true;
|
p.allow_range = true;
|
||||||
return parse_expr(p, false);
|
return parse_expr(p, false);
|
||||||
|
|||||||
+4
-3
@@ -1760,15 +1760,16 @@ Ast *parse_operand(AstFile *f, bool lhs) {
|
|||||||
return parse_call_expr(f, tag);
|
return parse_call_expr(f, tag);
|
||||||
} else if (name.string == "soa" || name.string == "vector") {
|
} else if (name.string == "soa" || name.string == "vector") {
|
||||||
Ast *tag = ast_basic_directive(f, token, name.string);
|
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) {
|
switch (type->kind) {
|
||||||
case Ast_ArrayType: type->ArrayType.tag = tag; break;
|
case Ast_ArrayType: type->ArrayType.tag = tag; break;
|
||||||
case Ast_DynamicArrayType: type->DynamicArrayType.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]));
|
syntax_error(type, "Expected an array type after #%.*s, got %.*s", LIT(name.string), LIT(ast_strings[type->kind]));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return type;
|
return original_type;
|
||||||
} else {
|
} else {
|
||||||
operand = ast_tag_expr(f, token, name, parse_expr(f, false));
|
operand = ast_tag_expr(f, token, name, parse_expr(f, false));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user