Skip to content
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

Add text parser. #11

Merged
merged 15 commits into from
Mar 10, 2020
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,7 @@ Cargo.lock

# Intellij Files
.idea/
serde_ion.iml
serde_ion.iml

# VSCode Files
.vscode/
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,24 @@ travis-ci = { repository = "PeytonT/serde_ion", branch = "master" }

[dependencies]
serde = { version = "1.0", features = ["derive"] }
serde_bytes = "0.10"
serde_bytes = "0.11"
serde_derive = "1.0"
num-bigint = "0.2.2"
num-traits = "0.2.8"
num-derive = "0.3"
bit-vec = "0.6"
base64 = "0.10.1"
base64 = "0.11"
nom = "5.0.0"
thiserror = "1.0.9"
lazy_static = "1.4.0"
itertools = "0.8.2"

log = "0.4.8"
time = "0.2.6"

[dev-dependencies]
hex = "0.4.0"
pretty_assertions = "0.6.1"
pretty_env_logger = "0.4.0"

[build-dependencies]

Expand Down
28 changes: 28 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use num_bigint::ParseBigIntError;
use std::num::ParseFloatError;
use thiserror::Error;

pub type Result<T> = std::result::Result<T, Error>;
Expand All @@ -23,6 +25,14 @@ pub enum SymbolError {
UnknownSymbolText(usize),
#[error("the text for SID `{0}` is undefined")]
UndefinedSymbolText(usize),
#[error("the provided symbol table is invalid")]
InvalidSymbolTable,
#[error("invalid max_id for import in symbol table: {0:?}")]
InvalidMaxId(String),
#[error("invalid version for import in symbol table: {0:?}")]
InvalidVersion(String),
siler marked this conversation as resolved.
Show resolved Hide resolved
#[error("invalid SID (outside numeric range): {0:?}")]
InvalidSid(String),
}

#[derive(Error, Debug, PartialEq)]
Expand Down Expand Up @@ -65,4 +75,22 @@ pub enum BinaryFormatError {
pub enum TextFormatError {
#[error("TODO")]
TODO,
#[error("invalid hex escape: {0}")]
HexEscape(String),
#[error("unterminated short quoted string")]
OpenShortString,
#[error("unterminated long quoted string")]
OpenLongString,
#[error("invalid bigint")]
BigUint,
#[error("invalid bigint: {0}")]
BigInt(ParseBigIntError, String),
siler marked this conversation as resolved.
Show resolved Hide resolved
#[error("unable to decode Base64 value")]
Base64Decode,
#[error("unable to parse float value: {0}, {1}")]
FloatParse(String, ParseFloatError),
#[error("date out of range (invalid day)")]
DateOutOfRange,
#[error("Ion Version Marker indicates an unsupported version of Ion: {0}.{1}")]
UnsupportedVersion(u32, u32),
}
34 changes: 17 additions & 17 deletions src/parser/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub enum OperatorCharacter {
impl OperatorCharacter {
pub fn as_str(&self) -> String {
match self {
&OperatorCharacter::PlaceHolder => todo!(),
OperatorCharacter::PlaceHolder => todo!(),
siler marked this conversation as resolved.
Show resolved Hide resolved
// ...
}
}
Expand Down Expand Up @@ -68,21 +68,21 @@ pub enum NumericStopCharacter {
impl NumericStopCharacter {
pub fn as_str(&self) -> String {
match self {
&NumericStopCharacter::LeftCurlyBracket => todo!(),
&NumericStopCharacter::RightCurlyBracket => todo!(),
&NumericStopCharacter::LeftSquareBracket => todo!(),
&NumericStopCharacter::RightSquareBracket => todo!(),
&NumericStopCharacter::LeftParenthesis => todo!(),
&NumericStopCharacter::RightParenthesis => todo!(),
&NumericStopCharacter::Comma => todo!(),
&NumericStopCharacter::QuotationMark => todo!(),
&NumericStopCharacter::Apostrophe => todo!(),
&NumericStopCharacter::Space => todo!(),
&NumericStopCharacter::Tab => todo!(),
&NumericStopCharacter::LineFeed => todo!(),
&NumericStopCharacter::CarriageReturn => todo!(),
&NumericStopCharacter::VerticalTab => todo!(),
&NumericStopCharacter::FormFeed => todo!(),
NumericStopCharacter::LeftCurlyBracket => todo!(),
NumericStopCharacter::RightCurlyBracket => todo!(),
NumericStopCharacter::LeftSquareBracket => todo!(),
NumericStopCharacter::RightSquareBracket => todo!(),
NumericStopCharacter::LeftParenthesis => todo!(),
NumericStopCharacter::RightParenthesis => todo!(),
NumericStopCharacter::Comma => todo!(),
NumericStopCharacter::QuotationMark => todo!(),
NumericStopCharacter::Apostrophe => todo!(),
NumericStopCharacter::Space => todo!(),
NumericStopCharacter::Tab => todo!(),
NumericStopCharacter::LineFeed => todo!(),
NumericStopCharacter::CarriageReturn => todo!(),
NumericStopCharacter::VerticalTab => todo!(),
NumericStopCharacter::FormFeed => todo!(),
}
}
}
Expand Down Expand Up @@ -113,7 +113,7 @@ pub enum TextFormatEscapeCharacter {
impl TextFormatEscapeCharacter {
pub fn as_str(&self) -> String {
match self {
&TextFormatEscapeCharacter::PlaceHolder => todo!(),
TextFormatEscapeCharacter::PlaceHolder => todo!(),
// ...
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/parser/ion_1_0/binary.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ fn parse_top_level_value<'a, 'b>(
// And the value of the annotation is "$ion_symbol_table"...
if *token == SYSTEM_SYMBOL_TABLE_V1.symbols[3] {
// Then it is an update to the local symbol table. Apply it.
update_current_symbol_table(symbol_table, ion_struct);
update_current_symbol_table(symbol_table, ion_struct)
.map_err(|e| Err::Failure(IonError::from_symbol_error(i, e)))?;
// And return no Value
return Ok((rest, None));
}
Expand Down
Loading