forked from rust-bakery/nom
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inference.rs
54 lines (48 loc) · 1.3 KB
/
inference.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! test type inference issues in parsee compilation
//#![feature(trace_macros)]
#![allow(dead_code)]
#![allow(unused_comparisons)]
#![allow(unused_variables)]
#![allow(unused_imports)]
#[macro_use]
extern crate nom;
use nom::character::{is_digit, streaming::alpha1 as alpha};
use std::str;
// issue #617
named!(multi<&[u8], () >, fold_many0!( take_while1!( is_digit ), (), |_, _| {}));
// issue #561
#[cfg(feature = "alloc")]
named!(
value<Vec<Vec<&str>>>,
do_parse!(
first_line: map_res!(is_not!("\n"), std::str::from_utf8)
>> rest:
many_m_n!(
0,
1,
separated_list0!(
tag!("\n\t"),
map_res!(take_while!(call!(|c| c != b'\n')), std::str::from_utf8)
)
)
>> (rest)
)
);
// issue #534
#[cfg(feature = "alloc")]
fn wrap_suffix(input: &Option<Vec<&[u8]>>) -> Option<String> {
if input.is_some() {
// I've tried both of the lines below individually and get the same error.
Some("hello".to_string())
//Some(str::from_utf8(u).expect("Found invalid UTF-8").to_string())
} else {
None
}
}
#[cfg(feature = "alloc")]
named!(parse_suffix<&[u8],Option<String>>,do_parse!(
u: opt!(many1!(alt!(
complete!(tag!("%")) | complete!(tag!("#")) | complete!(tag!("@")) | complete!(alpha)
))) >>
(wrap_suffix(&u))
));