#![doc(test(attr(allow(unused_variables), deny(warnings))))]
#[macro_use]
extern crate nom;
#[macro_use]
extern crate hexf_parse;
#[cfg(feature="graphviz")]
extern crate dot;
macro_rules! ast_panic_test {
($name: ident, $func: ident, $input: expr) => {
#[test]
#[should_panic]
fn $name () {
use super::*;
$func($input.as_bytes()).unwrap().1;
}
}
}
macro_rules! ast_test {
($name: ident, $func: ident, $input: expr, $output: expr) => {
#[test]
fn $name () {
use super::*;
assert_eq!($func($input.as_bytes()).unwrap().1, $output);
}
}
}
macro_rules! ast_valid {
($name: ident, $func: ident, $input: expr) => {
#[test]
fn $name () {
use super::*;
assert!(match $func($input.as_bytes()).unwrap().1 {
_ => true,
});
}
}
}
macro_rules! ast_invalid {
($name: ident, $func: ident, $input: expr) => {
#[test]
#[should_panic]
fn $name () {
use super::*;
$func($input.as_bytes()).unwrap().1;
}
}
}
macro_rules! astb {
($name: ident, $($a: expr),*) => {
$name($(Box::new($a)),*)
};
}
macro_rules! ast {
($name: ident) => {
$name
};
($name: ident, $($a: expr),*) => {
$name($($a),*)
};
}
use function::parse_block;
pub use ast::ASTNode;
use std::io::Read;
pub mod ast;
pub mod op;
pub mod number;
pub mod exp;
pub mod string;
pub mod name;
pub mod var;
pub mod field;
pub mod statement;
pub mod function;
pub use nom::IResult;
use exp::parse_exp;
named!(pub parse_chunk<ASTNode>, dbg_dmp!(ws!(parse_exp)));
pub fn parse_string<'a, T: Into<&'a [u8]>>(s: T) -> Option<ASTNode> {
match parse_chunk(s.into()) {
IResult::Done(_, a) => Some(a),
_ => None
}
}
pub fn parse<T: Read>(mut s: T) -> Option<ASTNode> {
let mut buf = vec![];
s.read_to_end(&mut buf);
buf.pop(); match parse_chunk(&buf) {
IResult::Done(_, a) => Some(a),
_ => None
}
}