pub fn parse_gomod(text: &str) -> Result<GoMod<'_>, Err<Error<(u32, usize)>>>Expand description
Return an error indicating (line, offset)
Examples found in repository?
examples/parse.rs (line 6)
3fn main() {
4 let mod_file = std::env::args().nth(1).expect("specify a go.mod filepath");
5 let contents = std::fs::read_to_string(mod_file).unwrap();
6 let gomod = parse_gomod(&contents).unwrap();
7 gomod
8 .iter()
9 .filter_map(|i| match i {
10 Context {
11 value: Directive::Require { specs },
12 ..
13 } => Some(specs),
14 _ => None,
15 })
16 .for_each(|require_specs| {
17 require_specs.iter().for_each(|spec| {
18 println!(
19 "Requirement {{name: {}, version: {}}} at line {}, fragment: {}",
20 spec.value.0,
21 &spec.value.1 as &str,
22 spec.range.0.line,
23 &contents[spec.range.0.offset..spec.range.1.offset]
24 );
25 });
26 });
27}