Skip to content

inconsistent treatment of negative 0  #95

@gongfarmer

Description

@gongfarmer

The tests have inconsistent requirements for negative zero.

Negative zero in an index selector is invalid:

    {
      "name": "index selector, -0",
      "selector": "$[-0]",
      "invalid_selector": true,
      "tags": [
        "index"
      ]
    },

Negative zero in a filter selector must be handled as zero:

    {
      "name": "filter, equals number, negative zero and zero",
      "selector": "$[[email protected]==-0]",
      "document": [
        {
          "a": 0,
          "d": "e"
        },
        {
          "a": 0.1,
          "d": "f"
        },
        {
          "a": "0",
          "d": "g"
        }
      ],
      "result": [
        {
          "a": 0,
          "d": "e"
        }
      ]
    },

Why?

This inconsistency makes the parser code more complicated.

  • can't just raise an error when the lexer sees "-0", because it might be OK
  • have to defer that decision to the parsing stage and decide whether the -0 is inside an index selector, which is a pain.

Personally I would prefer to just allow negative zero. It's harmless, easy to parse and most "real" languages allow it.
If you are writing a parser that is good enough to detect this error, it is just as easy to treat it as positive zero and move on.

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