mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:17:35 +00:00
LibJS: Implement parsing of TemporalYearMonthString
This commit is contained in:
parent
3ddab2f4fe
commit
3b1de431cc
5 changed files with 56 additions and 6 deletions
|
@ -210,6 +210,21 @@ bool ISO8601Parser::parse_date_day()
|
|||
return true;
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-temporal/#prod-DateSpecYearMonth
|
||||
bool ISO8601Parser::parse_date_spec_year_month()
|
||||
{
|
||||
// DateSpecYearMonth :
|
||||
// DateYear -[opt] DateMonth
|
||||
StateTransaction transaction { *this };
|
||||
if (!parse_date_year())
|
||||
return false;
|
||||
m_state.lexer.consume_specific('-');
|
||||
if (!parse_date_month())
|
||||
return false;
|
||||
transaction.commit();
|
||||
return true;
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-temporal/#prod-DateSpecMonthDay
|
||||
bool ISO8601Parser::parse_date_spec_month_day()
|
||||
{
|
||||
|
@ -528,13 +543,26 @@ bool ISO8601Parser::parse_temporal_time_string()
|
|||
|| parse_time();
|
||||
}
|
||||
|
||||
// https://tc39.es/proposal-temporal/#prod-TemporalYearMonthString
|
||||
bool ISO8601Parser::parse_temporal_year_month_string()
|
||||
{
|
||||
// TemporalYearMonthString :
|
||||
// DateSpecYearMonth
|
||||
// DateTime
|
||||
// NOTE: Reverse order here because `DateSpecYearMonth` can be a subset of `DateTime`,
|
||||
// so we'd not attempt to parse that but may not exhaust the input string.
|
||||
return parse_date_time()
|
||||
|| parse_date_spec_year_month();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#define JS_ENUMERATE_ISO8601_PRODUCTION_PARSERS \
|
||||
__JS_ENUMERATE(TemporalDateString, parse_temporal_date_string) \
|
||||
__JS_ENUMERATE(TemporalDateTimeString, parse_temporal_date_time_string) \
|
||||
__JS_ENUMERATE(TemporalMonthDayString, parse_temporal_month_day_string) \
|
||||
__JS_ENUMERATE(TemporalTimeString, parse_temporal_time_string)
|
||||
__JS_ENUMERATE(TemporalTimeString, parse_temporal_time_string) \
|
||||
__JS_ENUMERATE(TemporalYearMonthString, parse_temporal_year_month_string)
|
||||
|
||||
Optional<ParseResult> parse_iso8601(Production production, StringView input)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue