-
Notifications
You must be signed in to change notification settings - Fork 21
Temporal parser #379
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Temporal parser #379
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey! Thanks for working on this! I left a few review comments. Overall this is looking pretty good!
In general, the gist of the feedback is that the parser should ideally take utf8 and utf16 as primaries (a from_str
method is an option assuming it calls str::to_bytes
internally using the utf8 method).
For now, this can focus on primarily supporting utf8, but once ixdtf
is bumped to its current main or a new version, the utf16 support will need to be added.
Quick follow up, the |
Hi @blarfoon, are you able to fix the above? |
36976ea
to
f161a21
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is a lot of code duplication that will make it harder to maintain: the actual logic of the UTF8/UTF16 code paths should share code.
@@ -490,6 +490,25 @@ impl PlainDate { | |||
Self::try_new(date.year, date.month, date.day, calendar) | |||
} | |||
|
|||
/// Converts a UTF-16 encoded string into a `PlainDate`. | |||
pub fn from_utf16(s: &[u16]) -> TemporalResult<Self> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
n.b. temporal_capi has a bunch of internally-converting from_utf16
s that probably can be swapped over to these
} | ||
|
||
/// Parses the source into a `PlainDateTime` compatible record. | ||
pub fn parse_date_time(&self) -> TemporalResult<ParsedDateTime<'a>> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: ideally we link to exactly which part of the spec this implements: there are a lot of parseable things called DateTime
) -> TemporalResult<IxdtfParseRecord<'a, Utf16>> { | ||
let record = self.parse_ixdtf_utf16(source, ParseVariant::DateTime)?; | ||
|
||
if record.offset == Some(UtcOffsetRecordOrZ::Z) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: I think this code should be shared; same for the rest.
} | ||
} | ||
|
||
fn parse_ixdtf_utf16( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
observation: I also think this code should be shareable.
I think all of this can be made to operate on an IxdtfParser
, and the end functions construct an IxdtfParser::from_whatever
and pass it down.
Hell, I think the IxdtfParser can probably just be a field in TemporalParser
.
|
||
fn parse_date_time_utf16( | ||
&self, | ||
source: &'a [u16], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: what's the point of taking both a source
and self
here? Both wrap the same string?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with Manish that there is probably a good way to make the code shareable.
For reference -- if it's helpful at all -- the PR to add UTF16 support to ixdtf
is here.
Self::DateTimeOutOfRange => { | ||
TemporalError::range().with_message("Date/time is outside representable range") | ||
} | ||
Self::ParseError(msg) => TemporalError::syntax().with_message(msg), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this should probably be a RangeError
While it would be technically correct for this to be a syntax error, almost all syntax errors are thrown as range errors, so the general movement has been away from using them.
Addresses #224