Fix negative integer literal parsing in fuzzer DSL.

This commit is contained in:
KtorZ 2024-03-04 23:27:23 +01:00
parent fbeb611e5f
commit 4097d1edb2
No known key found for this signature in database
GPG Key ID: 33173CB6F77F4277
1 changed files with 18 additions and 2 deletions

View File

@ -5,7 +5,7 @@ use crate::{
annotation, annotation,
chain::{call::parser as call, field_access, tuple_index::parser as tuple_index, Chain}, chain::{call::parser as call, field_access, tuple_index::parser as tuple_index, Chain},
error::ParseError, error::ParseError,
expr::{self, bytearray, int, list, string, tuple, var}, expr::{self, bytearray, int as uint, list, string, tuple, var},
token::Token, token::Token,
}, },
}; };
@ -88,9 +88,25 @@ pub fn fuzzer<'a>() -> impl Parser<Token, UntypedExpr, Error = ParseError> + 'a
call(expression.clone()), call(expression.clone()),
)); ));
let int = || {
just(Token::Minus)
.to(ast::UnOp::Negate)
.map_with_span(|op, span| (op, span))
.or_not()
.then(uint())
.map(|(op, value)| match op {
None => value,
Some((op, location)) => UntypedExpr::UnOp {
op,
location,
value: Box::new(value),
},
})
};
choice(( choice((
string(),
int(), int(),
string(),
bytearray(), bytearray(),
tuple(expression.clone()), tuple(expression.clone()),
list(expression.clone()), list(expression.clone()),