mirror of
https://codeberg.org/icewind/tf-log-parser.git
synced 2026-06-03 10:14:10 +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,
|
parser: P,
|
||||||
) -> impl Fn(&'a str) -> IResult<&'a str, T> {
|
) -> impl Fn(&'a str) -> IResult<&'a str, T> {
|
||||||
move |input: &str| {
|
move |input: &str| {
|
||||||
let (input, _) = opt(tag(" "))(input)?;
|
debug_assert!(input.as_bytes()[0] != b' ');
|
||||||
let (input, open_tag) = opt(tag("("))(input)?;
|
let has_open = input.as_bytes()[0] == b'(';
|
||||||
|
let input = &input[has_open as usize..];
|
||||||
|
|
||||||
let (input, _) = tag(key)(input)?;
|
let input = &input[key.len() + 1..]; // skip space + key
|
||||||
let (input, _) = tag(r#" "#)(input)?;
|
|
||||||
|
|
||||||
let (input, value) = parser(input)?;
|
let (input, value) = parser(input)?;
|
||||||
|
|
||||||
if open_tag.is_some() {
|
let input = &input[has_open as usize..];
|
||||||
let (_input, _) = tag(")")(input)?;
|
|
||||||
}
|
Ok((input.trim_start_matches(' '), value))
|
||||||
Ok((input.trim_start(), value))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ pub struct KillEvent<'a> {
|
||||||
|
|
||||||
pub fn kill_event_parser(input: &str) -> IResult<&str, KillEvent> {
|
pub fn kill_event_parser(input: &str) -> IResult<&str, KillEvent> {
|
||||||
let (input, target) = against_subject_parser(input)?;
|
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 {
|
let mut event = KillEvent {
|
||||||
target,
|
target,
|
||||||
weapon,
|
weapon,
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue