PROJECT NAME: dot-parser
‘dot-parser’, yup, that’s the name. Too simple I know.
This is for parsing graphviz’s .dot language. I started working on it to give zigraph support for .dot. Which will not include it as is but there will be a wrapper that connects both. It is engine agnostic, though it was created zigraph in mind, it can be used for other purposes too like linting or other engine or simple graph related stuff.
It doesn’t yet support whole grammer: HTML identifiers and non-ascii identifiers are still pending implementation.
My main goal, like zigraph’s, has been performance, low memory usage, diagnostics-friendliness, and embeddability
Here is the taste of it:
var bag: dot.FixedDiagnosticBag(8) = .{};
var checked = dot.parseAndValidate(allocator, source, bag.sink(), .{});
defer checked.deinit(allocator);
const document = checked.document.?;
var statements = document.statements();
while (statements.next()) |statement| switch (statement) {
.node => |n| /* ... */,
.edge => |e| /* ... */,
else => {},
};
For error output, the built-in console renderer produces this:
parsed: success, document valid: false
┌─ Error 1: edge operator does not match the graph kind
│ example.dot:3:7
│
│ 1 │ graph {
│ │ ───── the document is undirected because of this keyword
│ ⋯
│ 3 │ a -> b;
│ │ ^^ expected '--', found '->'
│
│ Hint: change '->' to '--', or declare the document with 'digraph'
└─ E1 ─ [dot_parser:E.Validation.Operator.002]
Supported Zig versions
what versions are supported?
zig-0-16
AI / LLM usage disclosure
AI was used throughout, as a design collaborator during architecture and requirements work (proposing options, drafting formalizations, helping refine trade-offs), and implementation, going through reviews. I made the final calls on architecture, API shape, memory model, and diagnostics behavior, including rejecting or reversing AI-proposed directions where the linked decision log (docs/internal) shows that happening, some parts of it though not complete, because work has been done 2 places to keep project clean. Bookkeeping on those decisions was AI-assisted as well.