Parser modification to handle negative integer edge cases #121

Merged
sb10q merged 1 commits from integer_range_fix into master 2021-12-03 16:35:58 +08:00
1 changed files with 12 additions and 2 deletions

View File

@ -5,7 +5,7 @@
use std::iter::FromIterator;
use crate::ast;
use crate::ast::{self, Constant};
use crate::fstring::parse_located_fstring;
use crate::function::{ArgumentList, parse_args, parse_params};
use crate::error::LexicalError;
@ -916,7 +916,17 @@ Factor: ast::Expr = {
<location:@L> <op:UnaryOp> <e:Factor> => ast::Expr {
location,
custom: (),
node: ast::ExprKind::UnaryOp { operand: Box::new(e), op }
node: {
match (&op, &e.node) {
(ast::Unaryop::USub, ast::ExprKind::Constant { value: Constant::Int(val), kind }) => {
ast::ExprKind::Constant {
value: Constant::Int(-val),
kind: kind.clone()
}
}
_ => ast::ExprKind::UnaryOp { operand: Box::new(e), op }
}
}
},
Power,
};