Skip to content

Commit

Permalink
Editorial: Remove repeats of grammar productions already in ECMA-262
Browse files Browse the repository at this point in the history
These productions already exist in ECMA-262, sometimes with slightly
different names, and don't need to be separately defined here.
See https://tc39.es/ecma262/#sec-time-zone-offset-strings
  • Loading branch information
ptomato authored and Ms2ger committed Feb 2, 2024
1 parent 23e2d72 commit 7bd3589
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 60 deletions.
22 changes: 10 additions & 12 deletions polyfill/test/validStrings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -188,10 +188,10 @@ function seq(...productions) {
// Grammar productions, based on the grammar in RFC 3339

// characters
const sign = character('+-−');
const temporalSign = character('+-−');
const hour = zeroPaddedInclusive(0, 23, 2);
const minuteSecond = zeroPaddedInclusive(0, 59, 2);
const decimalSeparator = character('.,');
const temporalDecimalSeparator = character('.,');
const daysDesignator = character('Dd');
const hoursDesignator = character('Hh');
const minutesDesignator = character('Mm');
Expand All @@ -206,11 +206,11 @@ const utcDesignator = withCode(character('Zz'), (data) => {
data.z = true;
});
const annotationCriticalFlag = character('!');
const fraction = seq(decimalSeparator, between(1, 9, digit()));
const temporalDecimalFraction = seq(temporalDecimalSeparator, between(1, 9, digit()));

const dateFourDigitYear = repeat(4, digit());

const dateExtendedYear = withSyntaxConstraints(seq(sign, repeat(6, digit())), (result) => {
const dateExtendedYear = withSyntaxConstraints(seq(temporalSign, repeat(6, digit())), (result) => {
if (result === '-000000' || result === '−000000') {
throw new SyntaxError('Negative zero extended year');
}
Expand All @@ -235,15 +235,13 @@ function saveSecond(data, result) {
const timeHour = withCode(hour, saveHour);
const timeMinute = withCode(minuteSecond, saveMinute);
const timeSecond = withCode(choice(minuteSecond, '60'), saveSecond);
const timeFraction = withCode(fraction, (data, result) => {
const timeFraction = withCode(temporalDecimalFraction, (data, result) => {
result = result.slice(1);
const fraction = result.padEnd(9, '0');
data.millisecond = +fraction.slice(0, 3);
data.microsecond = +fraction.slice(3, 6);
data.nanosecond = +fraction.slice(6, 9);
});
const temporalSign = sign;
const temporalDecimalFraction = fraction;
function saveOffset(data, result) {
data.offset = ES.ParseDateTimeUTCOffset(result);
}
Expand All @@ -259,7 +257,7 @@ const utcOffsetSubMinutePrecision = withCode(
saveOffset
);
const dateTimeUTCOffset = choice(utcDesignator, utcOffsetSubMinutePrecision);
const timeZoneUTCOffsetName = seq(sign, hour, choice([minuteSecond], seq(':', minuteSecond)));
const timeZoneUTCOffsetName = seq(temporalSign, hour, choice([minuteSecond], seq(':', minuteSecond)));
const timeZoneIANAName = choice(...timezoneNames);
const timeZoneIdentifier = withCode(
choice(timeZoneUTCOffsetName, timeZoneIANAName),
Expand Down Expand Up @@ -336,22 +334,22 @@ const annotatedMonthDay = withSyntaxConstraints(
}
);

const durationSecondsFraction = withCode(fraction, (data, result) => {
const durationSecondsFraction = withCode(temporalDecimalFraction, (data, result) => {
result = result.slice(1);
const fraction = result.padEnd(9, '0');
data.milliseconds = +fraction.slice(0, 3) * data.factor;
data.microseconds = +fraction.slice(3, 6) * data.factor;
data.nanoseconds = +fraction.slice(6, 9) * data.factor;
});
const durationMinutesFraction = withCode(fraction, (data, result) => {
const durationMinutesFraction = withCode(temporalDecimalFraction, (data, result) => {
result = result.slice(1);
const ns = +result.padEnd(9, '0') * 60;
data.seconds = Math.trunc(ns / 1e9) * data.factor;
data.milliseconds = Math.trunc((ns % 1e9) / 1e6) * data.factor;
data.microseconds = Math.trunc((ns % 1e6) / 1e3) * data.factor;
data.nanoseconds = Math.trunc(ns % 1e3) * data.factor;
});
const durationHoursFraction = withCode(fraction, (data, result) => {
const durationHoursFraction = withCode(temporalDecimalFraction, (data, result) => {
result = result.slice(1);
const ns = +result.padEnd(9, '0') * 3600;
data.minutes = Math.trunc(ns / 6e10) * data.factor;
Expand Down Expand Up @@ -403,7 +401,7 @@ const durationYears = seq(
);
const durationDate = seq(choice(durationYears, durationMonths, durationWeeks, durationDays), [durationTime]);
const duration = seq(
withCode([sign], (data, result) => (data.factor = result === '-' || result === '\u2212' ? -1 : 1)),
withCode([temporalSign], (data, result) => (data.factor = result === '-' || result === '\u2212' ? -1 : 1)),
durationDesignator,
choice(durationDate, durationTime)
);
Expand Down
58 changes: 10 additions & 48 deletions spec/abstractops.html
Original file line number Diff line number Diff line change
Expand Up @@ -1172,32 +1172,6 @@ <h1>ISO 8601 grammar</h1>
`a` `b` `c` `d` `e` `f` `g` `h` `i` `j` `k` `l` `m`
`n` `o` `p` `q` `r` `s` `t` `u` `v` `w` `x` `y` `z`

ASCIISign ::: one of
`+` `-`

Sign :::
ASCIISign
U+2212

Hour :::
`0` DecimalDigit
`1` DecimalDigit
`20`
`21`
`22`
`23`

MinuteSecond :::
`0` DecimalDigit
`1` DecimalDigit
`2` DecimalDigit
`3` DecimalDigit
`4` DecimalDigit
`5` DecimalDigit

DecimalSeparator ::: one of
`.` `,`

DaysDesignator ::: one of
`D` `d`

Expand Down Expand Up @@ -1238,7 +1212,7 @@ <h1>ISO 8601 grammar</h1>

DateYear :::
DecimalDigit DecimalDigit DecimalDigit DecimalDigit
Sign DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
TemporalSign DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit

DateMonth :::
`0` NonZeroDigit
Expand Down Expand Up @@ -1284,31 +1258,19 @@ <h1>ISO 8601 grammar</h1>
MinuteSecond
`60`

Fraction :::
> Readability note: This production matches a decimal separator followed by 1 to 9 digits
DecimalSeparator DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
DecimalSeparator DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit

TimeFraction :::
Fraction
TemporalDecimalFraction

UTCOffsetWithSubMinuteComponents[Extended] :::
Sign Hour TimeSeparator[?Extended] MinuteSecond TimeSeparator[?Extended] MinuteSecond Fraction?
TemporalSign Hour TimeSeparator[?Extended] MinuteSecond TimeSeparator[?Extended] MinuteSecond TemporalDecimalFraction?

NormalizedUTCOffset :::
ASCIISign Hour `:` MinuteSecond

UTCOffsetMinutePrecision :::
Sign Hour
Sign Hour TimeSeparator[+Extended] MinuteSecond
Sign Hour TimeSeparator[~Extended] MinuteSecond
TemporalSign Hour
TemporalSign Hour TimeSeparator[+Extended] MinuteSecond
TemporalSign Hour TimeSeparator[~Extended] MinuteSecond

UTCOffsetSubMinutePrecision :::
UTCOffsetMinutePrecision
Expand Down Expand Up @@ -1475,8 +1437,8 @@ <h1>ISO 8601 grammar</h1>
DurationDaysPart DurationTime?

Duration :::
Sign? DurationDesignator DurationDate
Sign? DurationDesignator DurationTime
TemporalSign? DurationDesignator DurationDate
TemporalSign? DurationDesignator DurationTime

TemporalInstantString :::
Date DateTimeSeparator TimeSpec DateTimeUTCOffset TimeZoneAnnotation? Annotations?
Expand Down Expand Up @@ -1504,7 +1466,7 @@ <h1>ISO 8601 grammar</h1>
<h1>Static Semantics: Early Errors</h1>
<emu-grammar>
DateYear :::
Sign DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
TemporalSign DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit DecimalDigit
</emu-grammar>
<ul>
<li>
Expand Down Expand Up @@ -1733,7 +1695,7 @@ <h1>
<emu-alg>
1. Let _duration_ be ParseText(StringToCodePoints(_isoString_), |TemporalDurationString|).
1. If _duration_ is a List of errors, throw a *RangeError* exception.
1. Let each of _sign_, _years_, _months_, _weeks_, _days_, _hours_, _fHours_, _minutes_, _fMinutes_, _seconds_, and _fSeconds_ be the source text matched by the respective |Sign|, |DurationYears|, |DurationMonths|, |DurationWeeks|, |DurationDays|, |DurationWholeHours|, |DurationHoursFraction|, |DurationWholeMinutes|, |DurationMinutesFraction|, |DurationWholeSeconds|, and |DurationSecondsFraction| Parse Node contained within _duration_, or an empty sequence of code points if not present.
1. Let each of _sign_, _years_, _months_, _weeks_, _days_, _hours_, _fHours_, _minutes_, _fMinutes_, _seconds_, and _fSeconds_ be the source text matched by the respective |TemporalSign|, |DurationYears|, |DurationMonths|, |DurationWeeks|, |DurationDays|, |DurationWholeHours|, |DurationHoursFraction|, |DurationWholeMinutes|, |DurationMinutesFraction|, |DurationWholeSeconds|, and |DurationSecondsFraction| Parse Node contained within _duration_, or an empty sequence of code points if not present.
1. Let _yearsMV_ be ? ToIntegerWithTruncation(CodePointsToString(_years_)).
1. Let _monthsMV_ be ? ToIntegerWithTruncation(CodePointsToString(_months_)).
1. Let _weeksMV_ be ? ToIntegerWithTruncation(CodePointsToString(_weeks_)).
Expand Down

0 comments on commit 7bd3589

Please sign in to comment.