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