parser: empty document should be scalar, not string

I think I originally set this up before I had fully decided on the
semantics of scalars vs strings. This option makes much more sense to
me because it mirrors the empty value behavior map keys. Without an
introducer sequence, it's can't be a string.
This commit is contained in:
torque 2023-12-01 22:31:30 -08:00
parent 0f4a9fcaa7
commit dbf2762982
Signed by: torque
SSH Key Fingerprint: SHA256:nCrXefBNo6EbjNSQhv0nXmEg/VuNq3sMF5b8zETw3Tk
2 changed files with 2 additions and 2 deletions

View File

@ -50,7 +50,7 @@ pub const Options = struct {
// If an empty document is parsed, this defines what value type should be the // If an empty document is parsed, this defines what value type should be the
// resulting document root object. The default behavior is to emit an error if the // resulting document root object. The default behavior is to emit an error if the
// document is empty. // document is empty.
default_object: enum { string, list, map, fail } = .fail, default_object: enum { scalar, list, map, fail } = .fail,
// Only used by the parseTo family of functions. // Only used by the parseTo family of functions.
// If false, and a mapping contains additional keys that do not map to the fields of // If false, and a mapping contains additional keys that do not map to the fields of

View File

@ -59,7 +59,7 @@ pub const State = struct {
switch (state.mode) { switch (state.mode) {
.initial => switch (options.default_object) { .initial => switch (options.default_object) {
.string => state.document.root = Value.emptyString(), .scalar => state.document.root = Value.emptyScalar(),
.list => state.document.root = Value.newList(arena_alloc), .list => state.document.root = Value.newList(arena_alloc),
.map => state.document.root = Value.newMap(arena_alloc), .map => state.document.root = Value.newMap(arena_alloc),
.fail => { .fail => {