Skip to content

Commit

Permalink
Merge pull request #759 from zig-lang/error-sets
Browse files Browse the repository at this point in the history
Error Sets
  • Loading branch information
andrewrk committed Feb 9, 2018
2 parents 1c236b0 + 8e55456 commit 5911962
Show file tree
Hide file tree
Showing 83 changed files with 3,263 additions and 1,607 deletions.
4 changes: 2 additions & 2 deletions build.zig
Expand Up @@ -10,7 +10,7 @@ const ArrayList = std.ArrayList;
const Buffer = std.Buffer;
const io = std.io;

pub fn build(b: &Builder) %void {
pub fn build(b: &Builder) !void {
const mode = b.standardReleaseOptions();

var docgen_exe = b.addExecutable("docgen", "doc/docgen.zig");
Expand Down Expand Up @@ -149,7 +149,7 @@ const LibraryDep = struct {
includes: ArrayList([]const u8),
};

fn findLLVM(b: &Builder, llvm_config_exe: []const u8) %LibraryDep {
fn findLLVM(b: &Builder, llvm_config_exe: []const u8) !LibraryDep {
const libs_output = try b.exec([][]const u8{llvm_config_exe, "--libs", "--system-libs"});
const includes_output = try b.exec([][]const u8{llvm_config_exe, "--includedir"});
const libdir_output = try b.exec([][]const u8{llvm_config_exe, "--libdir"});
Expand Down
7 changes: 3 additions & 4 deletions ci/appveyor/build_script.bat
Expand Up @@ -30,11 +30,10 @@ cd %APPVEYOR_BUILD_FOLDER%
SET "PATH=C:\msys64\mingw64\bin;C:\msys64\usr\bin;%PATH%"
SET "MSYSTEM=MINGW64"

bash -lc "pacman -Syu --needed --noconfirm"
bash -lc "pacman -Su --needed --noconfirm"
bash -lc "yes | pacman -Syu --needed --noconfirm"
bash -lc "yes | pacman -Su --needed --noconfirm"

bash -lc "pacman -S --needed --noconfirm make mingw64/mingw-w64-x86_64-make mingw64/mingw-w64-x86_64-cmake mingw64/mingw-w64-x86_64-clang mingw64/mingw-w64-x86_64-llvm mingw64/mingw-w64-x86_64-lld mingw64/mingw-w64-x86_64-gcc"
bash -lc "yes | pacman -S --needed --noconfirm make mingw64/mingw-w64-x86_64-make mingw64/mingw-w64-x86_64-cmake mingw64/mingw-w64-x86_64-clang mingw64/mingw-w64-x86_64-llvm mingw64/mingw-w64-x86_64-lld mingw64/mingw-w64-x86_64-gcc"

bash -lc "cd ${APPVEYOR_BUILD_FOLDER} && mkdir build && cd build && cmake .. -G""MSYS Makefiles"" -DCMAKE_INSTALL_PREFIX=$(pwd) -DZIG_LIBC_LIB_DIR=$(dirname $(cc -print-file-name=crt1.o)) -DZIG_LIBC_INCLUDE_DIR=$(echo -n | cc -E -x c - -v 2>&1 | grep -B1 ""End of search list."" | head -n1 | cut -c 2- | sed ""s/ .*//"") -DZIG_LIBC_STATIC_LIB_DIR=$(dirname $(cc -print-file-name=crtbegin.o)) && make && make install"

@echo "MinGW build successful"
29 changes: 10 additions & 19 deletions doc/docgen.zig
Expand Up @@ -12,7 +12,7 @@ const exe_ext = std.build.Target(std.build.Target.Native).exeFileExt();
const obj_ext = std.build.Target(std.build.Target.Native).oFileExt();
const tmp_dir_name = "docgen_tmp";

pub fn main() %void {
pub fn main() !void {
// TODO use a more general purpose allocator here
var inc_allocator = try std.heap.IncrementingAllocator.init(max_doc_file_size);
defer inc_allocator.deinit();
Expand Down Expand Up @@ -42,7 +42,7 @@ pub fn main() %void {
const input_file_bytes = try file_in_stream.stream.readAllAlloc(allocator, max_doc_file_size);

var file_out_stream = io.FileOutStream.init(&out_file);
var buffered_out_stream = io.BufferedOutStream.init(&file_out_stream.stream);
var buffered_out_stream = io.BufferedOutStream(io.FileOutStream.Error).init(&file_out_stream.stream);

var tokenizer = Tokenizer.init(in_file_name, input_file_bytes);
var toc = try genToc(allocator, &tokenizer);
Expand Down Expand Up @@ -218,8 +218,6 @@ const Tokenizer = struct {
}
};

error ParseError;

fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const u8, args: ...) error {
const loc = tokenizer.getTokenLocation(token);
warn("{}:{}:{}: error: " ++ fmt ++ "\n", tokenizer.source_file_name, loc.line + 1, loc.column + 1, args);
Expand All @@ -243,13 +241,13 @@ fn parseError(tokenizer: &Tokenizer, token: &const Token, comptime fmt: []const
return error.ParseError;
}

fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) %void {
fn assertToken(tokenizer: &Tokenizer, token: &const Token, id: Token.Id) !void {
if (token.id != id) {
return parseError(tokenizer, token, "expected {}, found {}", @tagName(id), @tagName(token.id));
}
}

fn eatToken(tokenizer: &Tokenizer, id: Token.Id) %Token {
fn eatToken(tokenizer: &Tokenizer, id: Token.Id) !Token {
const token = tokenizer.next();
try assertToken(tokenizer, token, id);
return token;
Expand Down Expand Up @@ -316,7 +314,7 @@ const Action = enum {
Close,
};

fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) %Toc {
fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) !Toc {
var urls = std.HashMap([]const u8, Token, mem.hash_slice_u8, mem.eql_slice_u8).init(allocator);
errdefer urls.deinit();

Expand Down Expand Up @@ -540,7 +538,7 @@ fn genToc(allocator: &mem.Allocator, tokenizer: &Tokenizer) %Toc {
};
}

fn urlize(allocator: &mem.Allocator, input: []const u8) %[]u8 {
fn urlize(allocator: &mem.Allocator, input: []const u8) ![]u8 {
var buf = try std.Buffer.initSize(allocator, 0);
defer buf.deinit();

Expand All @@ -560,7 +558,7 @@ fn urlize(allocator: &mem.Allocator, input: []const u8) %[]u8 {
return buf.toOwnedSlice();
}

fn escapeHtml(allocator: &mem.Allocator, input: []const u8) %[]u8 {
fn escapeHtml(allocator: &mem.Allocator, input: []const u8) ![]u8 {
var buf = try std.Buffer.initSize(allocator, 0);
defer buf.deinit();

Expand Down Expand Up @@ -596,15 +594,13 @@ const TermState = enum {
ExpectEnd,
};

error UnsupportedEscape;

test "term color" {
const input_bytes = "A\x1b[32;1mgreen\x1b[0mB";
const result = try termColor(std.debug.global_allocator, input_bytes);
assert(mem.eql(u8, result, "A<span class=\"t32\">green</span>B"));
}

fn termColor(allocator: &mem.Allocator, input: []const u8) %[]u8 {
fn termColor(allocator: &mem.Allocator, input: []const u8) ![]u8 {
var buf = try std.Buffer.initSize(allocator, 0);
defer buf.deinit();

Expand Down Expand Up @@ -684,9 +680,7 @@ fn termColor(allocator: &mem.Allocator, input: []const u8) %[]u8 {
return buf.toOwnedSlice();
}

error ExampleFailedToCompile;

fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io.OutStream, zig_exe: []const u8) %void {
fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: var, zig_exe: []const u8) !void {
var code_progress_index: usize = 0;
for (toc.nodes) |node| {
switch (node) {
Expand Down Expand Up @@ -974,10 +968,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io

}

error ChildCrashed;
error ChildExitError;

fn exec(allocator: &mem.Allocator, args: []const []const u8) %os.ChildProcess.ExecResult {
fn exec(allocator: &mem.Allocator, args: []const []const u8) !os.ChildProcess.ExecResult {
const result = try os.ChildProcess.exec(allocator, args, null, null, max_doc_file_size);
switch (result.term) {
os.ChildProcess.Term.Exited => |exit_code| {
Expand Down

0 comments on commit 5911962

Please sign in to comment.