Commit 37aae53009

Andrew Kelley <superjoe30@gmail.com>
2016-01-23 11:06:29
various small cleanups
1 parent 706f72f
Changed files (3)
doc
vim
syntax
example
std
doc/vim/syntax/zig.vim
@@ -9,7 +9,7 @@ endif
 
 syn keyword zigStorage const var extern volatile export pub noalias
 syn keyword zigStructure struct enum
-syn keyword zigStatement goto break return continue asm
+syn keyword zigStatement goto break return continue asm defer
 syn keyword zigConditional if else switch
 syn keyword zigRepeat while for
 
example/cat/main.zig
@@ -7,11 +7,10 @@ import "std.zig";
 // * update std API
 // * defer
 // * %return
-// * %% operator
+// * %% binary operator
+// * %% prefix operator
 // * cast err type to string
 
-pub %.Invalid;
-
 pub fn main(args: [][]u8) %void => {
     const exe = args[0];
     var catted_anything = false;
@@ -24,7 +23,7 @@ pub fn main(args: [][]u8) %void => {
         } else {
             var is: InputStream;
             is.open(arg, OpenReadOnly) %% (err) => {
-                stderr.print("Unable to open file: {}", ([]u8])(err));
+                %%stderr.print("Unable to open file: {}", ([]u8])(err));
                 return err;
             }
             defer is.close();
@@ -39,7 +38,7 @@ pub fn main(args: [][]u8) %void => {
 }
 
 fn usage(exe: []u8) %void => {
-    stderr.print("Usage: {} [FILE]...\n", exe);
+    %%stderr.print("Usage: {} [FILE]...\n", exe);
     return %.Invalid;
 }
 
@@ -47,16 +46,18 @@ fn cat_stream(is: InputStream) %void => {
     var buf: [1024 * 4]u8;
 
     while (true) {
-        const bytes_read = is.read(buf);
-        if (bytes_read < 0) {
-            stderr.print("Unable to read from stream: {}", ([]u8)(is.err));
-            return is.err;
+        const bytes_read = is.read(buf) %% (err) => {
+            %%stderr.print("Unable to read from stream: {}", ([]u8)(err));
+            return err;
+        }
+
+        if (bytes_read == 0) {
+            break;
         }
 
-        const bytes_written = stdout.write(buf[0...bytes_read]);
-        if (bytes_written < bytes_read) {
-            stderr.print("Unable to write to stdout: {}", ([]u8)(stdout.err));
-            return stdout.err;
+        stdout.write(buf[0...bytes_read]) %% (err) => {
+            %%stderr.print("Unable to write to stdout: {}", ([]u8)(err));
+            return err;
         }
     }
 }
std/std.zig
@@ -23,6 +23,7 @@ pub var stderr = OutStream {
     .index = 0,
     .buffered = false,
 };
+*/
 
 pub %.Unexpected;
 pub %.DiskQuota;
@@ -32,7 +33,7 @@ pub %.Io;
 pub %.NoSpaceLeft;
 pub %.BadPerm;
 pub %.PipeFail;
-*/
+pub %.Invalid;
 
 const buffer_size = 4 * 1024;
 const max_u64_base10_digits = 20;