libxo icon indicating copy to clipboard operation
libxo copied to clipboard

Add a warning for duplicate siblings

Open philshafer opened this issue 10 years ago • 2 comments

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 avatar Jan 06 '15 05:01 philshafer

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.

philshafer avatar Jan 06 '15 17:01 philshafer

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.

stesser avatar Jan 07 '15 16:01 stesser