Skip to content

Instantly share code, notes, and snippets.

@aljce
Created September 11, 2016 23:13
Show Gist options
  • Save aljce/ace19cc40ea1f502befa88d7191b9cd1 to your computer and use it in GitHub Desktop.
Save aljce/ace19cc40ea1f502befa88d7191b9cd1 to your computer and use it in GitHub Desktop.
struct Group<'a> {
name: &'a str,
groups: Vec<&'a str>
}
fn is_whitespace(c: char) -> bool {
c == ' ' || c == '\t' || c == '\n'
}
fn isnt_whitespace(c: char) -> bool {
!is_whitespace(c)
}
named!(pub name<&str,&str> ,
take_while1_s!(isnt_whitespace)
);
named!(pub group<&str, Group> ,chain!(
name: name ~
groups: separated_list!(take_while1_s!(is_whitespace) , name),
|| {Group{name: name, groups: groups}}
)
);
/*
cargo run
Compiling spotfiles v0.1.0 (file:///home/kyle/repos/spotfiles)
<nom macros>:1:36: 1:49 error: expected function, found `&str`
<nom macros>:1 ( $ i : expr , $ fun : expr ) => ( $ fun ( $ i ) ) ; (
^~~~~~~~~~~~~
<nom macros>:24:63: 6:37 note: in this expansion of call! (defined in <nom macros>)
<nom macros>:24:1: 24:74 note: in this expansion of separated_list! (defined in <nom macros>)
lexer.rs:23:27: 141:42 note: in this expansion of separated_list! (defined in <nom macros>)
<nom macros>:50:19: 53:39 note: in this expansion of chaining_parser! (defined in <nom macros>)
<nom macros>:38:1: 39:63 note: in this expansion of chaining_parser! (defined in <nom macros>)
<nom macros>:2:3: 2:54 note: in this expansion of chaining_parser! (defined in <nom macros>)
lexer.rs:21:37: 32:34 note: in this expansion of chain! (defined in <nom macros>)
lexer.rs:21:1: 26:3 note: in this expansion of named! (defined in <nom macros>)
<nom macros>:39:20: 39:34 note: defined here
<nom macros>:39 $ i , $ consumed , $ field : call ! ( $ e ) ~ $ ( $ rest ) * ) ; ) ; (
^~~~~~~~~~~~~~
<nom macros>:38:1: 39:63 note: in this expansion of chaining_parser! (defined in <nom macros>)
<nom macros>:2:3: 2:54 note: in this expansion of chaining_parser! (defined in <nom macros>)
lexer.rs:21:37: 32:34 note: in this expansion of chain! (defined in <nom macros>)
lexer.rs:21:1: 26:3 note: in this expansion of named! (defined in <nom macros>)
<nom macros>:1:36: 1:49 error: expected function, found `&str`
<nom macros>:1 ( $ i : expr , $ fun : expr ) => ( $ fun ( $ i ) ) ; (
^~~~~~~~~~~~~
<nom macros>:24:63: 19:55 note: in this expansion of call! (defined in <nom macros>)
<nom macros>:24:1: 24:74 note: in this expansion of separated_list! (defined in <nom macros>)
lexer.rs:23:27: 141:42 note: in this expansion of separated_list! (defined in <nom macros>)
<nom macros>:50:19: 53:39 note: in this expansion of chaining_parser! (defined in <nom macros>)
<nom macros>:38:1: 39:63 note: in this expansion of chaining_parser! (defined in <nom macros>)
<nom macros>:2:3: 2:54 note: in this expansion of chaining_parser! (defined in <nom macros>)
lexer.rs:21:37: 32:34 note: in this expansion of chain! (defined in <nom macros>)
lexer.rs:21:1: 26:3 note: in this expansion of named! (defined in <nom macros>)
<nom macros>:39:20: 39:34 note: defined here
<nom macros>:39 $ i , $ consumed , $ field : call ! ( $ e ) ~ $ ( $ rest ) * ) ; ) ; (
^~~~~~~~~~~~~~
<nom macros>:38:1: 39:63 note: in this expansion of chaining_parser! (defined in <nom macros>)
<nom macros>:2:3: 2:54 note: in this expansion of chaining_parser! (defined in <nom macros>)
lexer.rs:21:37: 32:34 note: in this expansion of chain! (defined in <nom macros>)
lexer.rs:21:1: 26:3 note: in this expansion of named! (defined in <nom macros>)
error: aborting due to 2 previous errors
error: Could not compile `spotfiles`.
To learn more, run the command again with --verbose.
Cargo-Process exited abnormally with code 101 at Sun Sep 11 19:06:56
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment