Nom parser: which alt branch succeeded?

Using the nom parser framework I have the following parser construct:

let (r, s) = alt ((
   parser_alt_0,
   parser_alt_1,
   ...
))(input)?;

Each parser_alt_i returns, if successful, a different parser result construct from the others which need post processing to construct the final result. How can I identify which parser_alt_i branch succeeded so as to be able to apply:

let result = match s {
     parser_alt_0_success(p) => post_process_0(p),
     parser_alt_1_success(p) => post_process_1(p),
     ...
};
Ok((r, result))

Thanks!

1 Like

Got it: use map.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.