From 5876b7b9706397efedfd9840bc02a0e2df41062c Mon Sep 17 00:00:00 2001 From: desbma-s1n Date: Wed, 29 May 2024 18:01:17 +0200 Subject: [PATCH] fix: update/fix regex parser --- src/strace/parser/mod.rs | 42 ++++++++++++++++++-------------------- src/strace/parser/regex.rs | 12 ++++++----- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/strace/parser/mod.rs b/src/strace/parser/mod.rs index 52f140e..5a9cc6f 100644 --- a/src/strace/parser/mod.rs +++ b/src/strace/parser/mod.rs @@ -269,15 +269,15 @@ mod tests { complement: true, values: vec![ Expression::Integer( - IntegerExpression { + IntegerExpression { value: IntegerExpressionValue::NamedConst("RTMIN".to_owned()), - metadata: None + metadata: None } ), Expression::Integer( - IntegerExpression { + IntegerExpression { value: IntegerExpressionValue::NamedConst("RT_1".to_owned()), - metadata: None + metadata: None } ), ] @@ -336,27 +336,27 @@ mod tests { complement: true, values: vec![ Expression::Integer( - IntegerExpression { - value: IntegerExpressionValue::NamedConst("KILL".to_owned()), - metadata: None + IntegerExpression { + value: IntegerExpressionValue::NamedConst("KILL".to_owned()), + metadata: None } ), Expression::Integer( - IntegerExpression { - value: IntegerExpressionValue::NamedConst("STOP".to_owned()), - metadata: None + IntegerExpression { + value: IntegerExpressionValue::NamedConst("STOP".to_owned()), + metadata: None } ), Expression::Integer( - IntegerExpression { - value: IntegerExpressionValue::NamedConst("RTMIN".to_owned()), - metadata: None + IntegerExpression { + value: IntegerExpressionValue::NamedConst("RTMIN".to_owned()), + metadata: None } ), Expression::Integer( - IntegerExpression { - value: IntegerExpressionValue::NamedConst("RT_1".to_owned()), - metadata: None + IntegerExpression { + value: IntegerExpressionValue::NamedConst("RT_1".to_owned()), + metadata: None } ), ], @@ -1331,12 +1331,10 @@ mod tests { }), Expression::Collection { complement: false, - values: vec![ - Expression::Integer(IntegerExpression { - value: IntegerExpressionValue::Literal(3), - metadata: None, - }) - ] + values: vec![Expression::Integer(IntegerExpression { + value: IntegerExpressionValue::Literal(3), + metadata: None, + })] }, Expression::Integer(IntegerExpression { value: IntegerExpressionValue::NamedConst("NULL".to_owned()), diff --git a/src/strace/parser/regex.rs b/src/strace/parser/regex.rs index 84b893f..88dc157 100644 --- a/src/strace/parser/regex.rs +++ b/src/strace/parser/regex.rs @@ -338,19 +338,21 @@ fn parse_argument(caps: ®ex::Captures) -> anyhow::Result { } else { let int_tokens = tokens .into_iter() - .map(|t| { + .map(|t| -> anyhow::Result<_> { if let Some(one_shift) = t.strip_prefix("1<<") { - IntegerExpressionValue::LeftBitShift { + Ok(IntegerExpressionValue::LeftBitShift { bits: Box::new(IntegerExpressionValue::Literal(1)), shift: Box::new(IntegerExpressionValue::NamedConst( one_shift.to_owned(), )), - } + }) + } else if t.starts_with("0") { + Ok(IntegerExpressionValue::Literal(i128::from_str_radix(t, 8)?)) } else { - IntegerExpressionValue::NamedConst(t.to_owned()) + Ok(IntegerExpressionValue::NamedConst(t.to_owned())) } }) - .collect(); + .collect::>()?; Ok(Expression::Integer(IntegerExpression { value: IntegerExpressionValue::BinaryOr(int_tokens), metadata: None,