Skip to content

Commit

Permalink
Fixed elided_named_lifetimes warning
Browse files Browse the repository at this point in the history
```text
warning: elided lifetime has a name
  --> lib/gml-parser/src/parser.rs:45:65
   |
45 | pub fn key<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, &str, E> {
   |            -- lifetime `'a` declared here                       ^ this elided lifetime gets resolved as `'a`
   |
   = note: `#[warn(elided_named_lifetimes)]` on by default
```
  • Loading branch information
stevenengler committed Oct 8, 2024
1 parent 2e032f5 commit ca337da
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/lib/gml-parser/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ fn take_verify<'a, E: GmlParseError<'a>>(
}

/// Parse a GML key.
pub fn key<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, &str, E> {
pub fn key<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
// a key starts with the a character [a-zA-Z_], and has remaining characters [a-zA-Z0-9_]
let take_first = take_verify(1, |chr| is_alphabetic(chr as u8) || chr == '_');
let take_remaining = take_while(|chr| is_alphanumeric(chr as u8) || chr == '_');
Expand All @@ -51,7 +51,7 @@ pub fn key<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, &str, E> {
}

/// Parse a GML item (a key + value).
pub fn item<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, GmlItem, E> {
pub fn item<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, GmlItem<'a>, E> {
match key(input)? {
(input, "node") => node(input).map(|(input, node)| (input, GmlItem::Node(node))),
(input, "edge") => edge(input).map(|(input, edge)| (input, GmlItem::Edge(edge))),
Expand All @@ -65,7 +65,7 @@ pub fn item<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, GmlItem,
}

/// Parse a GML graph.
pub fn gml<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Gml, E> {
pub fn gml<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, Gml<'a>, E> {
let (input, _) = multispace0(input)?;
let (input, _) = tag("graph")(input)?;
let (input, _) = space0(input)?;
Expand Down Expand Up @@ -150,7 +150,7 @@ pub fn gml<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Gml, E> {
}

/// Parse a GML node.
fn node<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Node, E> {
fn node<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, Node<'a>, E> {
let (input, _) = space0(input)?;
let (input, _) = tag("[")(input)?;
let (input, _) = newline(input)?;
Expand Down Expand Up @@ -178,7 +178,7 @@ fn node<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Node, E> {
}

/// Parse a GML edge.
fn edge<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Edge, E> {
fn edge<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, Edge<'a>, E> {
let (input, _) = space0(input)?;
let (input, _) = tag("[")(input)?;
let (input, _) = newline(input)?;
Expand Down Expand Up @@ -223,18 +223,18 @@ fn value<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, Value<'a>
Ok((input, value))
}

fn int<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Value<'a>, E> {
fn int<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, Value<'a>, E> {
let (input, value) = map_res(recognize(digit1), str::parse)(input)?;
Ok((input, Value::Int(value)))
}

fn float<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Value<'a>, E> {
fn float<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, Value<'a>, E> {
let (input, value) = map_res(nom::number::complete::recognize_float, str::parse)(input)?;
Ok((input, Value::Float(value)))
}

/// Parse a GML string.
fn string<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Value<'a>, E> {
fn string<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, Value<'a>, E> {
let (input, _) = tag("\"")(input)?;
let (input, value) = escaped_transform(
is_not("\""),
Expand All @@ -249,7 +249,7 @@ fn string<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, Value<'a>,
Ok((input, Value::Str(value.into())))
}

fn newline<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, &str, E> {
fn newline<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, &'a str, E> {
recognize(tuple((space0, multispace1, space0)))(input)
}

Expand All @@ -261,7 +261,7 @@ fn int_to_bool(x: i32) -> Result<bool, &'static str> {
}
}

fn int_as_bool<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&str, bool, E> {
fn int_as_bool<'a, E: GmlParseError<'a>>(input: &'a str) -> IResult<&'a str, bool, E> {
let (input, value) = value(input)?;

let value = match value {
Expand Down

0 comments on commit ca337da

Please sign in to comment.