Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub fn build(b: *std.Build) void {
const diag_file = b.fmt("{s}.diag", .{path[0 .. path.len - 5]});

const test_run = b.addRunArtifact(exe);
test_run.addArgs(&.{"--json-diagnostics"});
test_run.addFileArg(b.path(path));
test_run.expectExitCode(1);
const generated_diag = test_run.captureStdErr();
Expand Down
28 changes: 21 additions & 7 deletions src/main.zig
Original file line number Diff line number Diff line change
Expand Up @@ -34,17 +34,25 @@ pub fn main() !u8 {
options,
);

for (diagnostics.items.items) |diag| {
try stderr.interface.print("{s}:{f}: {f}\n", .{
options.file_path,
diag.location,
diag.code,
});
if (options.json_diagnostics) {
const json_options: std.json.Stringify.Options = .{ .whitespace = .indent_2 };
try std.json.Stringify.value(diagnostics.items.items, json_options, &stderr.interface);
try stderr.interface.writeByte('\n');
} else {
for (diagnostics.items.items) |diag| {
try stderr.interface.print("{s}:{f}: {f}\n", .{
options.file_path,
diag.location,
diag.code,
});
}
}
try stderr.interface.flush();

parse_result catch |err| {
std.log.err("failed to parse \"{s}\": {t}", .{ options.file_path, err });
if (!options.json_diagnostics) {
std.log.err("failed to parse \"{s}\": {t}", .{ options.file_path, err });
}
return 1;
};

Expand Down Expand Up @@ -73,6 +81,7 @@ fn parse_and_process(allocator: std.mem.Allocator, diagnostics: *hdoc.Diagnostic
const CliOptions = struct {
format: RenderFormat = .html,
file_path: []const u8,
json_diagnostics: bool = false,
};

const RenderFormat = enum {
Expand All @@ -98,6 +107,11 @@ fn parse_options(stderr: *std.Io.Writer, argv: []const []const u8) !CliOptions {
i += 1;
continue;
}
if (std.mem.eql(u8, value, "--json-diagnostics")) {
options.json_diagnostics = true;
i += 1;
continue;
}
return error.InvalidCli;
}

Expand Down
33 changes: 29 additions & 4 deletions test/conformance/reject/container_children.diag
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
/workspace/hyperdoc/test/conformance/reject/container_children.hdoc:5:5: Node not allowed here.
/workspace/hyperdoc/test/conformance/reject/container_children.hdoc:4:3: Node requires list body.
/workspace/hyperdoc/test/conformance/reject/container_children.hdoc:10:3: Node not allowed here.
error: failed to parse "/workspace/hyperdoc/test/conformance/reject/container_children.hdoc": InvalidFile
[
{
"code": {
"illegal_child_item": {}
},
"location": {
"line": 5,
"column": 5
}
},
{
"code": {
"list_body_required": {}
},
"location": {
"line": 4,
"column": 3
}
},
{
"code": {
"illegal_child_item": {}
},
"location": {
"line": 10,
"column": 3
}
}
]
65 changes: 59 additions & 6 deletions test/conformance/reject/heading_sequence.diag
Original file line number Diff line number Diff line change
@@ -1,6 +1,59 @@
/workspace/hyperdoc/test/conformance/reject/heading_sequence.hdoc:3:1: h3 requires a preceding h2.
/workspace/hyperdoc/test/conformance/reject/heading_sequence.hdoc:5:1: h3 requires a preceding h2.
/workspace/hyperdoc/test/conformance/reject/heading_sequence.hdoc:3:1: Inserted automatic h1 to fill heading level gap.
/workspace/hyperdoc/test/conformance/reject/heading_sequence.hdoc:3:1: Inserted automatic h2 to fill heading level gap.
/workspace/hyperdoc/test/conformance/reject/heading_sequence.hdoc:5:1: Inserted automatic h2 to fill heading level gap.
error: failed to parse "/workspace/hyperdoc/test/conformance/reject/heading_sequence.hdoc": InvalidFile
[
{
"code": {
"invalid_heading_sequence": {
"level": "h3",
"missing": "h2"
}
},
"location": {
"line": 3,
"column": 1
}
},
{
"code": {
"invalid_heading_sequence": {
"level": "h3",
"missing": "h2"
}
},
"location": {
"line": 5,
"column": 1
}
},
{
"code": {
"automatic_heading_insertion": {
"level": "h1"
}
},
"location": {
"line": 3,
"column": 1
}
},
{
"code": {
"automatic_heading_insertion": {
"level": "h2"
}
},
"location": {
"line": 3,
"column": 1
}
},
{
"code": {
"automatic_heading_insertion": {
"level": "h2"
}
},
"location": {
"line": 5,
"column": 1
}
}
]
15 changes: 13 additions & 2 deletions test/conformance/reject/inline_identifier_dash.diag
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
/workspace/hyperdoc/test/conformance/reject/inline_identifier_dash.hdoc:3:9: Invalid identifier character: '-'.
error: failed to parse "/workspace/hyperdoc/test/conformance/reject/inline_identifier_dash.hdoc": SyntaxError
[
{
"code": {
"invalid_identifier_character": {
"char": 45
}
},
"location": {
"line": 3,
"column": 9
}
}
]
13 changes: 11 additions & 2 deletions test/conformance/reject/nested_top_level.diag
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/workspace/hyperdoc/test/conformance/reject/nested_top_level.hdoc:4:3: Node not allowed here.
error: failed to parse "/workspace/hyperdoc/test/conformance/reject/nested_top_level.hdoc": InvalidFile
[
{
"code": {
"illegal_child_item": {}
},
"location": {
"line": 4,
"column": 3
}
}
]
15 changes: 13 additions & 2 deletions test/conformance/reject/ref_in_heading.diag
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
/workspace/hyperdoc/test/conformance/reject/ref_in_heading.hdoc:5:14: \\ref is not allowed in this context.
error: failed to parse "/workspace/hyperdoc/test/conformance/reject/ref_in_heading.hdoc": InvalidFile
[
{
"code": {
"inline_not_allowed": {
"node_type": "\\ref"
}
},
"location": {
"line": 5,
"column": 14
}
}
]
15 changes: 13 additions & 2 deletions test/conformance/reject/string_cr_escape.diag
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
/workspace/hyperdoc/test/conformance/reject/string_cr_escape.hdoc:3:8: Forbidden control character U+000D.
error: failed to parse "/workspace/hyperdoc/test/conformance/reject/string_cr_escape.hdoc": InvalidFile
[
{
"code": {
"illegal_character": {
"codepoint": 13
}
},
"location": {
"line": 3,
"column": 8
}
}
]
13 changes: 11 additions & 2 deletions test/conformance/reject/time_relative_fmt.diag
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
/workspace/hyperdoc/test/conformance/reject/time_relative_fmt.hdoc:3:15: Invalid 'fmt' value for date/time.
error: failed to parse "/workspace/hyperdoc/test/conformance/reject/time_relative_fmt.hdoc": InvalidFile
[
{
"code": {
"invalid_date_time_fmt": {}
},
"location": {
"line": 3,
"column": 15
}
}
]