[][src]Function rustpython_parser::parser::parse_expression

pub fn parse_expression(source: &str) -> Result<Expression, ParseError>

Parses a python expression

Example

extern crate num_bigint;
use num_bigint::BigInt;
use rustpython_parser::{parser, ast};
let expr = parser::parse_expression("1 + 2").unwrap();

assert_eq!(ast::Expression {
        location: ast::Location::new(1, 3),
        node: ast::ExpressionType::Binop {
            a: Box::new(ast::Expression {
                location: ast::Location::new(1, 1),
                node: ast::ExpressionType::Number {
                    value: ast::Number::Integer { value: BigInt::from(1) }
                }
            }),
            op: ast::Operator::Add,
            b: Box::new(ast::Expression {
                location: ast::Location::new(1, 5),
                node: ast::ExpressionType::Number {
                    value: ast::Number::Integer { value: BigInt::from(2) }
                }
            })
        }
    },
    expr);