diff options
| author | gingerBill <bill@gingerbill.org> | 2022-02-05 13:09:16 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2022-02-05 13:09:16 +0000 |
| commit | 6418ec3b21de26bac4b291a2ad8e58c011c21c38 (patch) | |
| tree | 2646d5bec1b045a9fae5d1fc08f2f4bedf28993e /src/parser.cpp | |
| parent | 2bcc7b00641a0a0a8d7bca3f207082504a85fc0a (diff) | |
Correct `#sparse` usage and error messages
Diffstat (limited to 'src/parser.cpp')
| -rw-r--r-- | src/parser.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp index 7302b18a9..0914c77ca 100644 --- a/src/parser.cpp +++ b/src/parser.cpp @@ -2134,6 +2134,22 @@ Ast *parse_operand(AstFile *f, bool lhs) { break; } return original_type; + } else if (name.string == "partial") { + Ast *tag = ast_basic_directive(f, token, name); + Ast *original_expr = parse_expr(f, lhs); + Ast *expr = unparen_expr(original_expr); + switch (expr->kind) { + case Ast_ArrayType: + syntax_error(expr, "#partial has been replaced with #sparse for non-contiguous enumerated array types"); + break; + case Ast_CompoundLit: + expr->CompoundLit.tag = tag; + break; + default: + syntax_error(expr, "Expected a compound literal after #%.*s, got %.*s", LIT(name.string), LIT(ast_strings[expr->kind])); + break; + } + return original_expr; } else if (name.string == "sparse") { Ast *tag = ast_basic_directive(f, token, name); Ast *original_type = parse_type(f); |