Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/teh-cmc/zig-ron
[WIP] A robust, efficient implementation of the Rusty Object Notation (RON) for the Zig programming language.
https://github.com/teh-cmc/zig-ron
parser ron zig
Last synced: about 2 months ago
JSON representation
[WIP] A robust, efficient implementation of the Rusty Object Notation (RON) for the Zig programming language.
- Host: GitHub
- URL: https://github.com/teh-cmc/zig-ron
- Owner: teh-cmc
- License: mit
- Created: 2021-10-28T16:54:55.000Z (over 3 years ago)
- Default Branch: master
- Last Pushed: 2021-10-28T16:56:14.000Z (over 3 years ago)
- Last Synced: 2024-12-13T02:36:50.002Z (2 months ago)
- Topics: parser, ron, zig
- Language: Zig
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Zig-RON
_**wip**_
Hopefully: a robust, efficient implementation of the [Rusty Object Notation](https://github.com/ron-rs/ron) for the Zig programming language.
This is a work in progress: you can and should expect missing docs, miscellaneous bugs, a general lack of polish, etc.
The deserializer should already be in a pretty usable state though, hence this early release.
There simply isn't a serializer yet, that's the easy part though :)Feel free to reach out either via the issue tracker or on Zig discord (`clem#0498`).
## Usage
```zig
const std = @import("std");
const ron = @import("ron");const MyStruct = struct {
bool: bool,
float: f32,
int: i42,
string: []const u8,
char: ron.Char,
unit: ron.Unit,array_list: std.ArrayList(u32),
slice: []u32,string_map: std.StringArrayHashMap([]const u8),
map: std.AutoArrayHashMap(bool, []const u8),option: ?[]const u8,
enums: enum { a, b, c },
unions: union(enum) { a: bool, b: []const u8, c: f32 },
any: ron.Value, // Generic heterogeneous valuesnested: ?*@This(),
default: []const u8 = "some default value",
};const data =
\\MyStruct(
\\ bool: true,
\\ float: 42.420,
\\ int: 666,
\\ string: "ガタカへようこそ",
\\ char: '🚁',
\\ unit: (),
\\
\\ array_list: [1, 2, 3, 4],
\\ slice: [5, 6, 7, 8],
\\
\\ string_map: { "hello": "world" },
\\ map: { false: "is false", true: "is not false" },
\\
\\ option: Some("\u{263A}"),
\\ enums: b,
\\ unions: c(666.111),
\\ any: seq([string("hey"), bool(true), float(42.42)]),
\\
// Tuple to struct coercion!
\\ nested: Some((
\\ false, 1.0, 2, "xxx", 'X', (),
\\ [], [], {}, {},
\\ None, a, b("nope!"), option(None),
\\ None,
\\ )),
\\
// This will be silently ignored.
\\ field_that_doesnt_exist: DoesntExist(
\\ xxx: 42,
\\ 42: "xxx"
\\ ),
\\)
;pub fn main() !void {
var allocator = std.heap.page_allocator;var deser = ron.Deserializer.init(allocator);
// clears internal parser resources
defer deser.deinit();
// clears data allocated for the end-user (arrays, maps, escaped strings...)
defer deser.parseFree();var tokens = &ron.Lexer.init(data).token_stream;
const res = deser.parse(MyStruct, tokens) catch |err| {
try deser.report(std.io.getStdErr().writer());
return err;
};_ = ron.debug_ext.dbg(res);
}
```## License
[MIT](./LICENSE)