You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fix using optional between numbers; forbid duplicate and empty strings in tries (#362)
Fix not being able to parse some separator-free formatsу
The reproducer was:
```
offsetHours(Padding.NONE)
optional {
optional { char(':') }
offsetMinutesOfHour()
}
```
This showed us one bug and one inefficiency, both of which are
fixed here.
Inefficiency: the `optional { char(':') }` should for all intents
and purposes be equivalent to
`alternativeParsing({ char(':') }) { }`: both the empty string and
the `:` should be parsed, and, according to `optional`'s
definition, if none of the fields mentioned in the block are
non-zero, nothing should be output. However, such `optional` still
created a fake parser element that notified all the fields that
they are zero when an empty string is parsed, even though there are
no fields.
Bug: the fake parser element that notifies the fields that they
are zero even though nothing of note was parsed interfered with the
mechanism supporting compact formats. Number parsers are greedy,
so `number(hh); number(mm)` gets merged into `number(hhmm)`.
If there is something between them, this merge can't happen:
`number(hh); string("x"); number(mm)`.
For this reason, parsers that don't accept any strings are
forbidden (or just very unlikely to happen)--except for the
zero-width unconditional modification parser. This bug is fixed by
moving such parsers to the end of the parser:
`number(hh); modification(); number(mm); string("x")` will get
transformed to `number(hhmm); string("x"); modification()`.
To further improve the robustness of the parser, we revisited other
places where zero-width parsers were possible and forbade them:
now, AM/PM markers, month names, and day-of-week names can't
be empty. This limitation can be lifted at a later point, but it wouldn't
be easy.
While we were at it, we also require distinct month names,
day-of-week names, and AM/PM markers, just because we were
near that place in the code.
0 commit comments