Skip to content

Commit

Permalink
fix: update/fix regex parser
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma-s1n committed May 29, 2024
1 parent 09d4735 commit 5876b7b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 27 deletions.
42 changes: 20 additions & 22 deletions src/strace/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
),
]
Expand Down Expand Up @@ -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
}
),
],
Expand Down Expand Up @@ -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()),
Expand Down
12 changes: 7 additions & 5 deletions src/strace/parser/regex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,19 +338,21 @@ fn parse_argument(caps: &regex::Captures) -> anyhow::Result<Expression> {
} 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::<Result<_, _>>()?;
Ok(Expression::Integer(IntegerExpression {
value: IntegerExpressionValue::BinaryOr(int_tokens),
metadata: None,
Expand Down

0 comments on commit 5876b7b

Please sign in to comment.