Skip to content

Instantly share code, notes, and snippets.

@Kimundi
Created July 30, 2018 15:47
Show Gist options
  • Save Kimundi/46f4f017a484b288f46762becf01bc21 to your computer and use it in GitHub Desktop.
Save Kimundi/46f4f017a484b288f46762becf01bc21 to your computer and use it in GitHub Desktop.
#[macro_use]
extern crate nom;
#[derive(Debug, PartialEq)]
enum Keyword {
Func,
}
#[derive(Debug, PartialEq)]
enum Sexp {
Token(Vec<u8>),
/*
Keyword(Keyword),
U32(u32),
U64(u64),
S32(i32),
S64(i64),
F32(u64),
F64(u64),
String(Vec<u8>),
Id(String),
*/
Parens(Vec<Sexp>),
}
named!(linechar <&str, char>, none_of!("\x0a"));
named!(linecomment <&str, ()>, do_parse!(
tag!(";;")
>> many0!(linechar)
>> alt!(
tag!("\x0a")
| eof!()
)
>> (())
));
named!(comment <&str, ()>, alt!(
linecomment
// | blockcomment
));
named!(format <&str, ()>, map!(one_of!("\x09\x0a\x0d"), |_| ()));
named!(whitespace <&str, ()>, many0!(alt!(
map!(tag!(" "), |_| ())
| format
| comment
)));
named!(sexpr <&str, Sexp>, alt!(
do_parse!(
whitespace
>> tag!("(")
>> sub: sexpr
>> whitespace
>> tag!(")")
>> (sub)
)
));
#[cfg(test)]
mod tests {
use nom::Context::Code;
use nom::Err::Error;
use nom::Err::Incomplete;
use nom::ErrorKind::Alt;
use nom::Needed::Size;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment