From 06af1623a82a59d3275fa9de86090cad26ca18f4 Mon Sep 17 00:00:00 2001 From: pca006132 Date: Tue, 29 Dec 2020 11:42:16 +0800 Subject: [PATCH] fixed errors --- nac3core/src/expression.rs | 42 +++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/nac3core/src/expression.rs b/nac3core/src/expression.rs index 2329d94301..fd434aa601 100644 --- a/nac3core/src/expression.rs +++ b/nac3core/src/expression.rs @@ -14,45 +14,41 @@ pub fn parse_expr(ctx: &GlobalContext, sym_table: &SymTable, expr: &Expression) } fn parse_constant( - ctx: &GlobalContext, - sym_table: &SymTable, + _: &GlobalContext, + _: &SymTable, value: &rustpython_parser::ast::Number, ) -> ParserResult { use rustpython_parser::ast::Number; match value { - Number::Integer { value } => { - 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".to_string()) - } + Number::Integer { .. } => { + // not check the range now + Ok(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".to_string()) + // } } Number::Float { .. } => Ok(PrimitiveType(FLOAT_TYPE).into()), _ => Err("not supported".to_string()), } } -fn parse_identifier(ctx: &GlobalContext, sym_table: &SymTable, name: &str) -> ParserResult { +fn parse_identifier(_: &GlobalContext, sym_table: &SymTable, name: &str) -> ParserResult { match sym_table.get(name) { Some(v) => Ok(v.clone()), None => Err("unbounded variable".to_string()), } } -fn parse_list( - ctx: &GlobalContext, - sym_table: &SymTable, - elements: &[Expression], -) -> ParserResult { +fn parse_list(ctx: &GlobalContext, sym_table: &SymTable, elements: &[Expression]) -> ParserResult { if elements.len() == 0 { return Ok(ParametricType(LIST_TYPE, vec![BotType.into()]).into()); } - let mut types = elements - .iter() - .map(|v| parse_expr(&ctx, sym_table, v)); + let mut types = elements.iter().map(|v| parse_expr(&ctx, sym_table, v)); let head = types.next().unwrap()?; for v in types { @@ -63,4 +59,12 @@ fn parse_list( Ok(ParametricType(LIST_TYPE, vec![head]).into()) } +fn parse_tuple(ctx: &GlobalContext, sym_table: &SymTable, elements: &[Expression]) -> ParserResult { + let types: Result, String> = elements + .iter() + .map(|v| parse_expr(&ctx, sym_table, v)) + .collect(); + Ok(ParametricType(TUPLE_TYPE, types?).into()) +} +