diff --git a/nac3core/src/expression.rs b/nac3core/src/expression.rs index 17ab351f0c..43c3cf9657 100644 --- a/nac3core/src/expression.rs +++ b/nac3core/src/expression.rs @@ -7,6 +7,7 @@ use rustpython_parser::ast::{ UnaryOperator, }; use std::collections::HashMap; +use std::convert::TryInto; use std::rc::Rc; type SymTable<'a> = HashMap<&'a str, Rc>; @@ -48,6 +49,7 @@ pub fn parse_expr(ctx: &GlobalContext, sym_table: &SymTable, expr: &Expression) } _ => Err("only list comprehension is supported".into()), }, + ExpressionType::True | ExpressionType::False => Ok(Some(PrimitiveType(BOOL_TYPE).into())), _ => Err("not supported".into()), } } @@ -59,16 +61,18 @@ fn parse_constant( ) -> ParserResult { use rustpython_parser::ast::Number; match value { - Number::Integer { .. } => { - // not check the range now - Ok(Some(PrimitiveType(INT32_TYPE).into())) - // if i32::try_from(&value).is_ok() { - // Ok(PrimitiveType(INT32_TYPE).into()) - // } else if i64::try_from(&value).is_ok() { - // Ok(PrimitiveType(INT64_TYPE).into()) - // } else { - // Err("integer out of range".into()) - // } + Number::Integer { value } => { + let int32: Result = value.try_into(); + if int32.is_ok() { + Ok(Some(PrimitiveType(INT32_TYPE).into())) + } else { + let int64: Result = value.try_into(); + if int64.is_ok() { + Ok(Some(PrimitiveType(INT64_TYPE).into())) + } else { + Err("integer out of range".into()) + } + } } Number::Float { .. } => Ok(Some(PrimitiveType(FLOAT_TYPE).into())), _ => Err("not supported".into()),