authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-10 01:18:31-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-10 01:18:31-04:00
log0a95b0f1ffeb8ae5ee317b02626890adebe5ec63
treeb81af85f0e9ba611aa24ae8b1c855095f5c8f9e8
parent77678b2cbc7ac9ba2d5d4725241f6a9f7ac64fa4

std.zig: update syntax for orelse keyword


4 files changed, 9 insertions(+), 38 deletions(-)

src/ir.cpp-16
......@@ -14842,22 +14842,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1484214842 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
1484314843 if (type_is_invalid(type_entry)) {
1484414844 return ira->codegen->builtin_types.entry_invalid;
14845 } else if (type_entry->id == TypeTableEntryIdMetaType) {
14846 // surprise! actually this is just ??T not an unwrap maybe instruction
14847 ConstExprValue *ptr_val = const_ptr_pointee(ira->codegen, &value->value);
14848 assert(ptr_val->type->id == TypeTableEntryIdMetaType);
14849 TypeTableEntry *child_type = ptr_val->data.x_type;
14850
14851 type_ensure_zero_bits_known(ira->codegen, child_type);
14852 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);
14853 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);
14854
14855 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,
14856 unwrap_maybe_instruction->base.source_node, layer2);
14857 IrInstruction *result_instr = ir_get_ref(ira, &unwrap_maybe_instruction->base, const_instr,
14858 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
14859 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
14860 return result_instr->value.type;
1486114845 } else if (type_entry->id != TypeTableEntryIdOptional) {
1486214846 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
1486314847 buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
std/zig/parse.zig+1-1
......@@ -3248,7 +3248,7 @@ fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
32483248fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
32493249 return switch (id) {
32503250 Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null },
3251 Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op{ .UnwrapOptional = void{} },
3251 Token.Id.Keyword_orelse => ast.Node.InfixOp.Op{ .UnwrapOptional = void{} },
32523252 else => null,
32533253 };
32543254}
std/zig/parser_test.zig+1-1
......@@ -1151,7 +1151,7 @@ test "zig fmt: infix operators" {
11511151 \\ _ = i!i;
11521152 \\ _ = i ** i;
11531153 \\ _ = i ++ i;
1154 \\ _ = i ?? i;
1154 \\ _ = i orelse i;
11551155 \\ _ = i % i;
11561156 \\ _ = i / i;
11571157 \\ _ = i *% i;
std/zig/tokenizer.zig+7-20
......@@ -39,6 +39,7 @@ pub const Token = struct {
3939 Keyword{ .bytes = "noalias", .id = Id.Keyword_noalias },
4040 Keyword{ .bytes = "null", .id = Id.Keyword_null },
4141 Keyword{ .bytes = "or", .id = Id.Keyword_or },
42 Keyword{ .bytes = "orelse", .id = Id.Keyword_orelse },
4243 Keyword{ .bytes = "packed", .id = Id.Keyword_packed },
4344 Keyword{ .bytes = "promise", .id = Id.Keyword_promise },
4445 Keyword{ .bytes = "pub", .id = Id.Keyword_pub },
......@@ -129,7 +130,6 @@ pub const Token = struct {
129130 Ampersand,
130131 AmpersandEqual,
131132 QuestionMark,
132 QuestionMarkQuestionMark,
133133 AngleBracketLeft,
134134 AngleBracketLeftEqual,
135135 AngleBracketAngleBracketLeft,
......@@ -171,6 +171,7 @@ pub const Token = struct {
171171 Keyword_noalias,
172172 Keyword_null,
173173 Keyword_or,
174 Keyword_orelse,
174175 Keyword_packed,
175176 Keyword_promise,
176177 Keyword_pub,
......@@ -254,7 +255,6 @@ pub const Tokenizer = struct {
254255 Ampersand,
255256 Caret,
256257 Percent,
257 QuestionMark,
258258 Plus,
259259 PlusPercent,
260260 AngleBracketLeft,
......@@ -345,6 +345,11 @@ pub const Tokenizer = struct {
345345 self.index += 1;
346346 break;
347347 },
348 '?' => {
349 result.id = Token.Id.QuestionMark;
350 self.index += 1;
351 break;
352 },
348353 ':' => {
349354 result.id = Token.Id.Colon;
350355 self.index += 1;
......@@ -359,9 +364,6 @@ pub const Tokenizer = struct {
359364 '+' => {
360365 state = State.Plus;
361366 },
362 '?' => {
363 state = State.QuestionMark;
364 },
365367 '<' => {
366368 state = State.AngleBracketLeft;
367369 },
......@@ -496,18 +498,6 @@ pub const Tokenizer = struct {
496498 },
497499 },
498500
499 State.QuestionMark => switch (c) {
500 '?' => {
501 result.id = Token.Id.QuestionMarkQuestionMark;
502 self.index += 1;
503 break;
504 },
505 else => {
506 result.id = Token.Id.QuestionMark;
507 break;
508 },
509 },
510
511501 State.Percent => switch (c) {
512502 '=' => {
513503 result.id = Token.Id.PercentEqual;
......@@ -1084,9 +1074,6 @@ pub const Tokenizer = struct {
10841074 State.Plus => {
10851075 result.id = Token.Id.Plus;
10861076 },
1087 State.QuestionMark => {
1088 result.id = Token.Id.QuestionMark;
1089 },
10901077 State.Percent => {
10911078 result.id = Token.Id.Percent;
10921079 },