rename flow_(list|map) to inline_(list|map)
This is simply better word choice.
This commit is contained in:
parent
8dd5463683
commit
25386ac87a
@ -70,7 +70,7 @@ pub const State = struct {
|
|||||||
Value.emptyScalar(),
|
Value.emptyScalar(),
|
||||||
options.duplicate_key_behavior,
|
options.duplicate_key_behavior,
|
||||||
),
|
),
|
||||||
.scalar, .flow_list, .flow_map => {},
|
.scalar, .inline_list, .inline_map => {},
|
||||||
},
|
},
|
||||||
.done => {},
|
.done => {},
|
||||||
}
|
}
|
||||||
@ -110,12 +110,12 @@ pub const State = struct {
|
|||||||
try state.value_stack.append(&state.document.root);
|
try state.value_stack.append(&state.document.root);
|
||||||
state.mode = .value;
|
state.mode = .value;
|
||||||
},
|
},
|
||||||
.flow_list => |str| {
|
.inline_list => |str| {
|
||||||
state.document.root = try state.parseFlow(str, .flow_list, dkb);
|
state.document.root = try state.parseFlow(str, .inline_list, dkb);
|
||||||
state.mode = .done;
|
state.mode = .done;
|
||||||
},
|
},
|
||||||
.flow_map => |str| {
|
.inline_map => |str| {
|
||||||
state.document.root = try state.parseFlow(str, .flow_map, dkb);
|
state.document.root = try state.parseFlow(str, .inline_map, dkb);
|
||||||
state.mode = .done;
|
state.mode = .done;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -129,8 +129,8 @@ pub const State = struct {
|
|||||||
.empty => state.expect_shift = .indent,
|
.empty => state.expect_shift = .indent,
|
||||||
.scalar => |str| try rootlist.append(try Value.fromScalar(arena_alloc, str)),
|
.scalar => |str| try rootlist.append(try Value.fromScalar(arena_alloc, str)),
|
||||||
.line_string, .concat_string => |str| try rootlist.append(try Value.fromString(arena_alloc, str)),
|
.line_string, .concat_string => |str| try rootlist.append(try Value.fromString(arena_alloc, str)),
|
||||||
.flow_list => |str| try rootlist.append(try state.parseFlow(str, .flow_list, dkb)),
|
.inline_list => |str| try rootlist.append(try state.parseFlow(str, .inline_list, dkb)),
|
||||||
.flow_map => |str| try rootlist.append(try state.parseFlow(str, .flow_map, dkb)),
|
.inline_map => |str| try rootlist.append(try state.parseFlow(str, .inline_map, dkb)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.map_item => |pair| {
|
.map_item => |pair| {
|
||||||
@ -147,21 +147,25 @@ pub const State = struct {
|
|||||||
},
|
},
|
||||||
.scalar => |str| try rootmap.put(dupekey, try Value.fromScalar(arena_alloc, str)),
|
.scalar => |str| try rootmap.put(dupekey, try Value.fromScalar(arena_alloc, str)),
|
||||||
.line_string, .concat_string => |str| try rootmap.put(dupekey, try Value.fromString(arena_alloc, str)),
|
.line_string, .concat_string => |str| try rootmap.put(dupekey, try Value.fromString(arena_alloc, str)),
|
||||||
.flow_list => |str| try rootmap.put(dupekey, try state.parseFlow(str, .flow_list, dkb)),
|
.inline_list => |str| try rootmap.put(dupekey, try state.parseFlow(str, .inline_list, dkb)),
|
||||||
.flow_map => |str| try rootmap.put(dupekey, try state.parseFlow(str, .flow_map, dkb)),
|
.inline_map => |str| try rootmap.put(dupekey, try state.parseFlow(str, .inline_map, dkb)),
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.value => switch (state.value_stack.getLast().*) {
|
.value => switch (state.value_stack.getLast().*) {
|
||||||
// these three states are never reachable here. flow_list and
|
// these three states are never reachable here. inline_list and
|
||||||
// flow_map are parsed with a separate state machine. These
|
// inline_map are parsed with a separate state machine. These
|
||||||
// value types can only be present by themselves as the first
|
// value types can only be present by themselves as the first
|
||||||
// line of the document, in which case the document consists
|
// line of the document, in which case the document consists
|
||||||
// only of that single line: this parser jumps immediately into
|
// only of that single line: this parser jumps immediately into
|
||||||
// the .done state, bypassing the .value state in which this
|
// the .done state, bypassing the .value state in which this
|
||||||
// switch is embedded.
|
// switch is embedded.
|
||||||
.scalar, .flow_list, .flow_map => return error.Fail,
|
.scalar, .inline_list, .inline_map => {
|
||||||
|
state.diagnostics.length = 1;
|
||||||
|
state.diagnostics.message = "the document contains invalid data following a single-line value";
|
||||||
|
return error.Fail;
|
||||||
|
},
|
||||||
.string => |*string| {
|
.string => |*string| {
|
||||||
if (line.shift == .indent) {
|
if (line.shift == .indent) {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
@ -246,8 +250,8 @@ pub const State = struct {
|
|||||||
switch (in_line) {
|
switch (in_line) {
|
||||||
.empty => unreachable,
|
.empty => unreachable,
|
||||||
.scalar => |str| try list.append(try Value.fromScalar(arena_alloc, str)),
|
.scalar => |str| try list.append(try Value.fromScalar(arena_alloc, str)),
|
||||||
.flow_list => |str| try list.append(try state.parseFlow(str, .flow_list, dkb)),
|
.inline_list => |str| try list.append(try state.parseFlow(str, .inline_list, dkb)),
|
||||||
.flow_map => |str| try list.append(try state.parseFlow(str, .flow_map, dkb)),
|
.inline_map => |str| try list.append(try state.parseFlow(str, .inline_map, dkb)),
|
||||||
.line_string, .concat_string => |str| {
|
.line_string, .concat_string => |str| {
|
||||||
const new_string = try appendListGetValue(list, Value.emptyString());
|
const new_string = try appendListGetValue(list, Value.emptyString());
|
||||||
try state.string_builder.appendSlice(arena_alloc, str);
|
try state.string_builder.appendSlice(arena_alloc, str);
|
||||||
@ -263,8 +267,8 @@ pub const State = struct {
|
|||||||
.empty => state.expect_shift = .indent,
|
.empty => state.expect_shift = .indent,
|
||||||
.scalar => |str| try list.append(try Value.fromScalar(arena_alloc, str)),
|
.scalar => |str| try list.append(try Value.fromScalar(arena_alloc, str)),
|
||||||
.line_string, .concat_string => |str| try list.append(try Value.fromString(arena_alloc, str)),
|
.line_string, .concat_string => |str| try list.append(try Value.fromString(arena_alloc, str)),
|
||||||
.flow_list => |str| try list.append(try state.parseFlow(str, .flow_list, dkb)),
|
.inline_list => |str| try list.append(try state.parseFlow(str, .inline_list, dkb)),
|
||||||
.flow_map => |str| try list.append(try state.parseFlow(str, .flow_map, dkb)),
|
.inline_map => |str| try list.append(try state.parseFlow(str, .inline_map, dkb)),
|
||||||
}
|
}
|
||||||
} else if (line.shift == .indent) {
|
} else if (line.shift == .indent) {
|
||||||
if (state.expect_shift != .indent) return error.UnexpectedIndent;
|
if (state.expect_shift != .indent) return error.UnexpectedIndent;
|
||||||
@ -345,9 +349,9 @@ pub const State = struct {
|
|||||||
switch (in_line) {
|
switch (in_line) {
|
||||||
.empty => unreachable,
|
.empty => unreachable,
|
||||||
.scalar => |str| try state.putMap(map, state.dangling_key.?, try Value.fromScalar(arena_alloc, str), dkb),
|
.scalar => |str| try state.putMap(map, state.dangling_key.?, try Value.fromScalar(arena_alloc, str), dkb),
|
||||||
.flow_list => |str| try state.putMap(map, state.dangling_key.?, try state.parseFlow(str, .flow_list, dkb), dkb),
|
.inline_list => |str| try state.putMap(map, state.dangling_key.?, try state.parseFlow(str, .inline_list, dkb), dkb),
|
||||||
.flow_map => |str| {
|
.inline_map => |str| {
|
||||||
try state.putMap(map, state.dangling_key.?, try state.parseFlow(str, .flow_map, dkb), dkb);
|
try state.putMap(map, state.dangling_key.?, try state.parseFlow(str, .inline_map, dkb), dkb);
|
||||||
},
|
},
|
||||||
.line_string, .concat_string => |str| {
|
.line_string, .concat_string => |str| {
|
||||||
// string pushes the stack
|
// string pushes the stack
|
||||||
@ -392,8 +396,8 @@ pub const State = struct {
|
|||||||
},
|
},
|
||||||
.scalar => |str| try state.putMap(map, dupekey, try Value.fromScalar(arena_alloc, str), dkb),
|
.scalar => |str| try state.putMap(map, dupekey, try Value.fromScalar(arena_alloc, str), dkb),
|
||||||
.line_string, .concat_string => |str| try state.putMap(map, dupekey, try Value.fromString(arena_alloc, str), dkb),
|
.line_string, .concat_string => |str| try state.putMap(map, dupekey, try Value.fromString(arena_alloc, str), dkb),
|
||||||
.flow_list => |str| try state.putMap(map, dupekey, try state.parseFlow(str, .flow_list, dkb), dkb),
|
.inline_list => |str| try state.putMap(map, dupekey, try state.parseFlow(str, .inline_list, dkb), dkb),
|
||||||
.flow_map => |str| try state.putMap(map, dupekey, try state.parseFlow(str, .flow_map, dkb), dkb),
|
.inline_map => |str| try state.putMap(map, dupekey, try state.parseFlow(str, .inline_map, dkb), dkb),
|
||||||
}
|
}
|
||||||
} else if (line.shift == .indent) {
|
} else if (line.shift == .indent) {
|
||||||
if (state.expect_shift != .indent or state.dangling_key == null) {
|
if (state.expect_shift != .indent or state.dangling_key == null) {
|
||||||
@ -432,17 +436,17 @@ pub const State = struct {
|
|||||||
const arena_alloc = state.document.arena.allocator();
|
const arena_alloc = state.document.arena.allocator();
|
||||||
|
|
||||||
var root: Value = switch (root_type) {
|
var root: Value = switch (root_type) {
|
||||||
.flow_list => Value.newFlowList(arena_alloc),
|
.inline_list => Value.newFlowList(arena_alloc),
|
||||||
.flow_map => Value.newFlowMap(arena_alloc),
|
.inline_map => Value.newFlowMap(arena_alloc),
|
||||||
else => {
|
else => {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
state.diagnostics.message = "the flow item was closed too many times";
|
state.diagnostics.message = "the inline map or list was closed too many times";
|
||||||
return error.BadState;
|
return error.BadState;
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
var pstate: FlowParseState = switch (root_type) {
|
var pstate: FlowParseState = switch (root_type) {
|
||||||
.flow_list => .want_list_item,
|
.inline_list => .want_list_item,
|
||||||
.flow_map => .want_map_key,
|
.inline_map => .want_map_key,
|
||||||
else => unreachable,
|
else => unreachable,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -460,14 +464,14 @@ pub const State = struct {
|
|||||||
',' => {
|
',' => {
|
||||||
// empty value
|
// empty value
|
||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
try tip.flow_list.append(Value.emptyScalar());
|
try tip.inline_list.append(Value.emptyScalar());
|
||||||
item_start = idx + 1;
|
item_start = idx + 1;
|
||||||
},
|
},
|
||||||
'{' => {
|
'{' => {
|
||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
|
|
||||||
const new_map = try appendListGetValue(
|
const new_map = try appendListGetValue(
|
||||||
&tip.flow_list,
|
&tip.inline_list,
|
||||||
Value.newFlowMap(arena_alloc),
|
Value.newFlowMap(arena_alloc),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -479,7 +483,7 @@ pub const State = struct {
|
|||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
|
|
||||||
const new_list = try appendListGetValue(
|
const new_list = try appendListGetValue(
|
||||||
&tip.flow_list,
|
&tip.inline_list,
|
||||||
Value.newFlowList(arena_alloc),
|
Value.newFlowList(arena_alloc),
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -490,11 +494,11 @@ pub const State = struct {
|
|||||||
']' => {
|
']' => {
|
||||||
const finished = state.value_stack.getLastOrNull() orelse {
|
const finished = state.value_stack.getLastOrNull() orelse {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
state.diagnostics.message = "the flow list was closed too many times";
|
state.diagnostics.message = "the inline list was closed too many times";
|
||||||
return error.BadState;
|
return error.BadState;
|
||||||
};
|
};
|
||||||
if (finished.flow_list.items.len > 0 or idx > item_start)
|
if (finished.inline_list.items.len > 0 or idx > item_start)
|
||||||
try finished.flow_list.append(Value.emptyScalar());
|
try finished.inline_list.append(Value.emptyScalar());
|
||||||
pstate = try state.popFlowStack();
|
pstate = try state.popFlowStack();
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
@ -514,7 +518,7 @@ pub const State = struct {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
try tip.flow_list.append(
|
try tip.inline_list.append(
|
||||||
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
||||||
);
|
);
|
||||||
item_start = idx + 1;
|
item_start = idx + 1;
|
||||||
@ -533,10 +537,10 @@ pub const State = struct {
|
|||||||
|
|
||||||
const finished = state.value_stack.getLastOrNull() orelse {
|
const finished = state.value_stack.getLastOrNull() orelse {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
state.diagnostics.message = "the flow list was closed too many times";
|
state.diagnostics.message = "the inline list was closed too many times";
|
||||||
return error.BadState;
|
return error.BadState;
|
||||||
};
|
};
|
||||||
try finished.flow_list.append(
|
try finished.inline_list.append(
|
||||||
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
||||||
);
|
);
|
||||||
pstate = try state.popFlowStack();
|
pstate = try state.popFlowStack();
|
||||||
@ -553,19 +557,19 @@ pub const State = struct {
|
|||||||
']' => pstate = try state.popFlowStack(),
|
']' => pstate = try state.popFlowStack(),
|
||||||
else => return {
|
else => return {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
state.diagnostics.message = "the document contains an invalid flow list separator";
|
state.diagnostics.message = "the document contains an invalid inline list separator";
|
||||||
return error.BadToken;
|
return error.BadToken;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
.want_map_key => switch (char) {
|
.want_map_key => switch (char) {
|
||||||
' ' => continue :charloop,
|
' ' => continue :charloop,
|
||||||
'\t' => return error.IllegalTabWhitespaceInLine,
|
'\t' => return error.IllegalTabWhitespaceInLine,
|
||||||
// forbid these characters so that flow dictionary keys cannot start
|
// forbid these characters so that inline dictionary keys cannot start
|
||||||
// with characters that regular dictionary keys cannot start with
|
// with characters that regular dictionary keys cannot start with
|
||||||
// (even though they're unambiguous in this specific context).
|
// (even though they're unambiguous in this specific context).
|
||||||
'{', '[', '#', '-', '>', '|', ',' => return {
|
'{', '[', '#', '-', '>', '|', ',' => return {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
state.diagnostics.message = "this document contains a flow map key that starts with an invalid character";
|
state.diagnostics.message = "this document contains a inline map key that starts with an invalid sequence";
|
||||||
return error.BadToken;
|
return error.BadToken;
|
||||||
},
|
},
|
||||||
':' => {
|
':' => {
|
||||||
@ -600,7 +604,7 @@ pub const State = struct {
|
|||||||
',' => {
|
',' => {
|
||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
try state.putMap(
|
try state.putMap(
|
||||||
&tip.flow_map,
|
&tip.inline_map,
|
||||||
dangling_key.?,
|
dangling_key.?,
|
||||||
Value.emptyScalar(),
|
Value.emptyScalar(),
|
||||||
dkb,
|
dkb,
|
||||||
@ -613,7 +617,7 @@ pub const State = struct {
|
|||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
|
|
||||||
const new_list = try state.putMapGetValue(
|
const new_list = try state.putMapGetValue(
|
||||||
&tip.flow_map,
|
&tip.inline_map,
|
||||||
dangling_key.?,
|
dangling_key.?,
|
||||||
Value.newFlowList(arena_alloc),
|
Value.newFlowList(arena_alloc),
|
||||||
dkb,
|
dkb,
|
||||||
@ -628,7 +632,7 @@ pub const State = struct {
|
|||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
|
|
||||||
const new_map = try state.putMapGetValue(
|
const new_map = try state.putMapGetValue(
|
||||||
&tip.flow_map,
|
&tip.inline_map,
|
||||||
dangling_key.?,
|
dangling_key.?,
|
||||||
Value.newFlowMap(arena_alloc),
|
Value.newFlowMap(arena_alloc),
|
||||||
dkb,
|
dkb,
|
||||||
@ -642,7 +646,7 @@ pub const State = struct {
|
|||||||
// the value is an empty string and this map is closed
|
// the value is an empty string and this map is closed
|
||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
try state.putMap(
|
try state.putMap(
|
||||||
&tip.flow_map,
|
&tip.inline_map,
|
||||||
dangling_key.?,
|
dangling_key.?,
|
||||||
Value.emptyScalar(),
|
Value.emptyScalar(),
|
||||||
dkb,
|
dkb,
|
||||||
@ -669,7 +673,7 @@ pub const State = struct {
|
|||||||
|
|
||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
try state.putMap(
|
try state.putMap(
|
||||||
&tip.flow_map,
|
&tip.inline_map,
|
||||||
dangling_key.?,
|
dangling_key.?,
|
||||||
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
||||||
dkb,
|
dkb,
|
||||||
@ -689,7 +693,7 @@ pub const State = struct {
|
|||||||
|
|
||||||
const tip = try state.getStackTip();
|
const tip = try state.getStackTip();
|
||||||
try state.putMap(
|
try state.putMap(
|
||||||
&tip.flow_map,
|
&tip.inline_map,
|
||||||
dangling_key.?,
|
dangling_key.?,
|
||||||
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
try Value.fromScalar(arena_alloc, contents[item_start..end]),
|
||||||
dkb,
|
dkb,
|
||||||
@ -706,7 +710,7 @@ pub const State = struct {
|
|||||||
'}' => pstate = try state.popFlowStack(),
|
'}' => pstate = try state.popFlowStack(),
|
||||||
else => return {
|
else => return {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
state.diagnostics.message = "this document contains an invalid character instead of a flow map separator";
|
state.diagnostics.message = "this document contains an invalid character instead of a inline map separator";
|
||||||
return error.BadToken;
|
return error.BadToken;
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -722,7 +726,7 @@ pub const State = struct {
|
|||||||
// we ran out of characters while still in the middle of an object
|
// we ran out of characters while still in the middle of an object
|
||||||
if (pstate != .done) return {
|
if (pstate != .done) return {
|
||||||
state.diagnostics.length = 1;
|
state.diagnostics.length = 1;
|
||||||
state.diagnostics.message = "this document contains an unterminated flow item";
|
state.diagnostics.message = "this document contains an unterminated inline map or list";
|
||||||
return error.BadState;
|
return error.BadState;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -747,8 +751,8 @@ pub const State = struct {
|
|||||||
const parent = state.value_stack.getLastOrNull() orelse return .done;
|
const parent = state.value_stack.getLastOrNull() orelse return .done;
|
||||||
|
|
||||||
return switch (parent.*) {
|
return switch (parent.*) {
|
||||||
.flow_list => .want_list_separator,
|
.inline_list => .want_list_separator,
|
||||||
.flow_map => .want_map_separator,
|
.inline_map => .want_map_separator,
|
||||||
else => .done,
|
else => .done,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -49,9 +49,9 @@ pub const Value = union(enum) {
|
|||||||
scalar: String,
|
scalar: String,
|
||||||
string: String,
|
string: String,
|
||||||
list: List,
|
list: List,
|
||||||
flow_list: List,
|
inline_list: List,
|
||||||
map: Map,
|
map: Map,
|
||||||
flow_map: Map,
|
inline_map: Map,
|
||||||
|
|
||||||
pub fn convertTo(self: Value, comptime T: type, allocator: std.mem.Allocator, options: Options) !T {
|
pub fn convertTo(self: Value, comptime T: type, allocator: std.mem.Allocator, options: Options) !T {
|
||||||
switch (@typeInfo(T)) {
|
switch (@typeInfo(T)) {
|
||||||
@ -104,7 +104,7 @@ pub const Value = union(enum) {
|
|||||||
// TODO: This also doesn't handle sentinels properly.
|
// TODO: This also doesn't handle sentinels properly.
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.scalar, .string => |str| return if (ptr.child == u8) str else error.BadValue,
|
.scalar, .string => |str| return if (ptr.child == u8) str else error.BadValue,
|
||||||
.list, .flow_list => |lst| {
|
.list, .inline_list => |lst| {
|
||||||
var result = try std.ArrayList(ptr.child).initCapacity(allocator, lst.items.len);
|
var result = try std.ArrayList(ptr.child).initCapacity(allocator, lst.items.len);
|
||||||
errdefer result.deinit();
|
errdefer result.deinit();
|
||||||
for (lst.items) |item| {
|
for (lst.items) |item| {
|
||||||
@ -138,7 +138,7 @@ pub const Value = union(enum) {
|
|||||||
return result;
|
return result;
|
||||||
} else return error.BadValue;
|
} else return error.BadValue;
|
||||||
},
|
},
|
||||||
.list, .flow_list => |lst| {
|
.list, .inline_list => |lst| {
|
||||||
var storage = try std.ArrayList(arr.child).initCapacity(allocator, arr.len);
|
var storage = try std.ArrayList(arr.child).initCapacity(allocator, arr.len);
|
||||||
defer storage.deinit();
|
defer storage.deinit();
|
||||||
for (lst.items) |item| {
|
for (lst.items) |item| {
|
||||||
@ -158,7 +158,7 @@ pub const Value = union(enum) {
|
|||||||
|
|
||||||
if (stt.is_tuple) {
|
if (stt.is_tuple) {
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.list, .flow_list => |list| {
|
.list, .inline_list => |list| {
|
||||||
if (list.items.len != stt.fields.len) return error.BadValue;
|
if (list.items.len != stt.fields.len) return error.BadValue;
|
||||||
var result: T = undefined;
|
var result: T = undefined;
|
||||||
inline for (stt.fields, 0..) |field, idx| {
|
inline for (stt.fields, 0..) |field, idx| {
|
||||||
@ -171,7 +171,7 @@ pub const Value = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.map, .flow_map => |map| {
|
.map, .inline_map => |map| {
|
||||||
var result: T = undefined;
|
var result: T = undefined;
|
||||||
|
|
||||||
if (options.ignore_extra_fields) {
|
if (options.ignore_extra_fields) {
|
||||||
@ -232,7 +232,7 @@ pub const Value = union(enum) {
|
|||||||
if (unn.tag_type == null) @compileError("Cannot deserialize into untagged union " ++ @typeName(T));
|
if (unn.tag_type == null) @compileError("Cannot deserialize into untagged union " ++ @typeName(T));
|
||||||
|
|
||||||
switch (self) {
|
switch (self) {
|
||||||
.map, .flow_map => |map| {
|
.map, .inline_map => |map| {
|
||||||
// a union may not ever be deserialized from a map with more than one value
|
// a union may not ever be deserialized from a map with more than one value
|
||||||
if (map.count() != 1) return error.BadValue;
|
if (map.count() != 1) return error.BadValue;
|
||||||
const key = map.keys()[0];
|
const key = map.keys()[0];
|
||||||
@ -289,7 +289,7 @@ pub const Value = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn newFlowList(alloc: std.mem.Allocator) Value {
|
pub inline fn newFlowList(alloc: std.mem.Allocator) Value {
|
||||||
return .{ .flow_list = List.init(alloc) };
|
return .{ .inline_list = List.init(alloc) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn newMap(alloc: std.mem.Allocator) Value {
|
pub inline fn newMap(alloc: std.mem.Allocator) Value {
|
||||||
@ -297,21 +297,21 @@ pub const Value = union(enum) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub inline fn newFlowMap(alloc: std.mem.Allocator) Value {
|
pub inline fn newFlowMap(alloc: std.mem.Allocator) Value {
|
||||||
return .{ .flow_map = Map.init(alloc) };
|
return .{ .inline_map = Map.init(alloc) };
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn recursiveEqualsExact(self: Value, other: Value) bool {
|
pub fn recursiveEqualsExact(self: Value, other: Value) bool {
|
||||||
if (@as(TagType, self) != other) return false;
|
if (@as(TagType, self) != other) return false;
|
||||||
switch (self) {
|
switch (self) {
|
||||||
inline .scalar, .string => |str, tag| return std.mem.eql(u8, str, @field(other, @tagName(tag))),
|
inline .scalar, .string => |str, tag| return std.mem.eql(u8, str, @field(other, @tagName(tag))),
|
||||||
inline .list, .flow_list => |lst, tag| {
|
inline .list, .inline_list => |lst, tag| {
|
||||||
const olst = @field(other, @tagName(tag));
|
const olst = @field(other, @tagName(tag));
|
||||||
|
|
||||||
if (lst.items.len != olst.items.len) return false;
|
if (lst.items.len != olst.items.len) return false;
|
||||||
for (lst.items, olst.items) |this, that| if (!this.recursiveEqualsExact(that)) return false;
|
for (lst.items, olst.items) |this, that| if (!this.recursiveEqualsExact(that)) return false;
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
inline .map, .flow_map => |map, tag| {
|
inline .map, .inline_map => |map, tag| {
|
||||||
const omap = @field(other, @tagName(tag));
|
const omap = @field(other, @tagName(tag));
|
||||||
|
|
||||||
if (map.count() != omap.count()) return false;
|
if (map.count() != omap.count()) return false;
|
||||||
@ -355,7 +355,7 @@ pub const Value = union(enum) {
|
|||||||
std.debug.print("{s}", .{str});
|
std.debug.print("{s}", .{str});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
.list, .flow_list => |list| {
|
.list, .inline_list => |list| {
|
||||||
if (list.items.len == 0) {
|
if (list.items.len == 0) {
|
||||||
std.debug.print("[]", .{});
|
std.debug.print("[]", .{});
|
||||||
return;
|
return;
|
||||||
@ -372,7 +372,7 @@ pub const Value = union(enum) {
|
|||||||
.{ .empty = "", .indent = indent },
|
.{ .empty = "", .indent = indent },
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
.map, .flow_map => |map| {
|
.map, .inline_map => |map| {
|
||||||
if (map.count() == 0) {
|
if (map.count() == 0) {
|
||||||
std.debug.print("{{}}", .{});
|
std.debug.print("{{}}", .{});
|
||||||
return;
|
return;
|
||||||
|
@ -25,8 +25,8 @@ pub const InlineItem = union(enum) {
|
|||||||
line_string: []const u8,
|
line_string: []const u8,
|
||||||
concat_string: []const u8,
|
concat_string: []const u8,
|
||||||
|
|
||||||
flow_list: []const u8,
|
inline_list: []const u8,
|
||||||
flow_map: []const u8,
|
inline_map: []const u8,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const LineContents = union(enum) {
|
pub const LineContents = union(enum) {
|
||||||
@ -304,23 +304,23 @@ pub fn LineTokenizer(comptime Buffer: type) type {
|
|||||||
if (buf.len - start < 2 or buf[buf.len - 1] != ']') {
|
if (buf.len - start < 2 or buf[buf.len - 1] != ']') {
|
||||||
self.buffer.diag().line_offset = 0;
|
self.buffer.diag().line_offset = 0;
|
||||||
self.buffer.diag().length = 1;
|
self.buffer.diag().length = 1;
|
||||||
self.buffer.diag().message = "this line contains a flow-style list but does not end with the closing character ']'";
|
self.buffer.diag().message = "this line contains a inline list but does not end with the closing character ']'";
|
||||||
return error.BadToken;
|
return error.BadToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep the closing ] for the flow parser
|
// keep the closing ] for the inline parser
|
||||||
return .{ .flow_list = buf[start + 1 ..] };
|
return .{ .inline_list = buf[start + 1 ..] };
|
||||||
},
|
},
|
||||||
'{' => {
|
'{' => {
|
||||||
if (buf.len - start < 2 or buf[buf.len - 1] != '}') {
|
if (buf.len - start < 2 or buf[buf.len - 1] != '}') {
|
||||||
self.buffer.diag().line_offset = 0;
|
self.buffer.diag().line_offset = 0;
|
||||||
self.buffer.diag().length = 1;
|
self.buffer.diag().length = 1;
|
||||||
self.buffer.diag().message = "this line contains a flow-style map but does not end with the closing character '}'";
|
self.buffer.diag().message = "this line contains a inline map but does not end with the closing character '}'";
|
||||||
return error.BadToken;
|
return error.BadToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
// keep the closing } fpr the flow parser
|
// keep the closing } for the inline parser
|
||||||
return .{ .flow_map = buf[start + 1 ..] };
|
return .{ .inline_map = buf[start + 1 ..] };
|
||||||
},
|
},
|
||||||
else => {
|
else => {
|
||||||
if (buf[buf.len - 1] == ' ' or buf[buf.len - 1] == '\t') {
|
if (buf[buf.len - 1] == ' ' or buf[buf.len - 1] == '\t') {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user