Skip to content

Commit c3651b6

Browse files
Allow duration literals without date component (#394)
## Usage and product changes We modify the grammar to accept a `duration_literal` without a date component (e.g. `PT1S`) as per the standard. ## Implementation The valid duration literals are: - `"P" ~ duration_weeks` - `"P" ~ duration_date` - `"P" ~ duration_date ~ "T" ~ duration_time` - `"PT" ~ duration_time` The last option was missing from the grammar.
1 parent a84767c commit c3651b6

File tree

3 files changed

+7
-1
lines changed

3 files changed

+7
-1
lines changed

rust/parser/literal.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,10 @@ fn visit_duration_literal(node: Node<'_>) -> DurationLiteral {
167167
let time = children.try_consume_expected(Rule::duration_time).map(visit_duration_time);
168168
DurationLiteral::DateAndTime(date, time)
169169
}
170+
Rule::duration_time => {
171+
let time = visit_duration_time(child);
172+
DurationLiteral::Time(time)
173+
}
170174
_ => unreachable!("{}", TypeQLError::IllegalGrammar { input: child.to_string() }),
171175
};
172176
debug_assert_eq!(children.try_consume_any(), None);

rust/parser/typeql.pest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ date_literal = ${ date_fragment ~ WB }
557557
datetime_literal = ${ date_fragment ~ "T" ~ time ~ WB }
558558
datetime_tz_literal = ${ date_fragment ~ "T" ~ time ~ ( " " ~ iana_timezone | iso8601_timezone_offset ) ~ WB }
559559

560-
duration_literal = ${ "P" ~ ( duration_weeks | duration_date ~ ( "T" ~ duration_time )? ) ~ WB}
560+
duration_literal = ${ "P" ~ ( duration_weeks | duration_date ~ ( "T" ~ duration_time )? | "T" ~ duration_time ) ~ WB}
561561

562562
quoted_string_literal = @{ "\"" ~ ( !"\"" ~ !"\\" ~ ANY | escape_seq )* ~ "\""
563563
| "'" ~ ( !"'" ~ !"\\" ~ ANY | escape_seq )* ~ "'" }

rust/value.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ pub enum TimeZone {
9999
pub enum DurationLiteral {
100100
Weeks(IntegerLiteral),
101101
DateAndTime(DurationDate, Option<DurationTime>),
102+
Time(DurationTime),
102103
}
103104

104105
#[derive(Debug, Clone, Eq, PartialEq)]
@@ -328,6 +329,7 @@ impl fmt::Display for DurationLiteral {
328329
Some(time) => write!(f, "T{time}")?,
329330
}
330331
}
332+
DurationLiteral::Time(time) => write!(f, "T{time}")?,
331333
}
332334
Ok(())
333335
}

0 commit comments

Comments
 (0)