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 | 9d8f197 | 2016-09-04 11:58:48 -0700 | [diff] [blame] | 10 | pub mod parsing { |
| 11 | use super::*; |
| 12 | |
| 13 | fn ident_ch(ch: char) -> bool { |
| 14 | ch.is_alphanumeric() || ch == '_' |
| 15 | } |
| 16 | |
| 17 | named!(pub word<&str, Ident>, preceded!( |
| 18 | opt!(call!(::nom::multispace)), |
| 19 | map!(take_while1_s!(ident_ch), String::from) |
| 20 | )); |
| 21 | |
| 22 | named!(pub visibility<&str, Visibility>, preceded!( |
| 23 | opt!(call!(::nom::multispace)), |
| 24 | alt!( |
| 25 | terminated!(tag_s!("pub"), call!(::nom::multispace)) => { |_| Visibility::Public } |
| 26 | | |
| 27 | epsilon!() => { |_| Visibility::Inherited } |
| 28 | ) |
| 29 | )); |
David Tolnay | b79ee96 | 2016-09-04 09:39:20 -0700 | [diff] [blame] | 30 | } |