aboutsummaryrefslogtreecommitdiff
path: root/tests/inference.rs
blob: 851c1382c9bc5a0457ae10cecc33eb96ddf3ab28 (plain)
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
//! 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 std::str;
use nom::character::{streaming::alpha1 as alpha, is_digit};

// 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_list!(
            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))
));