This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/repro.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/repro.roc | |
# | |
app "lazy-parser-repro" | |
packages { pf: "platform/main.roc" } | |
imports [ | |
Parser.Core.{ Parser, map, lazy}, | |
Parser.Str.{ parseStr, RawStr } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/parse-json.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/parse-json.roc | |
# | |
app "parse-json" | |
packages { pf: "platform/main.roc" } | |
imports [ | |
Parser.Core.{ Parser, oneOf, flatten, map, apply, many, const, maybe, between, alt, sepBy, ignore, lazy}, | |
Parser.Str.{ string, strFromRaw, parseStr, RawStr, codeunitSatisfies, codeunit } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/float-parsing-repro.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/float-parsing-repro.roc | |
# | |
app "parse-json-repro" | |
packages { pf: "platform/main.roc" } | |
imports [ | |
Parser.Core.{ Parser, flatten, map, apply, many, const, maybe}, | |
Parser.Str.{ strFromRaw, parseStr, RawStr, codeunitSatisfies, codeunit } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create this file at <roc-repo-root>/examples/parser/parse-json.roc | |
# run | |
# $ cd <roc-repo-root> && roc examples/parser/parse-json.roc | |
# | |
# one-liner: clone roc repo to /tmp + wget gist + run gist | |
# $ cd /tmp && git clone [email protected]:roc-lang/roc.git && cd roc && wget https://gist.github.com/travisstaloch/7add1274a085f1e6cba59ca93d991d9c/raw/parse-json.roc -O examples/parser/parse-json.roc && roc examples/parser/parse-json.roc | |
app "parse-json" | |
packages { pf: "platform/main.roc" } | |
imports [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! Shows how to manually convert a group of enums / ints into a packed struct and then into an integer | |
//! which can be used in a switch statement. Useful for eliminting complicated nested switches / ifs. | |
//! | |
//! Then creates helpers switchable() and switchableAny() for doing the same. | |
//! | |
//! Note: the second part only works with stage1 as of 9/25/22 (zig version | |
//! 0.10.0-dev.4115+75e9a8c7f). stage2 currently crashes on this but will likely work soon. | |
const std = @import("std"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//! this script translates garbled @compileLog output into a readable form. | |
//! reads from stdin so you may need to redirect stderr to stdin like this: | |
//! $ zig run file.zig |& zig run print_compile_log.zig | |
//! | |
//! works by splitting lines on "u8{" delimiter and then skipping `delim_prefixes` | |
//! in `skipDelimPrefix()`. this makes things work when the type of the garbled string | |
//! is either `[]const u8{...}` or `*[N:0]u8{...}` | |
//! | |
const std = @import("std"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// adapted from https://gist.github.com/slimsag/db2dd2c49aa038e23b654120e70c9b00 | |
const std = @import("std"); | |
const Allocator = std.mem.Allocator; | |
pub const Error = error{ | |
EndOfStream, | |
Utf8InvalidStartByte, | |
} || std.fs.File.ReadError || std.fs.File.SeekError || std.mem.Allocator.Error; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extern const unsigned int choose[53][10]; | |
static int hash_binary(int k) | |
{ | |
int sum = 0; | |
sum += choose[0][k]; | |
return sum; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// copy all .c and .h files from antirez/rax to a folder named 'raxc' | |
// mkdir raxc && cp path/to/antirez/rax/*{.h,.c} raxc | |
// compile the rax c libs | |
// cd raxc && zig build-lib -lc --c-source rc4rand.c && zig build-lib -lc --c-source rax.c | |
// or compile with RAX_DEBUG_MSG (you might have to delete zig-cache) | |
// zig build-lib -lc --c-source rax.c -DRAX_DEBUG_MSG | |
// run this file's tests, linking rax c libs and including c headers | |
// cd .. && zig test -lc -lrax -lrc4rand -Iraxc -Lraxc test-rax.zig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const warn = std.debug.warn; | |
test "parse psf font file" { | |
// https://github.com/monarrk/trOS/raw/master/src/vga/font.psf | |
// const font_raw = @embedFile("font.psf"); | |
// https://github.com/powerline/fonts/blob/master/Terminus/PSF/ter-powerline-v16b.psf.gz | |
const font_raw = @embedFile("ter-powerline-v16b.psf"); | |
const PSFHeader = extern struct { |