Skip to content

Skip (or error) on duplicate keys #12

Open
@planetis-m

Description

@planetis-m

In JSON either action is valid for duplicate keys. Currently we process every duplicate key with a potential performance penalty. A better alternative would be to generate code like:

var
  onceBanana = false
eat(p, tkCurlyLe)
while p.tok != tkCurlyRi:
  if p.tok != tkString:
    raiseParseErr(p, "string literal as key")
  case p.a
  of "banana":
    discard getTok(p)
    eat(p, tkColon)
    if not onceBanana:
      onceBanana = true
      initFromJson(dst.banana, p)
    else:
      when defined(emiDuplicateKey):
        skipJson(p)
      else: raiseParseErr(p, "duplicate object field")
  else:
    raiseParseErr(p, "valid object field")
  if p.tok != tkComma:
    break
  discard getTok(p)
eat(p, tkCurlyRi)

...and leave it up to the user to specify whether it should error or skip them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions