Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into lazy-structs
Browse files Browse the repository at this point in the history
  • Loading branch information
Zack Slayton committed Aug 23, 2023
2 parents 4fc9078 + cb1042a commit 37a2a50
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 38 deletions.
4 changes: 2 additions & 2 deletions src/lazy/text/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ impl<'data> TextBufferView<'data> {
))(self)
}

/// Matches special IEEE-754 floating point values, including +/- infinity and NaN.
/// Matches special IEEE-754 values, including +/- infinity and NaN.
fn match_float_special_value(self) -> IonParseResult<'data, MatchedFloat> {
alt((
value(MatchedFloat::NotANumber, tag("nan")),
Expand Down Expand Up @@ -788,7 +788,7 @@ impl<'data> TextBufferView<'data> {

/// Matches a symbol ID (`$28`), an identifier (`foo`), or a quoted symbol (`'foo'`).
fn match_symbol(self) -> IonParseResult<'data, MatchedSymbol> {
// TODO: identifiers
// TODO: operators
alt((
Self::match_symbol_id,
Self::match_identifier,
Expand Down
9 changes: 4 additions & 5 deletions src/lazy/text/encoded_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ pub(crate) struct EncodedTextValue {
// value is stored. For others (e.g. a timestamp), the various components of the value are
// recognized during matching and partial information like subfield offsets can be stored here.
matched_value: MatchedValue,

field_name_syntax: Option<MatchedSymbol>,
}

Expand Down Expand Up @@ -193,13 +192,13 @@ impl EncodedTextValue {
self.data_length + u32::max(self.annotations_offset, self.field_name_offset) as usize
}

pub fn matched(&self) -> &MatchedValue {
&self.matched_value
}

pub fn field_name_syntax(&self) -> Option<MatchedSymbol> {
self.field_name_syntax
}

pub fn matched(&self) -> MatchedValue {
self.matched_value
}
}

#[cfg(test)]
Expand Down
17 changes: 5 additions & 12 deletions src/lazy/text/matched.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
//! use the previously recorded information to minimize the amount of information that needs to be
//! re-discovered.

use nom::character::is_hex_digit;
use std::borrow::Cow;
use std::num::IntErrorKind;
use std::str::FromStr;

use nom::character::is_hex_digit;
use num_bigint::BigInt;
use num_traits::Num;
use smallvec::SmallVec;
Expand Down Expand Up @@ -170,15 +170,7 @@ pub(crate) enum MatchedString {
/// The string is in multiple segments:
/// """hello,"""
/// """ world!"""
Long(MatchedLongString),
}

#[derive(Clone, Copy, Debug, PartialEq)]
pub(crate) struct MatchedLongString {
// TODO: Decide what (if anything) to store here.
// Storing any collection of bytes or ranges means that this type cannot implement Copy,
// which in turn means MatchedValue and EncodedTextValue also cannot implement Copy.
// We probably also don't want to heap allocate just to match the long string.
Long,
}

impl MatchedString {
Expand All @@ -191,7 +183,7 @@ impl MatchedString {
self.read_short_string_without_escapes(matched_input)
}
MatchedString::ShortWithEscapes => self.read_short_string_with_escapes(matched_input),
MatchedString::Long(_) => todo!("long-form strings"),
MatchedString::Long => todo!("long-form strings"),
}
}

Expand All @@ -213,7 +205,7 @@ impl MatchedString {
) -> IonResult<StrRef<'data>> {
// Take a slice of the input that ignores the first and last bytes, which are quotes.
let body = matched_input.slice(1, matched_input.len() - 2);
// Otherwise, there are escaped characters. We need to build a new version of our string
// There are escaped characters. We need to build a new version of our string
// that replaces the escaped characters with their corresponding bytes.
let mut sanitized = Vec::with_capacity(matched_input.len());
escape_text(body, &mut sanitized)?;
Expand Down Expand Up @@ -439,6 +431,7 @@ impl MatchedSymbol {
.as_text()
.map(|t| RawSymbolTokenRef::Text(Cow::Borrowed(t)))
}

fn read_symbol_id<'data>(
&self,
matched_input: TextBufferView<'data>,
Expand Down
15 changes: 0 additions & 15 deletions src/lazy/text/parse_result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,6 @@ impl<'data> InvalidInputError<'data> {
// TODO: Decide how to expose 'input'.
}

// impl<'data> From<InvalidInputError<'data>> for IonError {
// fn from(value: InvalidInputError) -> Self {
// dbg!(&value.backtrace);
// let mut message = String::from(value.description().unwrap_or("invalid text Ion syntax"));
// if let Some(label) = value.label {
// message.push_str(" while ");
// message.push_str(label.as_ref());
// }
// let position = Position::with_offset(value.input.offset()).with_length(value.input.len());
// let decoding_error = DecodingError::new(message).with_position(position);
// IonError::Decoding(decoding_error)
// }
// }

impl<'data> From<InvalidInputError<'data>> for IonParseError<'data> {
fn from(value: InvalidInputError<'data>) -> Self {
IonParseError::Invalid(value)
Expand All @@ -149,7 +135,6 @@ impl<'data> From<InvalidInputError<'data>> for IonError {
message.push_str("; buffer: ");
let input = invalid_input_error.input;
let buffer_text = if let Ok(text) = invalid_input_error.input.as_text() {
// TODO: This really should be graphemes instead of chars()
text.chars().take(32).collect::<String>()
} else {
format!(
Expand Down
5 changes: 3 additions & 2 deletions src/lazy/text/raw/reader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ mod tests {
"\x48ello, \x77orld!" // \x 2-digit hex escape
"\u0048ello, \u0077orld!" // \u 4-digit hex escape
"\U00000048ello, \U00000077orld!" // \U 8-digit hex escape
"#,
);
// Escaped newlines are discarded
Expand Down Expand Up @@ -165,7 +165,7 @@ mod tests {
// Short-form string
"baz": 300
}
"#,
);

Expand Down Expand Up @@ -280,6 +280,7 @@ mod tests {
);

// [1, 2, 3]

let list = reader.next()?.expect_value()?.read()?.expect_list()?;
let mut sum = 0;
for value in &list {
Expand Down
4 changes: 2 additions & 2 deletions src/lazy/text/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ impl<'data> LazyRawValue<'data, TextEncoding> for LazyRawTextValue<'data> {
self.encoded_value.data_length(),
);
let value_ref = match self.encoded_value.matched() {
MatchedValue::Null(ion_type) => RawValueRef::Null(*ion_type),
MatchedValue::Bool(b) => RawValueRef::Bool(*b),
MatchedValue::Null(ion_type) => RawValueRef::Null(ion_type),
MatchedValue::Bool(b) => RawValueRef::Bool(b),
MatchedValue::Int(i) => RawValueRef::Int(i.read(matched_input)?),
MatchedValue::Float(f) => RawValueRef::Float(f.read(matched_input)?),
// ...decimal, timestamp...
Expand Down

0 comments on commit 37a2a50

Please sign in to comment.