Skip to content
Snippets Groups Projects
Commit 76d0eda1 authored by Martin Larralde's avatar Martin Larralde
Browse files

Fix issue with parsing of floating-point numbers in JASPAR parser

parent f1744c1f
No related branches found
No related tags found
No related merge requests found
...@@ -58,10 +58,7 @@ pub fn parse_alphabet<S: Symbol>(input: &str) -> IResult<&str, Vec<S>> { ...@@ -58,10 +58,7 @@ pub fn parse_alphabet<S: Symbol>(input: &str) -> IResult<&str, Vec<S>> {
} }
pub fn parse_element(input: &str) -> IResult<&str, f32> { pub fn parse_element(input: &str) -> IResult<&str, f32> {
nom::branch::alt(( nom::number::complete::float(input)
nom::combinator::map_res(nom::character::complete::digit1, f32::from_str),
nom::combinator::map(nom::number::complete::float, |x| x),
))(input)
} }
pub fn parse_row(input: &str, k: usize) -> IResult<&str, Vec<f32>> { pub fn parse_row(input: &str, k: usize) -> IResult<&str, Vec<f32>> {
...@@ -331,6 +328,14 @@ mod test { ...@@ -331,6 +328,14 @@ mod test {
assert_eq!(res.1, vec![0., 0., 2., 0.]); assert_eq!(res.1, vec![0., 0., 2., 0.]);
} }
#[test]
fn test_parse_count_float() {
let line = "01 3566.0 119.0 342.0 225.0\n";
let res = super::parse_row(line, 4).unwrap();
assert_eq!(res.0, "");
assert_eq!(res.1, vec![3566., 119., 342., 225.]);
}
#[test] #[test]
fn test_parse_prodoric() { fn test_parse_prodoric() {
let text = concat!( let text = concat!(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment