Skip to content

Commit

Permalink
std.zig: update syntax for orelse keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewrk committed Jun 10, 2018
1 parent 77678b2 commit 0a95b0f
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 38 deletions.
16 changes: 0 additions & 16 deletions src/ir.cpp
Expand Up @@ -14842,22 +14842,6 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
if (type_is_invalid(type_entry)) {
return ira->codegen->builtin_types.entry_invalid;
} else if (type_entry->id == TypeTableEntryIdMetaType) {
// surprise! actually this is just ??T not an unwrap maybe instruction
ConstExprValue *ptr_val = const_ptr_pointee(ira->codegen, &value->value);
assert(ptr_val->type->id == TypeTableEntryIdMetaType);
TypeTableEntry *child_type = ptr_val->data.x_type;

type_ensure_zero_bits_known(ira->codegen, child_type);
TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);
TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);

IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,
unwrap_maybe_instruction->base.source_node, layer2);
IrInstruction *result_instr = ir_get_ref(ira, &unwrap_maybe_instruction->base, const_instr,
ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
return result_instr->value.type;
} else if (type_entry->id != TypeTableEntryIdOptional) {
ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
buf_sprintf("expected optional type, found '%s'", buf_ptr(&type_entry->name)));
Expand Down
2 changes: 1 addition & 1 deletion std/zig/parse.zig
Expand Up @@ -3248,7 +3248,7 @@ fn tokenIdToAssignment(id: *const Token.Id) ?ast.Node.InfixOp.Op {
fn tokenIdToUnwrapExpr(id: @TagType(Token.Id)) ?ast.Node.InfixOp.Op {
return switch (id) {
Token.Id.Keyword_catch => ast.Node.InfixOp.Op{ .Catch = null },
Token.Id.QuestionMarkQuestionMark => ast.Node.InfixOp.Op{ .UnwrapOptional = void{} },
Token.Id.Keyword_orelse => ast.Node.InfixOp.Op{ .UnwrapOptional = void{} },
else => null,
};
}
Expand Down
2 changes: 1 addition & 1 deletion std/zig/parser_test.zig
Expand Up @@ -1151,7 +1151,7 @@ test "zig fmt: infix operators" {
\\ _ = i!i;
\\ _ = i ** i;
\\ _ = i ++ i;
\\ _ = i ?? i;
\\ _ = i orelse i;
\\ _ = i % i;
\\ _ = i / i;
\\ _ = i *% i;
Expand Down
27 changes: 7 additions & 20 deletions std/zig/tokenizer.zig
Expand Up @@ -39,6 +39,7 @@ pub const Token = struct {
Keyword{ .bytes = "noalias", .id = Id.Keyword_noalias },
Keyword{ .bytes = "null", .id = Id.Keyword_null },
Keyword{ .bytes = "or", .id = Id.Keyword_or },
Keyword{ .bytes = "orelse", .id = Id.Keyword_orelse },
Keyword{ .bytes = "packed", .id = Id.Keyword_packed },
Keyword{ .bytes = "promise", .id = Id.Keyword_promise },
Keyword{ .bytes = "pub", .id = Id.Keyword_pub },
Expand Down Expand Up @@ -129,7 +130,6 @@ pub const Token = struct {
Ampersand,
AmpersandEqual,
QuestionMark,
QuestionMarkQuestionMark,
AngleBracketLeft,
AngleBracketLeftEqual,
AngleBracketAngleBracketLeft,
Expand Down Expand Up @@ -171,6 +171,7 @@ pub const Token = struct {
Keyword_noalias,
Keyword_null,
Keyword_or,
Keyword_orelse,
Keyword_packed,
Keyword_promise,
Keyword_pub,
Expand Down Expand Up @@ -254,7 +255,6 @@ pub const Tokenizer = struct {
Ampersand,
Caret,
Percent,
QuestionMark,
Plus,
PlusPercent,
AngleBracketLeft,
Expand Down Expand Up @@ -345,6 +345,11 @@ pub const Tokenizer = struct {
self.index += 1;
break;
},
'?' => {
result.id = Token.Id.QuestionMark;
self.index += 1;
break;
},
':' => {
result.id = Token.Id.Colon;
self.index += 1;
Expand All @@ -359,9 +364,6 @@ pub const Tokenizer = struct {
'+' => {
state = State.Plus;
},
'?' => {
state = State.QuestionMark;
},
'<' => {
state = State.AngleBracketLeft;
},
Expand Down Expand Up @@ -496,18 +498,6 @@ pub const Tokenizer = struct {
},
},

State.QuestionMark => switch (c) {
'?' => {
result.id = Token.Id.QuestionMarkQuestionMark;
self.index += 1;
break;
},
else => {
result.id = Token.Id.QuestionMark;
break;
},
},

State.Percent => switch (c) {
'=' => {
result.id = Token.Id.PercentEqual;
Expand Down Expand Up @@ -1084,9 +1074,6 @@ pub const Tokenizer = struct {
State.Plus => {
result.id = Token.Id.Plus;
},
State.QuestionMark => {
result.id = Token.Id.QuestionMark;
},
State.Percent => {
result.id = Token.Id.Percent;
},
Expand Down

0 comments on commit 0a95b0f

Please sign in to comment.