Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a warning for duplicate siblings #20

Open
philshafer opened this issue Jan 6, 2015 · 2 comments
Open

Add a warning for duplicate siblings #20

philshafer opened this issue Jan 6, 2015 · 2 comments
Assignees

Comments

@philshafer
Copy link

From Stefan Esser:

Add a warning for duplicate siblings:

Any name must be only used once for all children of some node, either

  • for a leaf node (xo_emit)

  • for a container node

  • for a list (all instances in a contiguous list)

    If use of a name has completed (end of list, container or leaf) no
    further list, container or leaf is allowed to use the same name for
    a node belonging to the same parent.

@philshafer philshafer self-assigned this Jan 6, 2015
@philshafer
Copy link
Author

Thanks! IMO, the semantics should be:

Start with a namelist that contains one element with empty name.
For each new node to be generated:
{

  • If the test is called for an xo_emit() that does not actually
    generate a JSON or XML node, no test is performed (it may or may not
    contain a valid node name).
  • For xo_emit, open_container or open_list check that the name of the
    node is not yet in the namelist.
    • If the name is found: WARN about duplicate use of this name.
  • For open_instance, the name of the instance must match the name in
    the first element of the namelist.
    • If the name differs: WARN about illegal other nodes in the xo_list.
  • Each xo_emit, open_container, open_list or open_instance puts its
    name into the element at the beginning of the namelist (which must
    be empty or in the case of an instance or leaf list may already
    contain that name).
    • If not empty or identical to instance name: WARN
  • Whenever a leaf, container or list is closed, an empty element is
    inserted at the beginning of the namelist. Leafs are implicitly
    closed (and an empty element inserted), unless the leaf is part of
    a leaf list (in which case the close_list will insert the empty
    element at the head of the namelist).
    }

When the xo_stack depth is reduced, the first element of the namelist
must be empty:

  • If not empty: WARN that some xo_close call is missing.

@stesser
Copy link

stesser commented Jan 7, 2015

I'm wondering whether another test should be added after the test for open_instance:
If xo_emit() is used with the "l" modifier, then the key/tag name should be the same as that of a previous open_list. I.e., the test for leaf list elements should be identical to the test for instances.

In addition, a test should be added to prevent mixing of instances and leaf list elements of the same name in one list, as would be generated by:
xo_open_list("item");
xo_open_instance("item");
xo_close_instance("item");
xo_emit("{l:item/value}");
xo_close_list("item");

While both instances and leaf list elements are allowed in lists, the above would lead to bad JSON output.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants