-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix using
optional
between numbers; forbid duplicate and empty stri…
…ngs 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.
- Loading branch information
1 parent
ce30554
commit e721269
Showing
8 changed files
with
117 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters