mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 18:24:09 +02:00
improve param_parse_with a bit
This commit is contained in:
parent
9bd6d16043
commit
3f51270509
2 changed files with 8 additions and 9 deletions
|
|
@ -275,18 +275,17 @@ fn param_parse_with<'a, T, P: Fn(&'a str) -> IResult<&'a str, T>>(
|
|||
parser: P,
|
||||
) -> impl Fn(&'a str) -> IResult<&'a str, T> {
|
||||
move |input: &str| {
|
||||
let (input, _) = opt(tag(" "))(input)?;
|
||||
let (input, open_tag) = opt(tag("("))(input)?;
|
||||
debug_assert!(input.as_bytes()[0] != b' ');
|
||||
let has_open = input.as_bytes()[0] == b'(';
|
||||
let input = &input[has_open as usize..];
|
||||
|
||||
let (input, _) = tag(key)(input)?;
|
||||
let (input, _) = tag(r#" "#)(input)?;
|
||||
let input = &input[key.len() + 1..]; // skip space + key
|
||||
|
||||
let (input, value) = parser(input)?;
|
||||
|
||||
if open_tag.is_some() {
|
||||
let (_input, _) = tag(")")(input)?;
|
||||
}
|
||||
Ok((input.trim_start(), value))
|
||||
let input = &input[has_open as usize..];
|
||||
|
||||
Ok((input.trim_start_matches(' '), value))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ pub struct KillEvent<'a> {
|
|||
|
||||
pub fn kill_event_parser(input: &str) -> IResult<&str, KillEvent> {
|
||||
let (input, target) = against_subject_parser(input)?;
|
||||
let (input, weapon) = param_parse("with")(input)?;
|
||||
let (input, weapon) = param_parse("with")(&input[1..])?;
|
||||
let mut event = KillEvent {
|
||||
target,
|
||||
weapon,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue