forked from M-Labs/nac3
fixed errors
This commit is contained in:
parent
1990486cc2
commit
06af1623a8
@ -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() {
|
||||
Number::Integer { .. } => {
|
||||
// not check the range now
|
||||
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())
|
||||
}
|
||||
// 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<Vec<_>, String> = elements
|
||||
.iter()
|
||||
.map(|v| parse_expr(&ctx, sym_table, v))
|
||||
.collect();
|
||||
Ok(ParametricType(TUPLE_TYPE, types?).into())
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user