1#![doc(test(attr(allow(unused_variables), deny(warnings))))]
12
13#[macro_use]
14extern crate nom;
15
16#[macro_use]
17extern crate hexf_parse;
18
19#[cfg(feature="graphviz")]
20extern crate dot;
21
22macro_rules! ast_panic_test {
26 ($name: ident, $func: ident, $input: expr) => {
27 #[test]
28 #[should_panic]
29 fn $name () {
30 use super::*;
31 $func($input.as_bytes()).unwrap().1;
32 }
33 }
34}
35
36macro_rules! ast_test {
37 ($name: ident, $func: ident, $input: expr, $output: expr) => {
38 #[test]
39 fn $name () {
40 use super::*;
41 assert_eq!($func($input.as_bytes()).unwrap().1, $output);
42 }
43 }
44}
45
46macro_rules! ast_valid {
47 ($name: ident, $func: ident, $input: expr) => {
48 #[test]
49 fn $name () {
50 use super::*;
51 assert!(match $func($input.as_bytes()).unwrap().1 {
52 _ => true,
53 });
54 }
55 }
56}
57
58macro_rules! ast_invalid {
59 ($name: ident, $func: ident, $input: expr) => {
60 #[test]
61 #[should_panic]
62 fn $name () {
63 use super::*;
64 $func($input.as_bytes()).unwrap().1;
65 }
66 }
67}
68
69macro_rules! astb {
70 ($name: ident, $($a: expr),*) => {
71 $name($(Box::new($a)),*)
72 };
73}
74
75macro_rules! ast {
76 ($name: ident) => {
77 $name
78 };
79 ($name: ident, $($a: expr),*) => {
80 $name($($a),*)
81 };
82}
83
84
85
86use function::parse_block;
87pub use ast::ASTNode;
88use std::io::Read;
89
90pub mod ast;
91pub mod op;
92pub mod number;
93pub mod exp;
94pub mod string;
95pub mod name;
96pub mod var;
97pub mod field;
98pub mod statement;
99pub mod function;
100
101pub use nom::IResult;
102
103use exp::parse_exp;
105named!(pub parse_chunk<ASTNode>, dbg_dmp!(ws!(parse_exp)));
106
107pub fn parse_string<'a, T: Into<&'a [u8]>>(s: T) -> Option<ASTNode> {
109 match parse_chunk(s.into()) {
110 IResult::Done(_, a) => Some(a),
111 _ => None
112 }
113}
114
115pub fn parse<T: Read>(mut s: T) -> Option<ASTNode> {
116 let mut buf = vec![];
117 s.read_to_end(&mut buf);
118 buf.pop(); match parse_chunk(&buf) {
120 IResult::Done(_, a) => Some(a),
121 _ => None
122 }
123}