authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-07 17:28:20-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-07 17:28:20-05:00
log632d143bff3611be8a48d8c9c9dc9d56e759eb15
treeb3166a1487a80942b1a489c745996a4f1f931de6
parent66717db735b9ddac9298bf08fcf95e7e11629fee

replace `a %% b` with `a catch b`

See #632 better fits the convention of using keywords for control flow

32 files changed, 173 insertions(+), 170 deletions(-)

doc/docgen.zig+1-1
......@@ -45,7 +45,7 @@ const State = enum {
4545fn gen(in: &io.InStream, out: &io.OutStream) {
4646 var state = State.Start;
4747 while (true) {
48 const byte = in.readByte() %% |err| {
48 const byte = in.readByte() catch |err| {
4949 if (err == error.EndOfStream) {
5050 return;
5151 }
doc/home.html.in+6-6
......@@ -142,7 +142,7 @@ pub fn addOverflow(comptime T: type, a: T, b: T) -&gt; %T {
142142}
143143
144144fn getNumberWithDefault(s: []u8) -&gt; u32 {
145 parseUnsigned(u32, s, 10) %% 42
145 parseUnsigned(u32, s, 10) catch 42
146146}
147147
148148fn getNumberOrCrash(s: []u8) -&gt; u32 {
......@@ -150,8 +150,8 @@ fn getNumberOrCrash(s: []u8) -&gt; u32 {
150150}
151151
152152fn addTwoTogetherOrReturnErr(a_str: []u8, b_str: []u8) -&gt; %u32 {
153 const a = parseUnsigned(u32, a_str, 10) %% |err| return err;
154 const b = parseUnsigned(u32, b_str, 10) %% |err| return err;
153 const a = parseUnsigned(u32, a_str, 10) catch |err| return err;
154 const b = parseUnsigned(u32, b_str, 10) catch |err| return err;
155155 return a + b;
156156}</code></pre>
157157 <h3 id="hashmap">HashMap with Custom Allocator</h3>
......@@ -424,7 +424,7 @@ pub fn main() -&gt; %void {
424424 } else if (arg[0] == '-') {
425425 return usage(exe);
426426 } else {
427 var is = io.InStream.open(arg, null) %% |err| {
427 var is = io.InStream.open(arg, null) catch |err| {
428428 %%io.stderr.printf("Unable to open file: {}\n", @errorName(err));
429429 return err;
430430 };
......@@ -449,7 +449,7 @@ fn cat_stream(is: &amp;io.InStream) -&gt; %void {
449449 var buf: [1024 * 4]u8 = undefined;
450450
451451 while (true) {
452 const bytes_read = is.read(buf[0..]) %% |err| {
452 const bytes_read = is.read(buf[0..]) catch |err| {
453453 %%io.stderr.printf("Unable to read from stream: {}\n", @errorName(err));
454454 return err;
455455 };
......@@ -458,7 +458,7 @@ fn cat_stream(is: &amp;io.InStream) -&gt; %void {
458458 break;
459459 }
460460
461 io.stdout.write(buf[0..bytes_read]) %% |err| {
461 io.stdout.write(buf[0..bytes_read]) catch |err| {
462462 %%io.stderr.printf("Unable to write to stdout: {}\n", @errorName(err));
463463 return err;
464464 };
doc/langref.html.in+15-15
......@@ -1211,8 +1211,8 @@ unwrapped == 1234</code></pre>
12111211 </td>
12121212 </tr>
12131213 <tr>
1214 <td><pre><code class="zig">a %% b
1215a %% |err| b</code></pre></td>
1214 <td><pre><code class="zig">a catch b
1215a catch |err| b</code></pre></td>
12161216 <td>
12171217 <ul>
12181218 <li><a href="#errors">Error Unions</a></li>
......@@ -1226,7 +1226,7 @@ a %% |err| b</code></pre></td>
12261226 </td>
12271227 <td>
12281228 <pre><code class="zig">const value: %u32 = null;
1229const unwrapped = value %% 1234;
1229const unwrapped = value catch 1234;
12301230unwrapped == 1234</code></pre>
12311231 </td>
12321232 </tr>
......@@ -1238,7 +1238,7 @@ unwrapped == 1234</code></pre>
12381238 </ul>
12391239 </td>
12401240 <td>Equivalent to:
1241 <pre><code class="zig">a %% unreachable</code></pre>
1241 <pre><code class="zig">a catch unreachable</code></pre>
12421242 </td>
12431243 <td>
12441244 <pre><code class="zig">const value: %u32 = 5678;
......@@ -1482,7 +1482,7 @@ x{}
14821482== != &lt; &gt; &lt;= &gt;=
14831483and
14841484or
1485?? %%
1485?? catch
14861486= *= /= %= += -= &lt;&lt;= &gt;&gt;= &amp;= ^= |=</code></pre>
14871487 <h2 id="arrays">Arrays</h2>
14881488 <pre><code class="zig">const assert = @import("std").debug.assert;
......@@ -1829,7 +1829,7 @@ Test 1/1 pointer alignment safety...incorrect alignment
18291829 return root.main();
18301830 ^
18311831/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:47:13: 0x0000000000216050 in ??? (test)
1832 callMain(argc, argv, envp) %% std.os.posix.exit(1);
1832 callMain(argc, argv, envp) catch std.os.posix.exit(1);
18331833 ^
18341834/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:34:25: 0x0000000000215fa0 in ??? (test)
18351835 posixCallMainAndExit()
......@@ -1885,7 +1885,7 @@ lib/zig/std/special/bootstrap.zig:60:21: 0x00000000002149e7 in ??? (test)
18851885 return root.main();
18861886 ^
18871887lib/zig/std/special/bootstrap.zig:47:13: 0x00000000002148a0 in ??? (test)
1888 callMain(argc, argv, envp) %% std.os.posix.exit(1);
1888 callMain(argc, argv, envp) catch std.os.posix.exit(1);
18891889 ^
18901890lib/zig/std/special/bootstrap.zig:34:25: 0x00000000002147f0 in ??? (test)
18911891 posixCallMainAndExit()
......@@ -2965,7 +2965,7 @@ lib/zig/std/special/bootstrap.zig:60:21: 0x0000000000214947 in ??? (test)
29652965 return root.main();
29662966 ^
29672967lib/zig/std/special/bootstrap.zig:47:13: 0x0000000000214800 in ??? (test)
2968 callMain(argc, argv, envp) %% std.os.posix.exit(1);
2968 callMain(argc, argv, envp) catch std.os.posix.exit(1);
29692969 ^
29702970lib/zig/std/special/bootstrap.zig:34:25: 0x0000000000214750 in ??? (test)
29712971 posixCallMainAndExit()
......@@ -3019,7 +3019,7 @@ extern fn bar(value: u32);</code></pre>
30193019 <pre><code class="zig">pub extern "kernel32" stdcallcc fn ExitProcess(exit_code: c_uint) -&gt; noreturn;
30203020
30213021fn foo() {
3022 const value = bar() %% ExitProcess(1);
3022 const value = bar() catch ExitProcess(1);
30233023 assert(value == 1234);
30243024}
30253025
......@@ -3209,7 +3209,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 {
32093209 </ul>
32103210 <p>If you want to provide a default value, you can use the <code>%%</code> binary operator:</p>
32113211 <pre><code class="zig">fn doAThing(str: []u8) {
3212 const number = parseU64(str, 10) %% 13;
3212 const number = parseU64(str, 10) catch 13;
32133213 // ...
32143214}</code></pre>
32153215 <p>
......@@ -3220,7 +3220,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 {
32203220 <p>Let's say you wanted to return the error if you got one, otherwise continue with the
32213221 function logic:</p>
32223222 <pre><code class="zig">fn doAThing(str: []u8) -&gt; %void {
3223 const number = parseU64(str, 10) %% |err| return err;
3223 const number = parseU64(str, 10) catch |err| return err;
32243224 // ...
32253225}</code></pre>
32263226 <p>
......@@ -3239,7 +3239,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 {
32393239 Maybe you know with complete certainty that an expression will never be an error.
32403240 In this case you can do this:
32413241 </p>
3242 <pre><code class="zig">const number = parseU64("1234", 10) %% unreachable;</code></pre>
3242 <pre><code class="zig">const number = parseU64("1234", 10) catch unreachable;</code></pre>
32433243 <p>
32443244 Here we know for sure that "1234" will parse successfully. So we put the
32453245 <code>unreachable</code> value on the right hand side. <code>unreachable</code> generates
......@@ -3250,7 +3250,7 @@ pub fn parseU64(buf: []const u8, radix: u8) -&gt; %u64 {
32503250 <p>Again there is a syntactic shortcut for this:</p>
32513251 <pre><code class="zig">const number = %%parseU64("1234", 10);</code></pre>
32523252 <p>
3253 The <code>%%</code> <em>prefix</em> operator is equivalent to <code class="zig">expression %% unreachable</code>. It unwraps an error union type,
3253 The <code>%%</code> <em>prefix</em> operator is equivalent to <code class="zig">expression catch unreachable</code>. It unwraps an error union type,
32543254 and panics in debug mode if the value was an error.
32553255 </p>
32563256 <p>
......@@ -4984,7 +4984,7 @@ Test 1/1 safety check...reached unreachable code
49844984 return root.main();
49854985 ^
49864986/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:37:13: 0x00000000002148d0 in ??? (test)
4987 callMain(argc, argv, envp) %% exit(1);
4987 callMain(argc, argv, envp) catch exit(1);
49884988 ^
49894989/home/andy/dev/zig/build/lib/zig/std/special/bootstrap.zig:30:20: 0x0000000000214820 in ??? (test)
49904990 callMainAndExit()
......@@ -5909,7 +5909,7 @@ UnwrapExpression = BoolOrExpression (UnwrapNullable | UnwrapError) | BoolOrExpre
59095909
59105910UnwrapNullable = "??" Expression
59115911
5912UnwrapError = "%%" option("|" Symbol "|") Expression
5912UnwrapError = "catch" option("|" Symbol "|") Expression
59135913
59145914AssignmentExpression = UnwrapExpression AssignmentOperator UnwrapExpression | UnwrapExpression
59155915
example/cat/main.zig+4-4
......@@ -20,7 +20,7 @@ pub fn main() -> %void {
2020 } else if (arg[0] == '-') {
2121 return usage(exe);
2222 } else {
23 var file = io.File.openRead(arg, null) %% |err| {
23 var file = io.File.openRead(arg, null) catch |err| {
2424 warn("Unable to open file: {}\n", @errorName(err));
2525 return err;
2626 };
......@@ -45,7 +45,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void {
4545 var buf: [1024 * 4]u8 = undefined;
4646
4747 while (true) {
48 const bytes_read = file.read(buf[0..]) %% |err| {
48 const bytes_read = file.read(buf[0..]) catch |err| {
4949 warn("Unable to read from stream: {}\n", @errorName(err));
5050 return err;
5151 };
......@@ -54,7 +54,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void {
5454 break;
5555 }
5656
57 stdout.write(buf[0..bytes_read]) %% |err| {
57 stdout.write(buf[0..bytes_read]) catch |err| {
5858 warn("Unable to write to stdout: {}\n", @errorName(err));
5959 return err;
6060 };
......@@ -62,7 +62,7 @@ fn cat_file(stdout: &io.File, file: &io.File) -> %void {
6262}
6363
6464fn unwrapArg(arg: %[]u8) -> %[]u8 {
65 return arg %% |err| {
65 return arg catch |err| {
6666 warn("Unable to parse command line: {}\n", err);
6767 return err;
6868 };
example/guess_number/main.zig+2-2
......@@ -25,12 +25,12 @@ pub fn main() -> %void {
2525 try stdout.print("\nGuess a number between 1 and 100: ");
2626 var line_buf : [20]u8 = undefined;
2727
28 const line_len = stdin_file.read(line_buf[0..]) %% |err| {
28 const line_len = stdin_file.read(line_buf[0..]) catch |err| {
2929 try stdout.print("Unable to read from stdin: {}\n", @errorName(err));
3030 return err;
3131 };
3232
33 const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) %% {
33 const guess = fmt.parseUnsigned(u8, line_buf[0..line_len - 1], 10) catch {
3434 try stdout.print("Invalid number.\n");
3535 continue;
3636 };
src-self-hosted/main.zig+4-4
......@@ -21,7 +21,7 @@ error ZigInstallationNotFound;
2121const default_zig_cache_name = "zig-cache";
2222
2323pub fn main() -> %void {
24 main2() %% |err| {
24 main2() catch |err| {
2525 if (err != error.InvalidCommandLineArguments) {
2626 warn("{}\n", @errorName(err));
2727 }
......@@ -571,12 +571,12 @@ fn printZen() -> %void {
571571/// Caller must free result
572572fn resolveZigLibDir(allocator: &mem.Allocator, zig_install_prefix_arg: ?[]const u8) -> %[]u8 {
573573 if (zig_install_prefix_arg) |zig_install_prefix| {
574 return testZigInstallPrefix(allocator, zig_install_prefix) %% |err| {
574 return testZigInstallPrefix(allocator, zig_install_prefix) catch |err| {
575575 warn("No Zig installation found at prefix {}: {}\n", zig_install_prefix_arg, @errorName(err));
576576 return error.ZigInstallationNotFound;
577577 };
578578 } else {
579 return findZigLibDir(allocator) %% |err| {
579 return findZigLibDir(allocator) catch |err| {
580580 warn("Unable to find zig lib directory: {}.\nReinstall Zig or use --zig-install-prefix.\n",
581581 @errorName(err));
582582 return error.ZigLibDirNotFound;
......@@ -611,7 +611,7 @@ fn findZigLibDir(allocator: &mem.Allocator) -> %[]u8 {
611611 break;
612612 }
613613
614 return testZigInstallPrefix(allocator, test_dir) %% |err| {
614 return testZigInstallPrefix(allocator, test_dir) catch |err| {
615615 cur_path = test_dir;
616616 continue;
617617 };
src-self-hosted/module.zig+2-2
......@@ -207,13 +207,13 @@ pub const Module = struct {
207207 }
208208
209209 const root_src_path = self.root_src_path ?? @panic("TODO handle null root src path");
210 const root_src_real_path = os.path.real(self.allocator, root_src_path) %% |err| {
210 const root_src_real_path = os.path.real(self.allocator, root_src_path) catch |err| {
211211 try printError("unable to get real path '{}': {}", root_src_path, err);
212212 return err;
213213 };
214214 %defer self.allocator.free(root_src_real_path);
215215
216 const source_code = io.readFileAllocExtra(root_src_real_path, self.allocator, 3) %% |err| {
216 const source_code = io.readFileAllocExtra(root_src_real_path, self.allocator, 3) catch |err| {
217217 try printError("unable to open '{}': {}", root_src_real_path, err);
218218 return err;
219219 };
src-self-hosted/parser.zig+26-26
......@@ -96,12 +96,12 @@ pub const Parser = struct {
9696 var stack = self.initUtilityArrayList(&ast.Node);
9797 defer self.deinitUtilityArrayList(stack);
9898
99 stack.append(&root_node.base) %% unreachable;
99 stack.append(&root_node.base) catch unreachable;
100100 while (stack.popOrNull()) |node| {
101101 var i: usize = 0;
102102 while (node.iterate(i)) |child| : (i += 1) {
103103 if (child.iterate(0) != null) {
104 stack.append(child) %% unreachable;
104 stack.append(child) catch unreachable;
105105 } else {
106106 child.destroy(self.allocator);
107107 }
......@@ -111,7 +111,7 @@ pub const Parser = struct {
111111 }
112112
113113 pub fn parse(self: &Parser) -> %&ast.NodeRoot {
114 const result = self.parseInner() %% |err| x: {
114 const result = self.parseInner() catch |err| x: {
115115 if (self.cleanup_root_node) |root_node| {
116116 self.freeAst(root_node);
117117 }
......@@ -156,14 +156,14 @@ pub const Parser = struct {
156156 const token = self.getNextToken();
157157 switch (token.id) {
158158 Token.Id.Keyword_pub, Token.Id.Keyword_export => {
159 stack.append(State { .TopLevelExtern = token }) %% unreachable;
159 stack.append(State { .TopLevelExtern = token }) catch unreachable;
160160 continue;
161161 },
162162 Token.Id.Eof => return root_node,
163163 else => {
164164 self.putBackToken(token);
165165 // TODO shouldn't need this cast
166 stack.append(State { .TopLevelExtern = null }) %% unreachable;
166 stack.append(State { .TopLevelExtern = null }) catch unreachable;
167167 continue;
168168 },
169169 }
......@@ -176,7 +176,7 @@ pub const Parser = struct {
176176 .visib_token = visib_token,
177177 .extern_token = token,
178178 },
179 }) %% unreachable;
179 }) catch unreachable;
180180 continue;
181181 }
182182 self.putBackToken(token);
......@@ -185,14 +185,14 @@ pub const Parser = struct {
185185 .visib_token = visib_token,
186186 .extern_token = null,
187187 },
188 }) %% unreachable;
188 }) catch unreachable;
189189 continue;
190190 },
191191 State.TopLevelDecl => |ctx| {
192192 const token = self.getNextToken();
193193 switch (token.id) {
194194 Token.Id.Keyword_var, Token.Id.Keyword_const => {
195 stack.append(State.TopLevel) %% unreachable;
195 stack.append(State.TopLevel) catch unreachable;
196196 // TODO shouldn't need these casts
197197 const var_decl_node = try self.createAttachVarDecl(&root_node.decls, ctx.visib_token,
198198 token, (?Token)(null), ctx.extern_token);
......@@ -200,7 +200,7 @@ pub const Parser = struct {
200200 continue;
201201 },
202202 Token.Id.Keyword_fn => {
203 stack.append(State.TopLevel) %% unreachable;
203 stack.append(State.TopLevel) catch unreachable;
204204 // TODO shouldn't need these casts
205205 const fn_proto = try self.createAttachFnProto(&root_node.decls, token,
206206 ctx.extern_token, (?Token)(null), (?Token)(null), (?Token)(null));
......@@ -212,7 +212,7 @@ pub const Parser = struct {
212212 @panic("TODO extern with string literal");
213213 },
214214 Token.Id.Keyword_coldcc, Token.Id.Keyword_nakedcc, Token.Id.Keyword_stdcallcc => {
215 stack.append(State.TopLevel) %% unreachable;
215 stack.append(State.TopLevel) catch unreachable;
216216 const fn_token = try self.eatToken(Token.Id.Keyword_fn);
217217 // TODO shouldn't need this cast
218218 const fn_proto = try self.createAttachFnProto(&root_node.decls, fn_token,
......@@ -226,7 +226,7 @@ pub const Parser = struct {
226226 },
227227 State.VarDecl => |var_decl| {
228228 var_decl.name_token = try self.eatToken(Token.Id.Identifier);
229 stack.append(State { .VarDeclAlign = var_decl }) %% unreachable;
229 stack.append(State { .VarDeclAlign = var_decl }) catch unreachable;
230230
231231 const next_token = self.getNextToken();
232232 if (next_token.id == Token.Id.Colon) {
......@@ -238,7 +238,7 @@ pub const Parser = struct {
238238 continue;
239239 },
240240 State.VarDeclAlign => |var_decl| {
241 stack.append(State { .VarDeclEq = var_decl }) %% unreachable;
241 stack.append(State { .VarDeclEq = var_decl }) catch unreachable;
242242
243243 const next_token = self.getNextToken();
244244 if (next_token.id == Token.Id.Keyword_align) {
......@@ -255,7 +255,7 @@ pub const Parser = struct {
255255 const token = self.getNextToken();
256256 if (token.id == Token.Id.Equal) {
257257 var_decl.eq_token = token;
258 stack.append(State { .ExpectToken = Token.Id.Semicolon }) %% unreachable;
258 stack.append(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable;
259259 try stack.append(State {
260260 .Expression = DestPtr {.NullableField = &var_decl.init_node},
261261 });
......@@ -273,7 +273,7 @@ pub const Parser = struct {
273273
274274 State.Expression => |dest_ptr| {
275275 // save the dest_ptr for later
276 stack.append(state) %% unreachable;
276 stack.append(state) catch unreachable;
277277 try stack.append(State.ExpectOperand);
278278 continue;
279279 },
......@@ -383,7 +383,7 @@ pub const Parser = struct {
383383 var token = self.getNextToken();
384384 switch (token.id) {
385385 Token.Id.Keyword_align => {
386 stack.append(state) %% unreachable;
386 stack.append(state) catch unreachable;
387387 if (addr_of_info.align_expr != null) return self.parseError(token, "multiple align qualifiers");
388388 _ = try self.eatToken(Token.Id.LParen);
389389 try stack.append(State { .ExpectToken = Token.Id.RParen });
......@@ -391,13 +391,13 @@ pub const Parser = struct {
391391 continue;
392392 },
393393 Token.Id.Keyword_const => {
394 stack.append(state) %% unreachable;
394 stack.append(state) catch unreachable;
395395 if (addr_of_info.const_token != null) return self.parseError(token, "duplicate qualifier: const");
396396 addr_of_info.const_token = token;
397397 continue;
398398 },
399399 Token.Id.Keyword_volatile => {
400 stack.append(state) %% unreachable;
400 stack.append(state) catch unreachable;
401401 if (addr_of_info.volatile_token != null) return self.parseError(token, "duplicate qualifier: volatile");
402402 addr_of_info.volatile_token = token;
403403 continue;
......@@ -416,12 +416,12 @@ pub const Parser = struct {
416416 }
417417 self.putBackToken(token);
418418
419 stack.append(State { .Expression = dest_ptr }) %% unreachable;
419 stack.append(State { .Expression = dest_ptr }) catch unreachable;
420420 continue;
421421 },
422422
423423 State.FnProto => |fn_proto| {
424 stack.append(State { .FnProtoAlign = fn_proto }) %% unreachable;
424 stack.append(State { .FnProtoAlign = fn_proto }) catch unreachable;
425425 try stack.append(State { .ParamDecl = fn_proto });
426426 try stack.append(State { .ExpectToken = Token.Id.LParen });
427427
......@@ -442,7 +442,7 @@ pub const Parser = struct {
442442 if (token.id == Token.Id.Arrow) {
443443 stack.append(State {
444444 .TypeExpr = DestPtr {.NullableField = &fn_proto.return_type},
445 }) %% unreachable;
445 }) catch unreachable;
446446 continue;
447447 } else {
448448 self.putBackToken(token);
......@@ -474,13 +474,13 @@ pub const Parser = struct {
474474 }
475475 if (token.id == Token.Id.Ellipsis3) {
476476 param_decl.var_args_token = token;
477 stack.append(State { .ExpectToken = Token.Id.RParen }) %% unreachable;
477 stack.append(State { .ExpectToken = Token.Id.RParen }) catch unreachable;
478478 continue;
479479 } else {
480480 self.putBackToken(token);
481481 }
482482
483 stack.append(State { .ParamDecl = fn_proto }) %% unreachable;
483 stack.append(State { .ParamDecl = fn_proto }) catch unreachable;
484484 try stack.append(State.ParamDeclComma);
485485 try stack.append(State {
486486 .TypeExpr = DestPtr {.Field = &param_decl.type_node}
......@@ -506,7 +506,7 @@ pub const Parser = struct {
506506 Token.Id.LBrace => {
507507 const block = try self.createBlock(token);
508508 fn_proto.body_node = &block.base;
509 stack.append(State { .Block = block }) %% unreachable;
509 stack.append(State { .Block = block }) catch unreachable;
510510 continue;
511511 },
512512 Token.Id.Semicolon => continue,
......@@ -523,7 +523,7 @@ pub const Parser = struct {
523523 },
524524 else => {
525525 self.putBackToken(token);
526 stack.append(State { .Block = block }) %% unreachable;
526 stack.append(State { .Block = block }) catch unreachable;
527527 try stack.append(State { .Statement = block });
528528 continue;
529529 },
......@@ -560,7 +560,7 @@ pub const Parser = struct {
560560 self.putBackToken(mut_token);
561561 }
562562
563 stack.append(State { .ExpectToken = Token.Id.Semicolon }) %% unreachable;
563 stack.append(State { .ExpectToken = Token.Id.Semicolon }) catch unreachable;
564564 try stack.append(State { .Expression = DestPtr{.List = &block.statements} });
565565 continue;
566566 },
......@@ -1112,7 +1112,7 @@ fn testCanonical(source: []const u8) {
11121112 // Try it once with unlimited memory, make sure it works
11131113 var fixed_allocator = mem.FixedBufferAllocator.init(fixed_buffer_mem[0..]);
11141114 var failing_allocator = std.debug.FailingAllocator.init(&fixed_allocator.allocator, @maxValue(usize));
1115 const result_source = testParse(source, &failing_allocator.allocator) %% @panic("test failed");
1115 const result_source = testParse(source, &failing_allocator.allocator) catch @panic("test failed");
11161116 if (!mem.eql(u8, result_source, source)) {
11171117 warn("\n====== expected this output: =========\n");
11181118 warn("{}", source);
src-self-hosted/tokenizer.zig+4-4
......@@ -557,22 +557,22 @@ pub const Tokenizer = struct {
557557 return 0;
558558 } else {
559559 // check utf8-encoded character.
560 const length = std.unicode.utf8ByteSequenceLength(c0) %% return 1;
560 const length = std.unicode.utf8ByteSequenceLength(c0) catch return 1;
561561 // the last 3 bytes in the buffer are guaranteed to be '\n',
562562 // which means we don't need to do any bounds checking here.
563563 const bytes = self.buffer[self.index..self.index + length];
564564 switch (length) {
565565 2 => {
566 const value = std.unicode.utf8Decode2(bytes) %% return length;
566 const value = std.unicode.utf8Decode2(bytes) catch return length;
567567 if (value == 0x85) return length; // U+0085 (NEL)
568568 },
569569 3 => {
570 const value = std.unicode.utf8Decode3(bytes) %% return length;
570 const value = std.unicode.utf8Decode3(bytes) catch return length;
571571 if (value == 0x2028) return length; // U+2028 (LS)
572572 if (value == 0x2029) return length; // U+2029 (PS)
573573 },
574574 4 => {
575 _ = std.unicode.utf8Decode4(bytes) %% return length;
575 _ = std.unicode.utf8Decode4(bytes) catch return length;
576576 },
577577 else => unreachable,
578578 }
src/all_types.hpp+4-4
......@@ -389,7 +389,7 @@ enum NodeType {
389389 NodeTypeArrayType,
390390 NodeTypeErrorType,
391391 NodeTypeVarLiteral,
392 NodeTypeTryExpr,
392 NodeTypeIfErrorExpr,
393393 NodeTypeTestExpr,
394394};
395395
......@@ -546,7 +546,7 @@ struct AstNodeBinOpExpr {
546546 AstNode *op2;
547547};
548548
549struct AstNodeUnwrapErrorExpr {
549struct AstNodeCatchExpr {
550550 AstNode *op1;
551551 AstNode *symbol; // can be null
552552 AstNode *op2;
......@@ -860,7 +860,7 @@ struct AstNode {
860860 AstNodeErrorValueDecl error_value_decl;
861861 AstNodeTestDecl test_decl;
862862 AstNodeBinOpExpr bin_op_expr;
863 AstNodeUnwrapErrorExpr unwrap_err_expr;
863 AstNodeCatchExpr unwrap_err_expr;
864864 AstNodePrefixOpExpr prefix_op_expr;
865865 AstNodeAddrOfExpr addr_of_expr;
866866 AstNodeFnCallExpr fn_call_expr;
......@@ -868,7 +868,7 @@ struct AstNode {
868868 AstNodeSliceExpr slice_expr;
869869 AstNodeUse use;
870870 AstNodeIfBoolExpr if_bool_expr;
871 AstNodeTryExpr try_expr;
871 AstNodeTryExpr if_err_expr;
872872 AstNodeTestExpr test_expr;
873873 AstNodeWhileExpr while_expr;
874874 AstNodeForExpr for_expr;
src/analyze.cpp+1-1
......@@ -2933,7 +2933,7 @@ void scan_decls(CodeGen *g, ScopeDecls *decls_scope, AstNode *node) {
29332933 case NodeTypeArrayType:
29342934 case NodeTypeErrorType:
29352935 case NodeTypeVarLiteral:
2936 case NodeTypeTryExpr:
2936 case NodeTypeIfErrorExpr:
29372937 case NodeTypeTestExpr:
29382938 zig_unreachable();
29392939 }
src/ast_render.cpp+13-13
......@@ -68,7 +68,7 @@ static const char *prefix_op_str(PrefixOp prefix_op) {
6868 case PrefixOpDereference: return "*";
6969 case PrefixOpMaybe: return "?";
7070 case PrefixOpError: return "%";
71 case PrefixOpUnwrapError: return "%%";
71 case PrefixOpUnwrapError: return "catch";
7272 case PrefixOpUnwrapMaybe: return "??";
7373 }
7474 zig_unreachable();
......@@ -241,8 +241,8 @@ static const char *node_type_str(NodeType node_type) {
241241 return "ErrorType";
242242 case NodeTypeVarLiteral:
243243 return "VarLiteral";
244 case NodeTypeTryExpr:
245 return "TryExpr";
244 case NodeTypeIfErrorExpr:
245 return "IfErrorExpr";
246246 case NodeTypeTestExpr:
247247 return "TestExpr";
248248 }
......@@ -872,23 +872,23 @@ static void render_node_extra(AstRender *ar, AstNode *node, bool grouped) {
872872 fprintf(ar->f, "null");
873873 break;
874874 }
875 case NodeTypeTryExpr:
875 case NodeTypeIfErrorExpr:
876876 {
877877 fprintf(ar->f, "if (");
878 render_node_grouped(ar, node->data.try_expr.target_node);
878 render_node_grouped(ar, node->data.if_err_expr.target_node);
879879 fprintf(ar->f, ") ");
880 if (node->data.try_expr.var_symbol) {
881 const char *ptr_str = node->data.try_expr.var_is_ptr ? "*" : "";
882 const char *var_name = buf_ptr(node->data.try_expr.var_symbol);
880 if (node->data.if_err_expr.var_symbol) {
881 const char *ptr_str = node->data.if_err_expr.var_is_ptr ? "*" : "";
882 const char *var_name = buf_ptr(node->data.if_err_expr.var_symbol);
883883 fprintf(ar->f, "|%s%s| ", ptr_str, var_name);
884884 }
885 render_node_grouped(ar, node->data.try_expr.then_node);
886 if (node->data.try_expr.else_node) {
885 render_node_grouped(ar, node->data.if_err_expr.then_node);
886 if (node->data.if_err_expr.else_node) {
887887 fprintf(ar->f, " else ");
888 if (node->data.try_expr.err_symbol) {
889 fprintf(ar->f, "|%s| ", buf_ptr(node->data.try_expr.err_symbol));
888 if (node->data.if_err_expr.err_symbol) {
889 fprintf(ar->f, "|%s| ", buf_ptr(node->data.if_err_expr.err_symbol));
890890 }
891 render_node_grouped(ar, node->data.try_expr.else_node);
891 render_node_grouped(ar, node->data.if_err_expr.else_node);
892892 }
893893 break;
894894 }
src/ir.cpp+10-10
......@@ -4665,16 +4665,16 @@ static IrInstruction *ir_gen_test_expr(IrBuilder *irb, Scope *scope, AstNode *no
46654665 return ir_build_phi(irb, scope, node, 2, incoming_blocks, incoming_values);
46664666}
46674667
4668static IrInstruction *ir_gen_try_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
4669 assert(node->type == NodeTypeTryExpr);
4668static IrInstruction *ir_gen_if_err_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
4669 assert(node->type == NodeTypeIfErrorExpr);
46704670
4671 AstNode *target_node = node->data.try_expr.target_node;
4672 AstNode *then_node = node->data.try_expr.then_node;
4673 AstNode *else_node = node->data.try_expr.else_node;
4674 bool var_is_ptr = node->data.try_expr.var_is_ptr;
4671 AstNode *target_node = node->data.if_err_expr.target_node;
4672 AstNode *then_node = node->data.if_err_expr.then_node;
4673 AstNode *else_node = node->data.if_err_expr.else_node;
4674 bool var_is_ptr = node->data.if_err_expr.var_is_ptr;
46754675 bool var_is_const = true;
4676 Buf *var_symbol = node->data.try_expr.var_symbol;
4677 Buf *err_symbol = node->data.try_expr.err_symbol;
4676 Buf *var_symbol = node->data.if_err_expr.var_symbol;
4677 Buf *err_symbol = node->data.if_err_expr.err_symbol;
46784678
46794679 IrInstruction *err_val_ptr = ir_gen_node_extra(irb, target_node, scope, LVAL_PTR);
46804680 if (err_val_ptr == irb->codegen->invalid_instruction)
......@@ -5411,8 +5411,8 @@ static IrInstruction *ir_gen_node_raw(IrBuilder *irb, AstNode *node, Scope *scop
54115411 return ir_lval_wrap(irb, scope, ir_gen_null_literal(irb, scope, node), lval);
54125412 case NodeTypeVarLiteral:
54135413 return ir_lval_wrap(irb, scope, ir_gen_var_literal(irb, scope, node), lval);
5414 case NodeTypeTryExpr:
5415 return ir_lval_wrap(irb, scope, ir_gen_try_expr(irb, scope, node), lval);
5414 case NodeTypeIfErrorExpr:
5415 return ir_lval_wrap(irb, scope, ir_gen_if_err_expr(irb, scope, node), lval);
54165416 case NodeTypeTestExpr:
54175417 return ir_lval_wrap(irb, scope, ir_gen_test_expr(irb, scope, node), lval);
54185418 case NodeTypeSwitchExpr:
src/parser.cpp+17-17
......@@ -1407,15 +1407,15 @@ static AstNode *ast_parse_if_try_test_expr(ParseContext *pc, size_t *token_index
14071407 }
14081408
14091409 if (err_name_tok != nullptr) {
1410 AstNode *node = ast_create_node(pc, NodeTypeTryExpr, if_token);
1411 node->data.try_expr.target_node = condition;
1412 node->data.try_expr.var_is_ptr = var_is_ptr;
1410 AstNode *node = ast_create_node(pc, NodeTypeIfErrorExpr, if_token);
1411 node->data.if_err_expr.target_node = condition;
1412 node->data.if_err_expr.var_is_ptr = var_is_ptr;
14131413 if (var_name_tok != nullptr) {
1414 node->data.try_expr.var_symbol = token_buf(var_name_tok);
1414 node->data.if_err_expr.var_symbol = token_buf(var_name_tok);
14151415 }
1416 node->data.try_expr.then_node = body_node;
1417 node->data.try_expr.err_symbol = token_buf(err_name_tok);
1418 node->data.try_expr.else_node = else_node;
1416 node->data.if_err_expr.then_node = body_node;
1417 node->data.if_err_expr.err_symbol = token_buf(err_name_tok);
1418 node->data.if_err_expr.else_node = else_node;
14191419 return node;
14201420 } else if (var_name_tok != nullptr) {
14211421 AstNode *node = ast_create_node(pc, NodeTypeTestExpr, if_token);
......@@ -2041,7 +2041,7 @@ static BinOpType ast_parse_ass_op(ParseContext *pc, size_t *token_index, bool ma
20412041/*
20422042UnwrapExpression : BoolOrExpression (UnwrapMaybe | UnwrapError) | BoolOrExpression
20432043UnwrapMaybe : "??" BoolOrExpression
2044UnwrapError : "%%" option("|" "Symbol" "|") BoolOrExpression
2044UnwrapError = "catch" option("|" Symbol "|") Expression
20452045*/
20462046static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, bool mandatory) {
20472047 AstNode *lhs = ast_parse_bool_or_expr(pc, token_index, mandatory);
......@@ -2061,7 +2061,7 @@ static AstNode *ast_parse_unwrap_expr(ParseContext *pc, size_t *token_index, boo
20612061 node->data.bin_op_expr.op2 = rhs;
20622062
20632063 return node;
2064 } else if (token->id == TokenIdPercentPercent) {
2064 } else if (token->id == TokenIdKeywordCatch) {
20652065 *token_index += 1;
20662066
20672067 AstNode *node = ast_create_node(pc, NodeTypeUnwrapErrorExpr, token);
......@@ -2157,10 +2157,10 @@ static bool statement_terminates_without_semicolon(AstNode *node) {
21572157 if (node->data.if_bool_expr.else_node)
21582158 return statement_terminates_without_semicolon(node->data.if_bool_expr.else_node);
21592159 return node->data.if_bool_expr.then_block->type == NodeTypeBlock;
2160 case NodeTypeTryExpr:
2161 if (node->data.try_expr.else_node)
2162 return statement_terminates_without_semicolon(node->data.try_expr.else_node);
2163 return node->data.try_expr.then_node->type == NodeTypeBlock;
2160 case NodeTypeIfErrorExpr:
2161 if (node->data.if_err_expr.else_node)
2162 return statement_terminates_without_semicolon(node->data.if_err_expr.else_node);
2163 return node->data.if_err_expr.then_node->type == NodeTypeBlock;
21642164 case NodeTypeTestExpr:
21652165 if (node->data.test_expr.else_node)
21662166 return statement_terminates_without_semicolon(node->data.test_expr.else_node);
......@@ -2833,10 +2833,10 @@ void ast_visit_node_children(AstNode *node, void (*visit)(AstNode **, void *cont
28332833 visit_field(&node->data.if_bool_expr.then_block, visit, context);
28342834 visit_field(&node->data.if_bool_expr.else_node, visit, context);
28352835 break;
2836 case NodeTypeTryExpr:
2837 visit_field(&node->data.try_expr.target_node, visit, context);
2838 visit_field(&node->data.try_expr.then_node, visit, context);
2839 visit_field(&node->data.try_expr.else_node, visit, context);
2836 case NodeTypeIfErrorExpr:
2837 visit_field(&node->data.if_err_expr.target_node, visit, context);
2838 visit_field(&node->data.if_err_expr.then_node, visit, context);
2839 visit_field(&node->data.if_err_expr.else_node, visit, context);
28402840 break;
28412841 case NodeTypeTestExpr:
28422842 visit_field(&node->data.test_expr.target_node, visit, context);
src/tokenizer.cpp+2
......@@ -111,6 +111,7 @@ static const struct ZigKeyword zig_keywords[] = {
111111 {"and", TokenIdKeywordAnd},
112112 {"asm", TokenIdKeywordAsm},
113113 {"break", TokenIdKeywordBreak},
114 {"catch", TokenIdKeywordCatch},
114115 {"coldcc", TokenIdKeywordColdCC},
115116 {"comptime", TokenIdKeywordCompTime},
116117 {"const", TokenIdKeywordConst},
......@@ -1512,6 +1513,7 @@ const char * token_name(TokenId id) {
15121513 case TokenIdKeywordAnd: return "and";
15131514 case TokenIdKeywordAsm: return "asm";
15141515 case TokenIdKeywordBreak: return "break";
1516 case TokenIdKeywordCatch: return "catch";
15151517 case TokenIdKeywordColdCC: return "coldcc";
15161518 case TokenIdKeywordCompTime: return "comptime";
15171519 case TokenIdKeywordConst: return "const";
src/tokenizer.hpp+2-1
......@@ -47,10 +47,10 @@ enum TokenId {
4747 TokenIdFloatLiteral,
4848 TokenIdIntLiteral,
4949 TokenIdKeywordAlign,
50 TokenIdKeywordSection,
5150 TokenIdKeywordAnd,
5251 TokenIdKeywordAsm,
5352 TokenIdKeywordBreak,
53 TokenIdKeywordCatch,
5454 TokenIdKeywordColdCC,
5555 TokenIdKeywordCompTime,
5656 TokenIdKeywordConst,
......@@ -74,6 +74,7 @@ enum TokenId {
7474 TokenIdKeywordPacked,
7575 TokenIdKeywordPub,
7676 TokenIdKeywordReturn,
77 TokenIdKeywordSection,
7778 TokenIdKeywordStdcallCC,
7879 TokenIdKeywordStruct,
7980 TokenIdKeywordSwitch,
std/build.zig+12-12
......@@ -300,7 +300,7 @@ pub const Builder = struct {
300300 s.loop_flag = true;
301301
302302 for (s.dependencies.toSlice()) |dep| {
303 self.makeOneStep(dep) %% |err| {
303 self.makeOneStep(dep) catch |err| {
304304 if (err == error.DependencyLoopDetected) {
305305 warn(" {}\n", s.name);
306306 }
......@@ -573,7 +573,7 @@ pub const Builder = struct {
573573 child.cwd = cwd;
574574 child.env_map = env_map;
575575
576 const term = child.spawnAndWait() %% |err| {
576 const term = child.spawnAndWait() catch |err| {
577577 warn("Unable to spawn {}: {}\n", argv[0], @errorName(err));
578578 return err;
579579 };
......@@ -596,7 +596,7 @@ pub const Builder = struct {
596596 }
597597
598598 pub fn makePath(self: &Builder, path: []const u8) -> %void {
599 os.makePath(self.allocator, self.pathFromRoot(path)) %% |err| {
599 os.makePath(self.allocator, self.pathFromRoot(path)) catch |err| {
600600 warn("Unable to create path {}: {}\n", path, @errorName(err));
601601 return err;
602602 };
......@@ -641,11 +641,11 @@ pub const Builder = struct {
641641
642642 const dirname = os.path.dirname(dest_path);
643643 const abs_source_path = self.pathFromRoot(source_path);
644 os.makePath(self.allocator, dirname) %% |err| {
644 os.makePath(self.allocator, dirname) catch |err| {
645645 warn("Unable to create path {}: {}\n", dirname, @errorName(err));
646646 return err;
647647 };
648 os.copyFileMode(self.allocator, abs_source_path, dest_path, mode) %% |err| {
648 os.copyFileMode(self.allocator, abs_source_path, dest_path, mode) catch |err| {
649649 warn("Unable to copy {} to {}: {}\n", abs_source_path, dest_path, @errorName(err));
650650 return err;
651651 };
......@@ -663,7 +663,7 @@ pub const Builder = struct {
663663 if (builtin.environ == builtin.Environ.msvc) {
664664 return "cl.exe";
665665 } else {
666 return os.getEnvVarOwned(self.allocator, "CC") %% |err|
666 return os.getEnvVarOwned(self.allocator, "CC") catch |err|
667667 if (err == error.EnvironmentVariableNotFound)
668668 ([]const u8)("cc")
669669 else
......@@ -723,7 +723,7 @@ pub const Builder = struct {
723723
724724 pub fn exec(self: &Builder, argv: []const []const u8) -> []u8 {
725725 const max_output_size = 100 * 1024;
726 const result = os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size) %% |err| {
726 const result = os.ChildProcess.exec(self.allocator, argv, null, null, max_output_size) catch |err| {
727727 std.debug.panic("Unable to spawn {}: {}", argv[0], @errorName(err));
728728 };
729729 switch (result.term) {
......@@ -1895,11 +1895,11 @@ pub const WriteFileStep = struct {
18951895 const self = @fieldParentPtr(WriteFileStep, "step", step);
18961896 const full_path = self.builder.pathFromRoot(self.file_path);
18971897 const full_path_dir = os.path.dirname(full_path);
1898 os.makePath(self.builder.allocator, full_path_dir) %% |err| {
1898 os.makePath(self.builder.allocator, full_path_dir) catch |err| {
18991899 warn("unable to make path {}: {}\n", full_path_dir, @errorName(err));
19001900 return err;
19011901 };
1902 io.writeFile(full_path, self.data, self.builder.allocator) %% |err| {
1902 io.writeFile(full_path, self.data, self.builder.allocator) catch |err| {
19031903 warn("unable to write {}: {}\n", full_path, @errorName(err));
19041904 return err;
19051905 };
......@@ -1942,7 +1942,7 @@ pub const RemoveDirStep = struct {
19421942 const self = @fieldParentPtr(RemoveDirStep, "step", step);
19431943
19441944 const full_path = self.builder.pathFromRoot(self.dir_path);
1945 os.deleteTree(self.builder.allocator, full_path) %% |err| {
1945 os.deleteTree(self.builder.allocator, full_path) catch |err| {
19461946 warn("Unable to remove {}: {}\n", full_path, @errorName(err));
19471947 return err;
19481948 };
......@@ -1991,13 +1991,13 @@ fn doAtomicSymLinks(allocator: &Allocator, output_path: []const u8, filename_maj
19911991 const out_basename = os.path.basename(output_path);
19921992 // sym link for libfoo.so.1 to libfoo.so.1.2.3
19931993 const major_only_path = %%os.path.join(allocator, out_dir, filename_major_only);
1994 os.atomicSymLink(allocator, out_basename, major_only_path) %% |err| {
1994 os.atomicSymLink(allocator, out_basename, major_only_path) catch |err| {
19951995 warn("Unable to symlink {} -> {}\n", major_only_path, out_basename);
19961996 return err;
19971997 };
19981998 // sym link for libfoo.so to libfoo.so.1
19991999 const name_only_path = %%os.path.join(allocator, out_dir, filename_name_only);
2000 os.atomicSymLink(allocator, filename_major_only, name_only_path) %% |err| {
2000 os.atomicSymLink(allocator, filename_major_only, name_only_path) catch |err| {
20012001 warn("Unable to symlink {} -> {}\n", name_only_path, filename_major_only);
20022002 return err;
20032003 };
std/debug/index.zig+9-9
......@@ -22,8 +22,8 @@ var stderr_file: io.File = undefined;
2222var stderr_file_out_stream: io.FileOutStream = undefined;
2323var stderr_stream: ?&io.OutStream = null;
2424pub fn warn(comptime fmt: []const u8, args: ...) {
25 const stderr = getStderrStream() %% return;
26 stderr.print(fmt, args) %% return;
25 const stderr = getStderrStream() catch return;
26 stderr.print(fmt, args) catch return;
2727}
2828fn getStderrStream() -> %&io.OutStream {
2929 if (stderr_stream) |st| {
......@@ -39,8 +39,8 @@ fn getStderrStream() -> %&io.OutStream {
3939
4040/// Tries to print a stack trace to stderr, unbuffered, and ignores any error returned.
4141pub fn dumpStackTrace() {
42 const stderr = getStderrStream() %% return;
43 writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) %% return;
42 const stderr = getStderrStream() catch return;
43 writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) catch return;
4444}
4545
4646/// This function invokes undefined behavior when `ok` is `false`.
......@@ -86,9 +86,9 @@ pub fn panic(comptime format: []const u8, args: ...) -> noreturn {
8686 panicking = true;
8787 }
8888
89 const stderr = getStderrStream() %% os.abort();
90 stderr.print(format ++ "\n", args) %% os.abort();
91 writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) %% os.abort();
89 const stderr = getStderrStream() catch os.abort();
90 stderr.print(format ++ "\n", args) catch os.abort();
91 writeStackTrace(stderr, global_allocator, stderr_file.isTty(), 1) catch os.abort();
9292
9393 os.abort();
9494}
......@@ -146,7 +146,7 @@ pub fn writeStackTrace(out_stream: &io.OutStream, allocator: &mem.Allocator, tty
146146 // at compile time. I'll call it issue #313
147147 const ptr_hex = if (@sizeOf(usize) == 4) "0x{x8}" else "0x{x16}";
148148
149 const compile_unit = findCompileUnit(st, return_address) %% {
149 const compile_unit = findCompileUnit(st, return_address) catch {
150150 try out_stream.print("???:?:?: " ++ DIM ++ ptr_hex ++ " in ??? (???)" ++ RESET ++ "\n ???\n\n",
151151 return_address);
152152 continue;
......@@ -757,7 +757,7 @@ fn getLineNumberInfo(st: &ElfStackTrace, compile_unit: &const CompileUnit, targe
757757 });
758758 },
759759 else => {
760 const fwd_amt = math.cast(isize, op_size - 1) %% return error.InvalidDebugInfo;
760 const fwd_amt = math.cast(isize, op_size - 1) catch return error.InvalidDebugInfo;
761761 try in_file.seekForward(fwd_amt);
762762 },
763763 }
std/fmt/index.zig+1-1
......@@ -533,7 +533,7 @@ fn bufPrintIntToSlice(buf: []u8, value: var, base: u8, uppercase: bool, width: u
533533}
534534
535535test "parse u64 digit too big" {
536 _ = parseUnsigned(u64, "123a", 10) %% |err| {
536 _ = parseUnsigned(u64, "123a", 10) catch |err| {
537537 if (err == error.InvalidChar) return;
538538 unreachable;
539539 };
std/heap.zig+2-2
......@@ -137,9 +137,9 @@ pub const IncrementingAllocator = struct {
137137
138138test "c_allocator" {
139139 if (builtin.link_libc) {
140 var slice = c_allocator.alloc(u8, 50) %% return;
140 var slice = c_allocator.alloc(u8, 50) catch return;
141141 defer c_allocator.free(slice);
142 slice = c_allocator.realloc(u8, slice, 100) %% return;
142 slice = c_allocator.realloc(u8, slice, 100) catch return;
143143 }
144144}
145145
std/os/child_process.zig+10-10
......@@ -383,27 +383,27 @@ pub const ChildProcess = struct {
383383 // we are the child
384384 restore_SIGCHLD();
385385
386 setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) %%
386 setUpChildIo(self.stdin_behavior, stdin_pipe[0], posix.STDIN_FILENO, dev_null_fd) catch
387387 |err| forkChildErrReport(err_pipe[1], err);
388 setUpChildIo(self.stdout_behavior, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) %%
388 setUpChildIo(self.stdout_behavior, stdout_pipe[1], posix.STDOUT_FILENO, dev_null_fd) catch
389389 |err| forkChildErrReport(err_pipe[1], err);
390 setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) %%
390 setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch
391391 |err| forkChildErrReport(err_pipe[1], err);
392392
393393 if (self.cwd) |cwd| {
394 os.changeCurDir(self.allocator, cwd) %%
394 os.changeCurDir(self.allocator, cwd) catch
395395 |err| forkChildErrReport(err_pipe[1], err);
396396 }
397397
398398 if (self.gid) |gid| {
399 os.posix_setregid(gid, gid) %% |err| forkChildErrReport(err_pipe[1], err);
399 os.posix_setregid(gid, gid) catch |err| forkChildErrReport(err_pipe[1], err);
400400 }
401401
402402 if (self.uid) |uid| {
403 os.posix_setreuid(uid, uid) %% |err| forkChildErrReport(err_pipe[1], err);
403 os.posix_setreuid(uid, uid) catch |err| forkChildErrReport(err_pipe[1], err);
404404 }
405405
406 os.posixExecve(self.argv, env_map, self.allocator) %%
406 os.posixExecve(self.argv, env_map, self.allocator) catch
407407 |err| forkChildErrReport(err_pipe[1], err);
408408 }
409409
......@@ -573,7 +573,7 @@ pub const ChildProcess = struct {
573573 defer self.allocator.free(app_name);
574574
575575 windowsCreateProcess(app_name.ptr, cmd_line.ptr, envp_ptr, cwd_ptr,
576 &siStartInfo, &piProcInfo) %% |no_path_err|
576 &siStartInfo, &piProcInfo) catch |no_path_err|
577577 {
578578 if (no_path_err != error.FileNotFound)
579579 return no_path_err;
......@@ -767,12 +767,12 @@ const ErrInt = @IntType(false, @sizeOf(error) * 8);
767767fn writeIntFd(fd: i32, value: ErrInt) -> %void {
768768 var bytes: [@sizeOf(ErrInt)]u8 = undefined;
769769 mem.writeInt(bytes[0..], value, builtin.endian);
770 os.posixWrite(fd, bytes[0..]) %% return error.SystemResources;
770 os.posixWrite(fd, bytes[0..]) catch return error.SystemResources;
771771}
772772
773773fn readIntFd(fd: i32) -> %ErrInt {
774774 var bytes: [@sizeOf(ErrInt)]u8 = undefined;
775 os.posixRead(fd, bytes[0..]) %% return error.SystemResources;
775 os.posixRead(fd, bytes[0..]) catch return error.SystemResources;
776776 return mem.readInt(bytes[0..], ErrInt, builtin.endian);
777777}
778778
std/os/index.zig+2-2
......@@ -842,7 +842,7 @@ pub fn makePath(allocator: &Allocator, full_path: []const u8) -> %void {
842842
843843 var end_index: usize = resolved_path.len;
844844 while (true) {
845 makeDir(allocator, resolved_path[0..end_index]) %% |err| {
845 makeDir(allocator, resolved_path[0..end_index]) catch |err| {
846846 if (err == error.PathAlreadyExists) {
847847 // TODO stat the file and return an error if it's not a directory
848848 // this is important because otherwise a dangling symlink
......@@ -915,7 +915,7 @@ pub fn deleteTree(allocator: &Allocator, full_path: []const u8) -> %void {
915915 return err;
916916 }
917917 {
918 var dir = Dir.open(allocator, full_path) %% |err| {
918 var dir = Dir.open(allocator, full_path) catch |err| {
919919 if (err == error.FileNotFound)
920920 return;
921921 if (err == error.NotDir)
std/os/path.zig+1-1
......@@ -1102,7 +1102,7 @@ pub fn real(allocator: &Allocator, pathname: []const u8) -> %[]u8 {
11021102 var buf = try allocator.alloc(u8, 256);
11031103 %defer allocator.free(buf);
11041104 while (true) {
1105 const buf_len = math.cast(windows.DWORD, buf.len) %% return error.NameTooLong;
1105 const buf_len = math.cast(windows.DWORD, buf.len) catch return error.NameTooLong;
11061106 const result = windows.GetFinalPathNameByHandleA(h_file, buf.ptr, buf_len, windows.VOLUME_NAME_DOS);
11071107
11081108 if (result == 0) {
std/os/windows/util.zig+1-1
......@@ -166,7 +166,7 @@ pub fn windowsUnloadDll(hModule: windows.HMODULE) {
166166test "InvalidDll" {
167167 const DllName = "asdf.dll";
168168 const allocator = std.debug.global_allocator;
169 const handle = os.windowsLoadDll(allocator, DllName) %% |err| {
169 const handle = os.windowsLoadDll(allocator, DllName) catch |err| {
170170 assert(err == error.DllNotFound);
171171 return;
172172 };
std/special/bootstrap.zig+4-4
......@@ -22,7 +22,7 @@ comptime {
2222
2323extern fn zenMain() -> noreturn {
2424 // TODO: call exit.
25 root.main() %% {};
25 root.main() catch {};
2626 while (true) {}
2727}
2828
......@@ -44,7 +44,7 @@ nakedcc fn _start() -> noreturn {
4444extern fn WinMainCRTStartup() -> noreturn {
4545 @setAlignStack(16);
4646
47 root.main() %% std.os.windows.ExitProcess(1);
47 root.main() catch std.os.windows.ExitProcess(1);
4848 std.os.windows.ExitProcess(0);
4949}
5050
......@@ -52,7 +52,7 @@ fn posixCallMainAndExit() -> noreturn {
5252 const argc = *argc_ptr;
5353 const argv = @ptrCast(&&u8, &argc_ptr[1]);
5454 const envp = @ptrCast(&?&u8, &argv[argc + 1]);
55 callMain(argc, argv, envp) %% std.os.posix.exit(1);
55 callMain(argc, argv, envp) catch std.os.posix.exit(1);
5656 std.os.posix.exit(0);
5757}
5858
......@@ -67,6 +67,6 @@ fn callMain(argc: usize, argv: &&u8, envp: &?&u8) -> %void {
6767}
6868
6969extern fn main(c_argc: i32, c_argv: &&u8, c_envp: &?&u8) -> i32 {
70 callMain(usize(c_argc), c_argv, c_envp) %% return 1;
70 callMain(usize(c_argc), c_argv, c_envp) catch return 1;
7171 return 0;
7272}
std/special/build_runner.zig+3-3
......@@ -117,7 +117,7 @@ pub fn main() -> %void {
117117 if (builder.validateUserInputDidItFail())
118118 return usageAndErr(&builder, true, try stderr_stream);
119119
120 builder.make(targets.toSliceConst()) %% |err| {
120 builder.make(targets.toSliceConst()) catch |err| {
121121 if (err == error.InvalidStepName) {
122122 return usageAndErr(&builder, true, try stderr_stream);
123123 }
......@@ -184,12 +184,12 @@ fn usage(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream)
184184}
185185
186186fn usageAndErr(builder: &Builder, already_ran_build: bool, out_stream: &io.OutStream) -> error {
187 usage(builder, already_ran_build, out_stream) %% {};
187 usage(builder, already_ran_build, out_stream) catch {};
188188 return error.InvalidArgs;
189189}
190190
191191fn unwrapArg(arg: %[]u8) -> %[]u8 {
192 return arg %% |err| {
192 return arg catch |err| {
193193 warn("Unable to parse command line: {}\n", err);
194194 return err;
195195 };
test/cases/defer.zig+1-1
......@@ -18,7 +18,7 @@ test "mixing normal and error defers" {
1818 assert(result[0] == 'c');
1919 assert(result[1] == 'a');
2020
21 const ok = runSomeErrorDefers(false) %% |err| x: {
21 const ok = runSomeErrorDefers(false) catch |err| x: {
2222 assert(err == error.FalseNotAllowed);
2323 break :x true;
2424 };
test/cases/error.zig+3-3
......@@ -11,7 +11,7 @@ pub fn bar() -> %i32 {
1111}
1212
1313pub fn baz() -> %i32 {
14 const y = foo() %% 1234;
14 const y = foo() catch 1234;
1515 return y + 1;
1616}
1717
......@@ -53,8 +53,8 @@ fn shouldBeNotEqual(a: error, b: error) {
5353
5454
5555test "error binary operator" {
56 const a = errBinaryOperatorG(true) %% 3;
57 const b = errBinaryOperatorG(false) %% 3;
56 const a = errBinaryOperatorG(true) catch 3;
57 const b = errBinaryOperatorG(false) catch 3;
5858 assert(a == 3);
5959 assert(b == 10);
6060}
test/cases/switch.zig+1-1
......@@ -230,7 +230,7 @@ fn return_a_number() -> %i32 {
230230}
231231
232232test "capture value of switch with all unreachable prongs" {
233 const x = return_a_number() %% |err| switch (err) {
233 const x = return_a_number() catch |err| switch (err) {
234234 else => unreachable,
235235 };
236236 assert(x == 1);
test/compare_output.zig+2-2
......@@ -395,7 +395,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
395395 cases.add("%defer and it fails",
396396 \\const io = @import("std").io;
397397 \\pub fn main() -> %void {
398 \\ do_test() %% return;
398 \\ do_test() catch return;
399399 \\}
400400 \\fn do_test() -> %void {
401401 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
......@@ -415,7 +415,7 @@ pub fn addCases(cases: &tests.CompareOutputContext) {
415415 cases.add("%defer and it passes",
416416 \\const io = @import("std").io;
417417 \\pub fn main() -> %void {
418 \\ do_test() %% return;
418 \\ do_test() catch return;
419419 \\}
420420 \\fn do_test() -> %void {
421421 \\ const stdout = &(io.FileOutStream.init(&%%io.getStdOut()).stream);
test/compile_errors.zig+1-1
......@@ -1288,7 +1288,7 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
12881288
12891289 cases.add("return from defer expression",
12901290 \\pub fn testTrickyDefer() -> %void {
1291 \\ defer canFail() %% {};
1291 \\ defer canFail() catch {};
12921292 \\
12931293 \\ defer try canFail();
12941294 \\
test/tests.zig+7-7
......@@ -259,7 +259,7 @@ pub const CompareOutputContext = struct {
259259 child.stderr_behavior = StdIo.Pipe;
260260 child.env_map = &b.env_map;
261261
262 child.spawn() %% |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
262 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
263263
264264 var stdout = Buffer.initNull(b.allocator);
265265 var stderr = Buffer.initNull(b.allocator);
......@@ -270,7 +270,7 @@ pub const CompareOutputContext = struct {
270270 %%stdout_file_in_stream.stream.readAllBuffer(&stdout, max_stdout_size);
271271 %%stderr_file_in_stream.stream.readAllBuffer(&stderr, max_stdout_size);
272272
273 const term = child.wait() %% |err| {
273 const term = child.wait() catch |err| {
274274 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
275275 };
276276 switch (term) {
......@@ -341,7 +341,7 @@ pub const CompareOutputContext = struct {
341341 child.stdout_behavior = StdIo.Ignore;
342342 child.stderr_behavior = StdIo.Ignore;
343343
344 const term = child.spawnAndWait() %% |err| {
344 const term = child.spawnAndWait() catch |err| {
345345 debug.panic("Unable to spawn {}: {}\n", full_exe_path, @errorName(err));
346346 };
347347
......@@ -590,7 +590,7 @@ pub const CompileErrorContext = struct {
590590 child.stdout_behavior = StdIo.Pipe;
591591 child.stderr_behavior = StdIo.Pipe;
592592
593 child.spawn() %% |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
593 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
594594
595595 var stdout_buf = Buffer.initNull(b.allocator);
596596 var stderr_buf = Buffer.initNull(b.allocator);
......@@ -601,7 +601,7 @@ pub const CompileErrorContext = struct {
601601 %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size);
602602 %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size);
603603
604 const term = child.wait() %% |err| {
604 const term = child.wait() catch |err| {
605605 debug.panic("Unable to spawn {}: {}\n", zig_args.items[0], @errorName(err));
606606 };
607607 switch (term) {
......@@ -862,7 +862,7 @@ pub const TranslateCContext = struct {
862862 child.stdout_behavior = StdIo.Pipe;
863863 child.stderr_behavior = StdIo.Pipe;
864864
865 child.spawn() %% |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
865 child.spawn() catch |err| debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
866866
867867 var stdout_buf = Buffer.initNull(b.allocator);
868868 var stderr_buf = Buffer.initNull(b.allocator);
......@@ -873,7 +873,7 @@ pub const TranslateCContext = struct {
873873 %%stdout_file_in_stream.stream.readAllBuffer(&stdout_buf, max_stdout_size);
874874 %%stderr_file_in_stream.stream.readAllBuffer(&stderr_buf, max_stdout_size);
875875
876 const term = child.wait() %% |err| {
876 const term = child.wait() catch |err| {
877877 debug.panic("Unable to spawn {}: {}\n", zig_args.toSliceConst()[0], @errorName(err));
878878 };
879879 switch (term) {