Skip to content

Duplicate fieldset error conflicts with documentation #4

Closed
@bb010g

Description

@bb010g

The analysis.duplicateFieldsetEntryName error seems to conflict with enojs's documentation and API.

Duplicate entries in fieldsets currently always errors out with no way to disable this behavior:

const input = `
languages:
eno = eno notation
json = JavaScript Object Notation
eno = eno notation
`.trim();

if(lastNameInstruction.type === 'FIELDSET') {
if(lastFieldsetEntryNames.has(instruction.name)) {
throw errors.duplicateFieldsetEntryName(context, lastNameInstruction, instruction);
} else {
lastFieldsetEntryNames.add(instruction.name);
}

But Fieldset.elements() would be able to give useful data from its entries if this was allowed to parse, and this example is given as the primary reason for using elements in its documentation:

dialogue:
alice = hi
bob = hey
alice = sup?
bob = nothin'

I think a good compromise would be to start by adding an option that controls for the whole parse whether duplicates error, and perhaps down the line some sort of specification scheme could be added so duplicates can error by default, but selectively can be used.

Alternatively / also, it might be useful in those cases to have entries_associative use array values that are appended to when parsing, so element could error on duplicate elements while normally retrieving the head of the list, but an element_multi method could easily pull out properly ordered values for fieldsets with mostly singular elements but some plural cases.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions