Skip to content

Commit

Permalink
Cleaner way to ignore return value.
Browse files Browse the repository at this point in the history
  • Loading branch information
kaj committed Feb 3, 2025
1 parent 90c894b commit 808c25b
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/expression.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ pub fn expression(input: &[u8]) -> PResult<&str> {
recognize(context(
"Expected rust expression",
(
map_res(alt((tag("&"), tag("*"), tag(""))), input_to_str),
alt((tag("&"), tag("*"), tag(""))),
alt((
rust_name,
map_res(digit1, input_to_str),
Expand Down
4 changes: 2 additions & 2 deletions src/spacelike.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ use crate::parseresult::PResult;
use nom::branch::alt;
use nom::bytes::complete::{is_not, tag};
use nom::character::complete::{multispace1, none_of};
use nom::combinator::{map, value};
use nom::combinator::value;
use nom::multi::many0;
use nom::sequence::preceded;
use nom::Parser as _;

pub fn spacelike(input: &[u8]) -> PResult<()> {
map(many0(alt((comment, map(multispace1, |_| ())))), |_| ()).parse(input)
value((), many0(alt((comment, value((), multispace1))))).parse(input)
}

pub fn comment(input: &[u8]) -> PResult<()> {
Expand Down
26 changes: 12 additions & 14 deletions src/template.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use nom::branch::alt;
use nom::bytes::complete::is_not;
use nom::bytes::complete::tag;
use nom::character::complete::{char, multispace0};
use nom::combinator::{map, map_res, opt, recognize};
use nom::combinator::{map, map_res, opt, recognize, value};
use nom::error::context;
use nom::multi::{many0, many_till, separated_list0, separated_list1};
use nom::sequence::{delimited, preceded, terminated};
Expand Down Expand Up @@ -152,7 +152,8 @@ fn formal_argument(input: &[u8]) -> PResult<&str> {
}

fn type_expression(input: &[u8]) -> PResult<()> {
map(
value(
(),
(
alt((tag("&"), tag(""))),
opt(lifetime),
Expand All @@ -164,40 +165,37 @@ fn type_expression(input: &[u8]) -> PResult<()> {
context(
"Expected rust type expression",
alt((
map(rust_name, |_| ()),
map(
delimited(tag("["), type_expression, tag("]")),
|_| (),
),
map(
delimited(tag("("), comma_type_expressions, tag(")")),
|_| (),
value((), rust_name),
delimited(tag("["), value((), type_expression), tag("]")),
delimited(
tag("("),
value((), comma_type_expressions),
tag(")"),
),
)),
),
opt(delimited(tag("<"), comma_type_expressions, tag(">"))),
),
|_| (),
)
.parse(input)
}

pub fn comma_type_expressions(input: &[u8]) -> PResult<()> {
map(
value(
(),
terminated(
separated_list0(
preceded(tag(","), multispace0),
alt((type_expression, lifetime)),
),
opt(preceded(tag(","), multispace0)),
),
|_| (),
)
.parse(input)
}

fn lifetime(input: &[u8]) -> PResult<()> {
map(delimited(spacelike, tag("'"), rust_name), |_| ()).parse(input)
delimited(spacelike, value((), tag("'")), rust_name).parse(input)
}

#[cfg(test)]
Expand Down

0 comments on commit 808c25b

Please sign in to comment.