-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to Nom 3.2 #27
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,10 +139,10 @@ named!(pub parse_f32<f32>, | |
map_res!(map_res!(fdigit, str::from_utf8), FromStr::from_str)); | ||
|
||
/// Parses a sequence of whitespace seperated u32s. | ||
named!(pub parse_u32s<Vec<u32> >, separated_list!(space, complete!(parse_u32))); | ||
named!(pub parse_u32s<Vec<u32> >, separated_list_complete!(space, parse_u32)); | ||
|
||
/// Parses a sequence of whitespace seperated i32s. | ||
named!(pub parse_i32s<Vec<i32> >, separated_list!(space, parse_i32)); | ||
named!(pub parse_i32s<Vec<i32> >, separated_list_complete!(space, parse_i32)); | ||
|
||
/// Parses a bit into a boolean | ||
named!(pub parse_bit<bool>, alt!( | ||
|
@@ -152,7 +152,12 @@ named!(pub parse_bit<bool>, alt!( | |
|
||
/// Parses a usize followed by a kB unit tag. | ||
named!(pub parse_kb<usize>, | ||
chain!(space ~ bytes: parse_usize ~ space ~ tag!("kB"), || { bytes })); | ||
do_parse!( | ||
space >> | ||
bytes: parse_usize >> | ||
space >> | ||
opt!(tag!("kB")) >> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I may have misinterpreted the logic of the chain, this may not need to be wrapped in |
||
(bytes))); | ||
|
||
/// Parses a u32 in base-16 format. | ||
named!(pub parse_u32_hex<u32>, | ||
|
@@ -181,7 +186,7 @@ fn reverse(n: u8) -> u8 { | |
/// | ||
/// See cpuset(7) for the format being parsed. | ||
named!(pub parse_u32_mask_list<Box<[u8]> >, | ||
map!(separated_nonempty_list!(tag!(","), parse_u32_hex), |mut ints: Vec<u32>| { | ||
map!(separated_nonempty_list_complete!(tag!(","), parse_u32_hex), |mut ints: Vec<u32>| { | ||
let mut bytes: Vec<u8> = Vec::with_capacity(ints.len() * 4); | ||
let mut buf: [u8; 4] = [0; 4]; | ||
ints.reverse(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,18 +29,27 @@ pub struct Statm { | |
|
||
/// Parses the statm file format. | ||
named!(parse_statm<Statm>, | ||
chain!(size: parse_usize ~ space ~ | ||
resident: parse_usize ~ space ~ | ||
share: parse_usize ~ space ~ | ||
text: parse_usize ~ space ~ | ||
digit ~ space ~ // lib - unused since linux 2.6 | ||
data: parse_usize ~ space ~ | ||
digit ~ line_ending, // dt - unused since linux 2.6 | ||
|| { Statm { size: size, | ||
resident: resident, | ||
share: share, | ||
text: text, | ||
data: data } })); | ||
do_parse!( | ||
size: parse_usize >> | ||
space >> | ||
resident: parse_usize >> | ||
space >> | ||
share: parse_usize >> | ||
space >> | ||
text: parse_usize >> | ||
space >> | ||
digit >> | ||
space >> // lib - unused since linux 2.6 | ||
data: parse_usize >> | ||
space >> | ||
digit >> | ||
opt!(line_ending) >> // dt - unused since linux 2.6 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto, do you think I can drop the |
||
(Statm { | ||
size: size, | ||
resident: resident, | ||
share: share, | ||
text: text, | ||
data: data } ))); | ||
|
||
/// Parses the provided statm file. | ||
fn statm_file(file: &mut File) -> Result<Statm> { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -194,12 +194,29 @@ named!(parse_tid<pid_t>, delimited!(tag!("Pid:\t"), parse_i32, | |
named!(parse_ppid<pid_t>, delimited!(tag!("PPid:\t"), parse_i32, line_ending)); | ||
named!(parse_tracer_pid<pid_t>, delimited!(tag!("TracerPid:\t"), parse_i32, line_ending)); | ||
|
||
named!(parse_uid<(uid_t, uid_t, uid_t, uid_t)>, chain!(tag!("Uid:\t") ~ real: parse_u32 ~ space ~ effective: parse_u32 | ||
~ space ~ saved: parse_u32 ~ space ~ fs: parse_u32 ~ line_ending, | ||
|| { (real, effective, saved, fs) })); | ||
named!(parse_gid<(gid_t, gid_t, gid_t, gid_t)>, chain!(tag!("Gid:\t") ~ real: parse_u32 ~ space ~ effective: parse_u32 | ||
~ space ~ saved: parse_u32 ~ space ~ fs: parse_u32 ~ line_ending, | ||
|| { (real, effective, saved, fs) })); | ||
named!(parse_uid<(uid_t, uid_t, uid_t, uid_t)>, do_parse!( | ||
tag!("Uid:\t") >> | ||
real: parse_u32 >> | ||
space >> | ||
effective: parse_u32 >> | ||
space >> | ||
saved: parse_u32 >> | ||
space >> | ||
fs: parse_u32 >> | ||
opt!(line_ending) >> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
((real, effective, saved, fs)))); | ||
|
||
named!(parse_gid<(gid_t, gid_t, gid_t, gid_t)>, do_parse!( | ||
tag!("Gid:\t") >> | ||
real: parse_u32 >> | ||
space >> | ||
effective: parse_u32 >> | ||
space >> | ||
saved: parse_u32 >> | ||
space >> | ||
fs: parse_u32 >> | ||
opt!(line_ending) >> | ||
((real, effective, saved, fs)))); | ||
|
||
named!(parse_fd_allocated<u32>, delimited!(tag!("FDSize:\t"), parse_u32, line_ending)); | ||
named!(parse_groups<Vec<gid_t> >, delimited!(tag!("Groups:\t"), parse_u32s, multispace)); | ||
|
@@ -248,8 +265,16 @@ named!(parse_seccomp<SeccompMode>, delimited!(tag!("Seccomp:\t"), parse | |
named!(parse_cpus_allowed<Box<[u8]> >, delimited!(tag!("Cpus_allowed:\t"), parse_u32_mask_list, line_ending)); | ||
named!(parse_mems_allowed<Box<[u8]> >, delimited!(tag!("Mems_allowed:\t"), parse_u32_mask_list, line_ending)); | ||
|
||
named!(parse_cpus_allowed_list<()>, chain!(tag!("Cpus_allowed_list:\t") ~ not_line_ending ~ line_ending, || { () })); | ||
named!(parse_mems_allowed_list<()>, chain!(tag!("Mems_allowed_list:\t") ~ not_line_ending ~ line_ending, || { () })); | ||
named!(parse_cpus_allowed_list<()>, do_parse!( | ||
tag!("Cpus_allowed_list:\t") >> | ||
not_line_ending >> | ||
opt!(line_ending) >> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ditto |
||
(()))); | ||
named!(parse_mems_allowed_list<()>, do_parse!( | ||
tag!("Mems_allowed_list:\t") >> | ||
not_line_ending >> | ||
opt!(line_ending) >> | ||
(()))); | ||
|
||
named!(parse_voluntary_ctxt_switches<u64>, delimited!(tag!("voluntary_ctxt_switches:\t"), parse_u64, line_ending)); | ||
named!(parse_nonvoluntary_ctxt_switches<u64>, delimited!(tag!("nonvoluntary_ctxt_switches:\t"), parse_u64, line_ending)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what the significance of this change is, but it was failing to unwrap Incomplete results until I changed this.