forked from M-Labs/nac3
1
0
Fork 0

nac3parser: modify parser to handle negative integer edge cases

This commit is contained in:
ychenfo 2021-12-02 02:54:11 +08:00 committed by Gitea
parent 8c05d8431d
commit 1f3aa48361
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,
};