David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 1 | pub type Ident = String; |
| 2 | |
| 3 | #[derive(Debug, Clone, Eq, PartialEq)] |
| 4 | pub enum Visibility { |
| 5 | Public, |
| 6 | Inherited, |
| 7 | } |
| 8 | |
David Tolnay | 86eca75 | 2016-09-04 11:26:41 -0700 | [diff] [blame^] | 9 | #[cfg(feature = "parsing")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 10 | fn ident_ch(ch: char) -> bool { |
| 11 | ch.is_alphanumeric() || ch == '_' |
| 12 | } |
| 13 | |
David Tolnay | 86eca75 | 2016-09-04 11:26:41 -0700 | [diff] [blame^] | 14 | #[cfg(feature = "parsing")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 15 | named!(pub word<&str, Ident>, preceded!( |
| 16 | opt!(call!(::nom::multispace)), |
| 17 | map!(take_while1_s!(ident_ch), String::from) |
| 18 | )); |
| 19 | |
David Tolnay | 86eca75 | 2016-09-04 11:26:41 -0700 | [diff] [blame^] | 20 | #[cfg(feature = "parsing")] |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 21 | named!(pub visibility<&str, Visibility>, preceded!( |
David Tolnay | 65e7f30 | 2016-09-04 10:19:25 -0700 | [diff] [blame] | 22 | opt!(call!(::nom::multispace)), |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 23 | alt!( |
| 24 | terminated!(tag_s!("pub"), call!(::nom::multispace)) => { |_| Visibility::Public } |
| 25 | | |
| 26 | epsilon!() => { |_| Visibility::Inherited } |
| 27 | ) |
| 28 | )); |