mirror of
https://github.com/zaphar/abortable_parser.git
synced 2025-07-22 20:39:50 -04:00
42 lines
1010 B
Rust
42 lines
1010 B
Rust
use iter::StrIter;
|
|
use super::{Result, eoi, ascii_ws};
|
|
|
|
make_fn!(proto<StrIter, &str>,
|
|
do_each!(
|
|
proto => until!(text_token!("://")),
|
|
_ => must!(text_token!("://")),
|
|
(proto)
|
|
)
|
|
);
|
|
|
|
make_fn!(domain<StrIter, &str>,
|
|
until!(either!(
|
|
discard!(text_token!("/")),
|
|
discard!(ascii_ws),
|
|
eoi))
|
|
);
|
|
|
|
make_fn!(path<StrIter, &str>,
|
|
until!(either!(discard!(ascii_ws), eoi))
|
|
);
|
|
|
|
make_fn!(pub url<StrIter, (Option<&str>, Option<&str>, &str)>,
|
|
do_each!(
|
|
protocol => optional!(proto),
|
|
domain => optional!(domain),
|
|
path => path,
|
|
(protocol, domain, path)
|
|
)
|
|
);
|
|
|
|
#[test]
|
|
fn test_url_parser() {
|
|
let iter = StrIter::new("http://example.com/some/path ");
|
|
let result = url(iter);
|
|
assert!(result.is_complete());
|
|
if let Result::Complete(_, (proto, domain, path)) = result {
|
|
assert!(proto.is_some());
|
|
assert!(domain.is_some());
|
|
assert_eq!(path, "/some/path");
|
|
}
|
|
}
|