1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
pub use self::{ast::*, parse::*};

/// Surface syntax tree.
mod ast;
/// Parser, based on pest.
mod parse;

/// Parse a string into an optional declaration list and print error to stderr.
#[inline]
pub fn parse_str_err_printed(code: &str) -> Option<Vec<ExprDecl>> {
    parse_str(code).map_err(|err| eprintln!("{}", err)).ok()
}

/// Parse a string into an optional standalone expression
/// and print error to stderr.
#[inline]
pub fn parse_expr_err_printed(code: &str) -> Option<Expr> {
    parse_str_expr(code)
        .map_err(|err| eprintln!("{}", err))
        .ok()
}

#[cfg(test)]
mod tests;