Skip to content

Commit

Permalink
Initial work on temporal ISO8601 parsing and grammar
Browse files Browse the repository at this point in the history
  • Loading branch information
nekevss committed Sep 11, 2023
1 parent 4dea08b commit cacfc76
Show file tree
Hide file tree
Showing 19 changed files with 1,327 additions and 164 deletions.
2 changes: 0 additions & 2 deletions boa_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ pub use self::{
statement::Statement,
statement_list::{StatementList, StatementListItem},
};
#[cfg(feature = "temporal")]
pub use temporal::UtcOffset;

/// Utility to join multiple Nodes into a single string.
fn join_nodes<N>(interner: &Interner, nodes: &[N]) -> String
Expand Down
24 changes: 0 additions & 24 deletions boa_ast/src/temporal.rs

This file was deleted.

13 changes: 13 additions & 0 deletions boa_ast/src/temporal/annotation.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//! Temporal Annotation Nodes.
/// A list of indidividual Annotation nodes.
#[derive(Debug, Clone, Copy)]
#[deny(dead_code)]
pub struct Annotations;
//{
// list: Box<[Annotation]>,
//}

/// An individual Annotation Information Node
#[derive(Debug, Clone, Copy)]
pub struct Annotation;
113 changes: 113 additions & 0 deletions boa_ast/src/temporal/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
//! AST nodes for Temporal's implementation of ISO8601 grammar.
use rustc_hash::FxHashMap;

pub mod annotation;

/// TBD...
#[derive(Default, Debug)]
pub struct AnnotatedDateTime {
/// Parsed Date Record
pub date_time: DateTimeRecord,
/// Parsed `TimeZoneAnnotation`
pub tz_annotation: Option<TimeZoneAnnotation>,
/// Parsed Annotations
pub annotations: Option<FxHashMap<String, (bool, String)>>,
}

#[derive(Default, Debug, Clone,Copy)]
/// The record of a parsed date.
pub struct DateRecord {
/// Date Year
pub year: i32,
/// Date Month
pub month: i32,
/// Date Day
pub day: i32,
}

/// Parsed Time info
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub struct TimeSpec {
/// An hour
pub hour: i8,
/// A minute value
pub minute: i8,
/// A floating point second value.
pub second: f64,
}

/// TimeZone UTC Offset info.
#[derive(Debug, Clone, Copy)]
pub struct DateTimeUtcOffset;

#[derive(Debug, Default, Clone, Copy)]
/// Boop
pub struct DateTimeRecord {
/// Date
pub date: DateRecord,
/// Time
pub time: Option<TimeSpec>,
/// Tz Offset
pub offset: Option<UtcOffset>,
}

/// A TimeZoneAnnotation.
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct TimeZoneAnnotation {
/// Critical Flag for the annotation.
pub critical: bool,
/// TimeZone Data
pub tz: TzIdentifier,
}

/// A valid `TimeZoneIdentifier` that is defined by
/// the specification as either a UTC Offset to minute
/// precision or a `TimeZoneIANAName`
#[derive(Debug, Clone)]
pub enum TzIdentifier {
/// A valid UTC `TimeZoneIdentifier` value
UtcOffset(UtcOffset),
/// A valid IANA name `TimeZoneIdentifier` value
TzIANAName(String),
}

// NOTE: is it worth consolidating MinutePrecision vs. Offset
/// A UTC Offset that maintains only minute precision.
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub struct UtcOffsetMinutePrecision {
sign: i8,
hour: i8,
minute: i8,
}

/// A full precision `UtcOffset`
#[derive(Debug, Clone, Copy)]
#[allow(dead_code)]
pub struct UtcOffset {
/// The UTC flag
pub utc: bool,
/// The `+`/`-` sign of this `UtcOffset`
pub sign: i8,
/// The hour value of the `UtcOffset`
pub hour: i8,
/// The minute value of the `UtcOffset`.
pub minute: i8,
/// A float representing the second value of the `UtcOffset`.
pub second: f64,
}

/// A KeyValueAnnotation Parse Node.
#[derive(Debug, Clone)]
#[allow(dead_code)]
pub struct KeyValueAnnotation {
/// An `Annotation`'s Key.
pub key: String,
/// An `Annotation`'s value.
pub value: String,
/// Whether the annotation was flagged as critical.
pub critical: bool,
}
Loading

0 comments on commit cacfc76

Please sign in to comment.