Skip to content

Instantly share code, notes, and snippets.

@rust-play

rust-play/playground.rs Secret

Created Jun 10, 2020
Embed
What would you like to do?
Code shared from the Rust Playground
fn nom_str_until_eol(i: &str) -> nom::IResult<&str, &str> {
let first_line = i.lines().next();
if let Some(first_line) = first_line {
let rest = &i[first_line.len()..];
let rest = rest.trim();
Ok((rest, first_line))
} else {
Ok((i, ""))
}
}
fn nom_comment(i: &str) -> nom::IResult<&str, &str> {
let(i, _) = tag("%")(i)?;
let(i, comment) = nom_str_until_eol(i)?;
Ok((i, comment))
}
fn nom_other_thing(i: &str) -> nom::IResult<&str, &str> {
let(i, _) = tag("fn")(i)?;
let(i, function_line) = nom_str_until_eol(i)?;
Ok((i, function_line))
}
fn nom_either(i: &str) -> nom::IResult<&str, &str> {
alt(nom_comment, nom_other_thing)(i)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment