Compare commits

..

No commits in common. "master" and "v0.2.4" have entirely different histories.

3 changed files with 35 additions and 59 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "abortable_parser" name = "abortable_parser"
version = "0.2.5" version = "0.2.4"
authors = ["Jeremy Wall <jeremy@marzhillstudios.com>"] authors = ["Jeremy Wall <jeremy@marzhillstudios.com>"]
description = "A parser combinator library with an emphasis on error handling" description = "A parser combinator library with an emphasis on error handling"
repository = "https://github.com/zaphar/abortable_parser" repository = "https://github.com/zaphar/abortable_parser"

View File

@ -63,14 +63,12 @@ macro_rules! not {
}}; }};
($i:expr, $f:ident( $( $args:tt )* ) ) => { ($i:expr, $f:ident( $( $args:tt )* ) ) => {
use $crate::run
$crate::not!($i, run!($f($($args)*))) $crate::not!($i, run!($f($($args)*)))
}; };
($i:expr, $f:ident) => {{ ($i:expr, $f:ident) => {
use $crate::run;
$crate::not!($i, run!($f)) $crate::not!($i, run!($f))
}}; };
} }
/// Checks the given matcher without consuming the input. /// Checks the given matcher without consuming the input.
@ -182,15 +180,13 @@ macro_rules! with_err {
} }
}}; }};
($i:expr, $f:ident( $( $args:tt )* ), $e:expr ) => {{ ($i:expr, $f:ident( $( $args:tt )* ), $e:expr ) => {
use $crate::run;
$crate::with_err!($i, run!($f($($args)*)), $e:expr) $crate::with_err!($i, run!($f($($args)*)), $e:expr)
}}; };
($i:expr, $f:ident, $e:expr) => {{ ($i:expr, $f:ident, $e:expr) => {
use $crate::run;
$crate::with_err!($i, run!($f), $e) $crate::with_err!($i, run!($f), $e)
}}; };
} }
/// Wraps any Error return from a subparser in another error. Stores the position at /// Wraps any Error return from a subparser in another error. Stores the position at
@ -300,8 +296,7 @@ macro_rules! complete {
}; };
($i:expr, $efn:expr, $f:ident) => { ($i:expr, $efn:expr, $f:ident) => {
use $crate::run $crate::complete!($i, $efn, $crate::run!($f))
$crate::complete!($i, $efn, run!($f))
}; };
} }
@ -455,13 +450,13 @@ macro_rules! do_each {
macro_rules! either { macro_rules! either {
// Initialization case. // Initialization case.
($i:expr, $f:ident!( $( $args:tt )* ), $( $rest:tt)* ) => { // 0 ($i:expr, $f:ident!( $( $args:tt )* ), $( $rest:tt)* ) => { // 0
$crate::either!(__impl $i, $f!( $($args)* ), $($rest)*) either!(__impl $i, $f!( $($args)* ), $($rest)*)
}; };
// Initialization case. // Initialization case.
($i:expr, $f:ident, $($rest:tt)* ) => {{ // 1 ($i:expr, $f:ident, $($rest:tt)* ) => {{ // 1
use $crate::run; use $crate::run;
$crate::either!(__impl $i, run!($f), $($rest)*) either!(__impl $i, run!($f), $($rest)*)
}}; }};
// Initialization failure case. // Initialization failure case.
@ -472,24 +467,24 @@ macro_rules! either {
// Initialization failure case. // Initialization failure case.
($i:expr, $f:ident) => {{ // 3 ($i:expr, $f:ident) => {{ // 3
use $crate::run; use $crate::run;
$crate::either!($i, run!($f)) either!($i, run!($f))
}}; }};
// Termination clause // Termination clause
(__impl $i:expr, $f:ident) => {{ // 4 (__impl $i:expr, $f:ident) => {{ // 4
use $crate::run; use $crate::run;
$crate::either!(__impl $i, run!($f)) either!(__impl $i, run!($f))
}}; }};
// Termination clause // Termination clause
(__impl $i:expr, $f:ident,) => {{ // 5 (__impl $i:expr, $f:ident,) => {{ // 5
use $crate::run; use $crate::run;
$crate::either!(__impl $i, run!($f)) either!(__impl $i, run!($f))
}}; }};
// Termination clause // Termination clause
(__impl $i:expr, $f:ident!( $( $args:tt )* ),) => { // 6 (__impl $i:expr, $f:ident!( $( $args:tt )* ),) => { // 6
$crate::either!(__impl $i, $f!($($args)*) __end) either!(__impl $i, $f!($($args)*) __end)
}; };
// Termination clause // Termination clause
@ -538,7 +533,7 @@ macro_rules! either {
// Internal Loop Implementation // Internal Loop Implementation
(__impl $i:expr, $f:ident, $( $rest:tt )* ) => {{ // 9 (__impl $i:expr, $f:ident, $( $rest:tt )* ) => {{ // 9
use $crate::run; use $crate::run;
$crate::either!(__impl $i, run!($f), $( $rest )* ) either!(__impl $i, run!($f), $( $rest )* )
}} }}
} }
@ -587,11 +582,11 @@ where
macro_rules! optional { macro_rules! optional {
($i:expr, $f:ident) => {{ ($i:expr, $f:ident) => {{
use $crate::run; use $crate::run;
$crate::optional!(__impl $i, run!($f)) optional!(__impl $i, run!($f))
}}; }};
($i:expr, $f:ident!( $( $args:tt )* ) ) => { ($i:expr, $f:ident!( $( $args:tt )* ) ) => {
$crate::optional!(__impl $i, $f!( $( $args )* )) optional!(__impl $i, $f!( $( $args )* ))
}; };
(__impl $i:expr, $f:ident!( $( $args:tt )* )) => {{ (__impl $i:expr, $f:ident!( $( $args:tt )* )) => {{
@ -658,7 +653,7 @@ macro_rules! repeat {
($i:expr, $f:ident) => {{ ($i:expr, $f:ident) => {{
use $crate::run; use $crate::run;
$crate::repeat!($i, run!($f)) repeat!($i, run!($f))
}}; }};
} }
@ -714,20 +709,17 @@ macro_rules! separated {
} }
}}; }};
($i:expr, $sep_rule:ident, $item_rule:ident ) => {{ ($i:expr, $sep_rule:ident, $item_rule:ident ) => {
use $crate::run; separated!($i, $crate::run!($sep_rule), $crate::run!($item_rule))
$crate::separated!($i, run!($sep_rule), run!($item_rule)) };
}};
($i:expr, $sep_rule:ident!( $( $args:tt )* ), $item_rule:ident ) => {{ ($i:expr, $sep_rule:ident!( $( $args:tt )* ), $item_rule:ident ) => {
use $crate::run; separated!($i, $sep_rule!($($args)*), $crate::run!($item_rule))
$crate::separated!($i, $sep_rule!($($args)*), run!($item_rule)) };
}};
($i:expr, $sep_rule:ident, $item_rule:ident!( $( $args:tt )* ) ) => {{ ($i:expr, $sep_rule:ident, $item_rule:ident!( $( $args:tt )* ) ) => {
use $crate::run; separated!($i, $crate::run!($sep_rule), $item_rule!($($args)*))
$crate::separated!($i, run!($sep_rule), $item_rule!($($args)*)) };
}};
} }
/// Convenience macro for looking for a specific text token in a byte input stream. /// Convenience macro for looking for a specific text token in a byte input stream.
@ -819,10 +811,9 @@ macro_rules! until {
pfn() pfn()
}}; }};
($i:expr, $rule:ident) => {{ ($i:expr, $rule:ident) => {
use $crate::run; until!($i, $crate::run!($rule))
$crate::until!($i, run!($rule)) };
}};
} }
/// Discards the output of a combinator rule when it completes and just returns `()`. /// Discards the output of a combinator rule when it completes and just returns `()`.
@ -831,7 +822,7 @@ macro_rules! until {
macro_rules! discard { macro_rules! discard {
($i:expr, $rule:ident) => {{ ($i:expr, $rule:ident) => {{
use $crate::run; use $crate::run;
$crate::discard!($i, run!($rule)) discard!($i, run!($rule))
}}; }};
($i:expr, $rule:ident!( $( $args:tt )* ) ) => {{ ($i:expr, $rule:ident!( $( $args:tt )* ) ) => {{
@ -913,13 +904,11 @@ macro_rules! make_fn {
}; };
($name:ident<$i:ty, $o:ty>, $rule:ident) => { ($name:ident<$i:ty, $o:ty>, $rule:ident) => {
use $crate::run make_fn!($name<$i, $o>, $crate::run!($rule));
$crate::make_fn!($name<$i, $o>, run!($rule));
}; };
(pub $name:ident<$i:ty, $o:ty>, $rule:ident) => { (pub $name:ident<$i:ty, $o:ty>, $rule:ident) => {
use $crate::run make_fn!(pub $name<$i, $o>, $crate::run!($rule));
$crate::make_fn!(pub $name<$i, $o>, run!($rule));
}; };
} }
@ -930,7 +919,7 @@ macro_rules! make_fn {
#[macro_export] #[macro_export]
macro_rules! input { macro_rules! input {
($i:expr) => { ($i:expr) => {
$crate::input!($i,) input!($i,)
}; };
($i:expr,) => {{ ($i:expr,) => {{
@ -987,7 +976,7 @@ macro_rules! consume_all {
($i:expr, $rule:ident) => {{ ($i:expr, $rule:ident) => {{
use $crate::run; use $crate::run;
$crate::consume_all!($i, run!($rule)) consume_all!($i, run!($rule))
}} }}
} }

View File

@ -402,19 +402,6 @@ fn test_until() {
} }
} }
#[test]
fn test_until_with_function_composition() {
let input_str = "foo ";
let iter = StrIter::new(input_str);
let result = until!(iter, ascii_ws);
assert!(result.is_complete());
if let Result::Complete(i, o) = result {
assert_eq!(i.get_offset(), 3);
assert_eq!(o.len(), 3);
assert_eq!(o, "foo");
}
}
#[test] #[test]
fn test_until_abort() { fn test_until_abort() {
let input_str = "foo "; let input_str = "foo ";