Skip to content

Commit

Permalink
Editorial: Replace AnnotatedDateTimeTimeRequired production with para…
Browse files Browse the repository at this point in the history
…meterization

Another place where we can deduplicate parts of the grammar.
  • Loading branch information
ptomato committed Feb 2, 2024
1 parent 8ceba50 commit 0933de3
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
32 changes: 15 additions & 17 deletions polyfill/test/validStrings.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,13 @@ const dateSpec = (extended) =>
validateDayOfMonth
);
const date = choice(dateSpec(true), dateSpec(false));
const dateTime = (plain) => seq(date, [dateTimeSeparator, time, [dateTimeUTCOffset(plain)]]);
const dateTime = (plain, timeRequired) =>
seq(
date,
timeRequired
? seq(dateTimeSeparator, time, [dateTimeUTCOffset(plain)])
: [dateTimeSeparator, time, [dateTimeUTCOffset(plain)]]
);
const annotatedTime = choice(
seq(timeDesignator, time, [dateTimeUTCOffset(true)], [timeZoneAnnotation], [annotations]),
seq(
Expand All @@ -320,16 +326,8 @@ const annotatedTime = choice(
[annotations]
)
);
const annotatedDateTime = (zoned) =>
seq(dateTime(!zoned), zoned ? timeZoneAnnotation : [timeZoneAnnotation], [annotations]);
const annotatedDateTimeTimeRequired = seq(
date,
dateTimeSeparator,
time,
[dateTimeUTCOffset(true)],
[timeZoneAnnotation],
[annotations]
);
const annotatedDateTime = (zoned, timeRequired) =>
seq(dateTime(!zoned, timeRequired), zoned ? timeZoneAnnotation : [timeZoneAnnotation], [annotations]);
const annotatedYearMonth = withSyntaxConstraints(
seq(dateSpecYearMonth, [timeZoneAnnotation], [annotations]),
(result, data) => {
Expand Down Expand Up @@ -420,18 +418,18 @@ const duration = seq(
);

const instant = seq(date, dateTimeSeparator, time, dateTimeUTCOffset(false), [timeZoneAnnotation], [annotations]);
const zonedDateTime = annotatedDateTime(true);
const zonedDateTime = annotatedDateTime(true, false);

// goal elements
const goals = {
Instant: instant,
Date: annotatedDateTime(false),
DateTime: annotatedDateTime(false),
Date: annotatedDateTime(false, false),
DateTime: annotatedDateTime(false, false),
Duration: duration,
MonthDay: choice(annotatedMonthDay, annotatedDateTime(false)),
Time: choice(annotatedTime, annotatedDateTimeTimeRequired),
MonthDay: choice(annotatedMonthDay, annotatedDateTime(false, false)),
Time: choice(annotatedTime, annotatedDateTime(false, true)),
TimeZone: choice(timeZoneIdentifier, zonedDateTime, instant),
YearMonth: choice(annotatedYearMonth, annotatedDateTime(false)),
YearMonth: choice(annotatedYearMonth, annotatedDateTime(false, false)),
ZonedDateTime: zonedDateTime
};

Expand Down
21 changes: 9 additions & 12 deletions spec/abstractops.html
Original file line number Diff line number Diff line change
Expand Up @@ -1346,20 +1346,17 @@ <h1>ISO 8601 grammar</h1>
TimeSpec[+Extended]
TimeSpec[~Extended]

DateTime[Plain] :::
Date
DateTime[Plain, TimeRequired] :::
[~TimeRequired] Date
Date DateTimeSeparator Time DateTimeUTCOffset[?Plain]?

AnnotatedTime :::
TimeDesignator Time DateTimeUTCOffset[+Plain]? TimeZoneAnnotation? Annotations?
Time DateTimeUTCOffset[+Plain]? TimeZoneAnnotation? Annotations?

AnnotatedDateTime[Zoned] :::
[~Zoned] DateTime[+Plain] TimeZoneAnnotation? Annotations?
[+Zoned] DateTime[~Plain] TimeZoneAnnotation Annotations?

AnnotatedDateTimeTimeRequired :::
Date DateTimeSeparator Time DateTimeUTCOffset[+Plain]? TimeZoneAnnotation? Annotations?
AnnotatedDateTime[Zoned, TimeRequired] :::
[~Zoned] DateTime[+Plain, ?TimeRequired] TimeZoneAnnotation? Annotations?
[+Zoned] DateTime[~Plain, ?TimeRequired] TimeZoneAnnotation Annotations?

AnnotatedYearMonth :::
DateSpecYearMonth TimeZoneAnnotation? Annotations?
Expand Down Expand Up @@ -1443,22 +1440,22 @@ <h1>ISO 8601 grammar</h1>
Date DateTimeSeparator Time DateTimeUTCOffset[~Plain] TimeZoneAnnotation? Annotations?

TemporalDateTimeString[Zoned] :::
AnnotatedDateTime[?Zoned]
AnnotatedDateTime[?Zoned, ~TimeRequired]

TemporalDurationString :::
Duration

TemporalMonthDayString :::
AnnotatedMonthDay
AnnotatedDateTime[~Zoned]
AnnotatedDateTime[~Zoned, ~TimeRequired]

TemporalTimeString :::
AnnotatedTime
AnnotatedDateTimeTimeRequired
AnnotatedDateTime[~Zoned, +TimeRequired]

TemporalYearMonthString :::
AnnotatedYearMonth
AnnotatedDateTime[~Zoned]
AnnotatedDateTime[~Zoned, ~TimeRequired]
</emu-grammar>

<emu-clause id="sec-temporal-iso8601grammar-static-semantics-isvalidmonthday" type="sdo">
Expand Down

0 comments on commit 0933de3

Please sign in to comment.