regexp-tree icon indicating copy to clipboard operation
regexp-tree copied to clipboard

Incorrect results when quantifier range unsafe integer

Open tjenkinson opened this issue 3 years ago • 4 comments

E.g

/a{9007199254740993}/

gives

{
  "type": "Quantifier",
  "kind": "Range",
  "from": 9007199254740992,
  "to": 9007199254740992,
  "greedy": true
}

Note 9007199254740992 not 9007199254740993.

I wonder if the parser should throw if !Number.isSafeInteger(x)?

tjenkinson avatar Mar 24 '21 22:03 tjenkinson

Or if numbers this size are actually handled by engines(?) maybe we should also expose a string version of the number

tjenkinson avatar Mar 24 '21 22:03 tjenkinson

Thanks, yeah, this is a weird edge-case. An agual JS regexp is actually generated with correct number /a{9007199254740993,9007199254740993}/, so from the code generator perspective it might be good to support it.

We can probably check if the number is safe, store the number, otherwise a string. Or add the new string fields as you suggests (not obvious though what will be kept in the number field).

DmitrySoshnikov avatar Mar 25 '21 05:03 DmitrySoshnikov

Maybe Bigint could help here? Although it's complicated with it not being supported everywhere.

Could be something like:

  • from: number | null
  • fromBigInt: bigint (if device supports big int)
  • fromString: string

tjenkinson avatar Mar 25 '21 18:03 tjenkinson

Yeah, we need something predictable and working on most of the case. I think we can just make types of the from and to fields to be strings, since we need to support correct code generation, back from having AST.

DmitrySoshnikov avatar Mar 25 '21 23:03 DmitrySoshnikov