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

nom 7 #7

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
edition = "2018"
edition = "2021"
name = "gb-io"
version = "0.7.1"
license = "MIT"
Expand All @@ -14,12 +14,12 @@ exclude = ["tests/*", ".github/*"]
string_cache_codegen = "0.5"

[dependencies]
itertools = "0.10"
itertools = "0.11"
circular = "0.3.0"
err-derive = "0.3.1"
string_cache = "0.8"
log = "0.4"
nom = "4.2.3"
nom = "7.1.3"
serde = { version = "1", optional = true, features = ["derive"] }
serde_bytes = { version = "0.11", optional = true }

Expand All @@ -29,8 +29,11 @@ default = ["serde", "serde_bytes"]
[dev-dependencies]
glob = "0.3.0"
bencher = "0.1.5"
env_logger = "0.9.0"
env_logger = "0.10.0"

[[bench]]
name = "parse"
harness = false

[profile.release]
lto = true # keeps performance on-par with nom 4 (macro-based)
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ fn main() {
"tRNA",
"V_segment",
];
let file = File::create(&Path::new(&env::var("OUT_DIR").unwrap()).join("atoms.rs")).unwrap();
let file = File::create(Path::new(&env::var("OUT_DIR").unwrap()).join("atoms.rs")).unwrap();
string_cache_codegen::AtomType::new("QualifierKey", "qualifier_key!")
.atoms(qualifiers.iter())
.write_to(&file)
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
#![cfg_attr(feature = "cargo-clippy", allow(clippy::useless_format))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::unreadable_literal))]
#![cfg_attr(feature = "cargo-clippy", allow(clippy::upper_case_acronyms))]
#![recursion_limit = "128"]
extern crate circular;
#[macro_use]
extern crate err_derive;
extern crate itertools;
#[macro_use]
extern crate log;
#[macro_use]
extern crate nom;
#[cfg(feature = "serde")]
#[macro_use]
Expand Down Expand Up @@ -46,7 +44,6 @@ pub mod tests {
let _ = env_logger::Builder::from_default_env().try_init();
}


#[test]
fn streaming() {
init();
Expand Down Expand Up @@ -134,4 +131,8 @@ pub mod tests {
}
}
}

fn parse_slice(bytes: &[u8]) -> Result<Vec<Seq>, GbParserError> {
SeqReader::new(bytes).collect()
}
}
58 changes: 0 additions & 58 deletions src/reader/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,61 +47,3 @@ impl fmt::Display for NomParserError {
write!(f, "{}", msg)
}
}

// Copied from nom and modified
macro_rules! map_res_custom_error (
// Internal parser, do not use directly
(__impl $i:expr, $e:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
{
use ::std::result::Result::*;
use ::nom::Err;

let i_ = $i.clone();
($submac!(i_, $($args)*)).and_then(|(i,o)| {
match $submac2!(o, $($args2)*) {
Ok(output) => Ok((i, output)),
Err(_) => {
let e = ::nom::ErrorKind::Custom(u32::from($e));
Err(Err::Error(error_position!($i, e)))
},
}
})
}
);
($i:expr, $e:expr, $submac:ident!( $($args:tt)* ), $g:expr) => (
map_res_custom_error!(__impl $i, $e, $submac!($($args)*), call!($g))
);
($i:expr, $e:expr, $submac:ident!( $($args:tt)* ), $submac2:ident!( $($args2:tt)* )) => (
map_res_custom_error!(__impl $i, $e, $submac!($($args)*), $submac2!($($args2)*))
);
($i:expr, $e:expr, $f:expr, $g:expr) => (
map_res_custom_error!(__impl $i, $e, call!($f), call!($g))
);
($i:expr, $e:expr, $f:expr, $submac:ident!( $($args:tt)* )) => (
map_res_custom_error!(__impl $i, call!($f), $submac!($($args)*))
)
);

macro_rules! to_str (
($i:expr, $submac:ident!( $($args:tt)* )) => (
map_res_custom_error!($i, NomParserError::Utf8Error,
$submac!($($args)*),
str::from_utf8
)
);
($i:expr, $f:expr) => (
to_str!($i, call!($f))
)
);

macro_rules! to_string (
($i:expr, $submac:ident!( $($args:tt)* )) => (
map_res_custom_error!($i, NomParserError::Utf8Error,
$submac!($($args)*),
String::from_utf8
)
);
($i:expr, $f:expr) => (
to_str!($i, call!($f))
)
);
Loading
Loading