From dfb41233bd227891a2d320abbd50ca94140c4d01 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sat, 29 Sep 2018 13:16:58 +0100 Subject: [PATCH] Update nom to v4 and regex to v1 --- Cargo.toml | 4 ++-- src/function.rs | 6 +++--- src/lib.rs | 31 ++++++++++++------------------- 3 files changed, 17 insertions(+), 24 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index aac1766..a238cc4 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,5 +4,5 @@ version = "0.1.0" authors = ["Oliver Hamlet "] [dependencies] -nom = "3.2.1" -regex = "0.2" +nom = "4.0.0" +regex = "1.0.5" diff --git a/src/function.rs b/src/function.rs index 7b0105d..9cfc69f 100644 --- a/src/function.rs +++ b/src/function.rs @@ -3,7 +3,7 @@ use std::path::{Path, PathBuf}; use std::str; use regex::Regex; -use nom::{IError, IResult}; +use nom::IResult; use super::Error; @@ -65,7 +65,7 @@ mod tests { #[test] fn function_parse_should_parse_a_file_path_function() { - let result = Function::parse("file(\"Cargo.toml\")").to_result().unwrap(); + let result = Function::parse("file(\"Cargo.toml\")").unwrap().1; match result { Function::FilePath(f) => assert_eq!(PathBuf::from("Cargo.toml"), f), @@ -75,7 +75,7 @@ mod tests { #[test] fn function_parse_should_parse_an_active_function() { - let result = Function::parse("active(\"Cargo.toml\")").to_result().unwrap(); + let result = Function::parse("active(\"Cargo.toml\")").unwrap().1; match result { Function::ActivePath(f) => assert_eq!(PathBuf::from("Cargo.toml"), f), diff --git a/src/lib.rs b/src/lib.rs index d604dd6..37f456d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2,7 +2,7 @@ extern crate nom; extern crate regex; -use nom::{IError, IResult}; +use nom::{Err, IResult}; use std::path::PathBuf; use std::str; @@ -17,11 +17,11 @@ pub enum Error { InvalidRegex(String), } -impl From for Error { - fn from(error: IError) -> Self { +impl From> for Error { + fn from(error: Err) -> Self { match error { - IError::Error(_) => Error::ParsingError, - _ => Error::ParsingIncomplete, + Err::Incomplete(_) => Error::ParsingIncomplete, + _ => Error::ParsingError, } } } @@ -115,8 +115,7 @@ mod tests { #[test] fn expression_parse_should_handle_a_single_compound_condition() { let result = Expression::parse("file(\"Cargo.toml\")") - .to_result() - .unwrap(); + .unwrap().1; match result.0.as_slice() { [CompoundCondition(_)] => {} @@ -127,8 +126,7 @@ mod tests { #[test] fn expression_parse_should_handle_multiple_compound_conditions() { let result = Expression::parse("file(\"Cargo.toml\") or file(\"Cargo.toml\")") - .to_result() - .unwrap(); + .unwrap().1; match result.0.as_slice() { [CompoundCondition(_), CompoundCondition(_)] => {} @@ -142,8 +140,7 @@ mod tests { #[test] fn compound_condition_parse_should_handle_a_single_condition() { let result = CompoundCondition::parse("file(\"Cargo.toml\")") - .to_result() - .unwrap(); + .unwrap().1; match result.0.as_slice() { [Condition::Function(Function::FilePath(f))] => { @@ -159,8 +156,7 @@ mod tests { #[test] fn compound_condition_parse_should_handle_multiple_conditions() { let result = CompoundCondition::parse("file(\"Cargo.toml\") and file(\"README.md\")") - .to_result() - .unwrap(); + .unwrap().1; match result.0.as_slice() { [Condition::Function(Function::FilePath(f1)), Condition::Function(Function::FilePath(f2))] => @@ -178,8 +174,7 @@ mod tests { #[test] fn condition_parse_should_handle_a_function() { let result = Condition::parse("file(\"Cargo.toml\")") - .to_result() - .unwrap(); + .unwrap().1; match result { Condition::Function(Function::FilePath(f)) => { @@ -195,8 +190,7 @@ mod tests { #[test] fn condition_parse_should_handle_a_inverted_function() { let result = Condition::parse("not file(\"Cargo.toml\")") - .to_result() - .unwrap(); + .unwrap().1; match result { Condition::InvertedFunction(Function::FilePath(f)) => { @@ -212,8 +206,7 @@ mod tests { #[test] fn condition_parse_should_handle_an_expression_in_parentheses() { let result = Condition::parse("(not file(\"Cargo.toml\"))") - .to_result() - .unwrap(); + .unwrap().1; match result { Condition::Expression(_) => {}