Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
pwbh committed Sep 7, 2024
1 parent fac70f3 commit 7146a0a
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
24 changes: 16 additions & 8 deletions src/root.zig
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ pub fn Ymlz(comptime Destination: type) type {
},
.Pointer => {
if (actual_type_info.Pointer.size == .Slice and actual_type_info.Pointer.child == u8) {
@field(destination, field.name) = try self.parseStringExpression(raw_line, depth);
@field(destination, field.name) = try self.parseStringExpression(raw_line, depth, false);
} else if (actual_type_info.Pointer.size == .Slice and (actual_type_info.Pointer.child == []const u8 or actual_type_info.Pointer.child == []u8)) {
@field(destination, field.name) = try self.parseStringArrayExpression(actual_type_info.Pointer.child, depth + 1);
} else if (actual_type_info.Pointer.size == .Slice and @typeInfo(actual_type_info.Pointer.child) != .Pointer) {
Expand Down Expand Up @@ -333,7 +333,7 @@ pub fn Ymlz(comptime Destination: type) type {
break;
}

const result = try self.parseStringExpression(raw_value_line, depth);
const result = try self.parseStringExpression(raw_value_line, depth, false);

try list.append(result);
}
Expand Down Expand Up @@ -362,8 +362,8 @@ pub fn Ymlz(comptime Destination: type) type {
return try list.toOwnedSlice();
}

fn parseStringExpression(self: *Self, raw_line: []const u8, depth: usize) ![]const u8 {
const expression = try self.parseSimpleExpression(raw_line, depth);
fn parseStringExpression(self: *Self, raw_line: []const u8, depth: usize, is_multiline: bool) ![]const u8 {
const expression = try self.parseSimpleExpression(raw_line, depth, is_multiline);
const value = self.getExpressionValue(expression);

if (value.len == 0) return value;
Expand Down Expand Up @@ -393,7 +393,7 @@ pub fn Ymlz(comptime Destination: type) type {
break;
}

const expression = try self.parseSimpleExpression(raw_value_line, depth);
const expression = try self.parseSimpleExpression(raw_value_line, depth, true);
const value = self.getExpressionValue(expression);

try list.appendSlice(value);
Expand All @@ -420,7 +420,7 @@ pub fn Ymlz(comptime Destination: type) type {
}

fn parseBooleanExpression(self: *Self, raw_line: []const u8, depth: usize) !bool {
const expression = try self.parseSimpleExpression(raw_line, depth);
const expression = try self.parseSimpleExpression(raw_line, depth, false);
const value = self.getExpressionValue(expression);

const isBooleanTrue = std.mem.eql(u8, value, "True") or std.mem.eql(u8, value, "true") or std.mem.eql(u8, value, "On") or std.mem.eql(u8, value, "on");
Expand All @@ -439,7 +439,7 @@ pub fn Ymlz(comptime Destination: type) type {
}

fn parseNumericExpression(self: *Self, comptime T: type, raw_line: []const u8, depth: usize) !T {
const expression = try self.parseSimpleExpression(raw_line, depth);
const expression = try self.parseSimpleExpression(raw_line, depth, false);
const value = self.getExpressionValue(expression);

switch (@typeInfo(T)) {
Expand All @@ -465,7 +465,7 @@ pub fn Ymlz(comptime Destination: type) type {
return line;
}

fn parseSimpleExpression(self: *Self, raw_line: []const u8, depth: usize) !Expression {
fn parseSimpleExpression(self: *Self, raw_line: []const u8, depth: usize, is_multiline: bool) !Expression {
const indent_depth = self.getIndentDepth(depth);

if (raw_line.len < indent_depth) {
Expand All @@ -475,6 +475,14 @@ pub fn Ymlz(comptime Destination: type) type {
};
}

// NOTE: Need to think about this a bit more, maybe there is a cleaner solution for this.
if (is_multiline) {
return .{
.value = .{ .Simple = raw_line[indent_depth..] },
.raw = raw_line,
};
}

const line = raw_line[indent_depth..];

if (line[0] == '-') {
Expand Down
3 changes: 1 addition & 2 deletions src/tests.zig
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ test "CC74" {
const element = result.elements[0];

try expect(std.mem.eql(u8, element.name, "Spec Example 6.20. Tag Handles"));
std.debug.print("parsed:{s}\n", .{element.dump});
try expect(std.mem.eql(u8, element.dump, "- !<tag:example.com,2000:app/foo> \"bar\""));
try expect(std.mem.eql(u8, element.dump, "--- !<tag:example.com,2000:app/foo> \"bar\"\n"));
}

test "F6MC" {
Expand Down

0 comments on commit 7146a0a

Please sign in to comment.