Skip to content

Commit 50c0ff1

Browse files
authored
Merge branch 'master' into alias-for-compound-labels
2 parents 6f03da9 + 692de91 commit 50c0ff1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+1118
-1105
lines changed

github-graphql/src/lib.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -323,17 +323,11 @@ pub mod project_items {
323323

324324
impl ProjectV2Item {
325325
pub fn status(&self) -> Option<&str> {
326-
let Some(ref status) = self.status else {
327-
return None;
328-
};
329-
status.as_str()
326+
self.status.as_ref()?.as_str()
330327
}
331328

332329
pub fn date(&self) -> Option<Date> {
333-
let Some(ref date) = self.date else {
334-
return None;
335-
};
336-
date.as_date()
330+
self.date.as_ref()?.as_date()
337331
}
338332
}
339333

parser/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
name = "parser"
33
version = "0.1.0"
44
authors = ["Mark Rousskov <[email protected]>"]
5-
edition = "2021"
5+
edition = "2024"
66

77
[dependencies]
88
pulldown-cmark = "0.12.0"

parser/src/command.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ impl<'a> Input<'a> {
6464
pub fn new(input: &'a str, bot: Vec<&'a str>) -> Input<'a> {
6565
let bots: Vec<_> = bot.iter().map(|bot| format!(r"(?:@{bot}\b)")).collect();
6666
let bot_re = Regex::new(&format!(
67-
r#"(?i)(?P<review>\br\?)|{bots}"#,
67+
r"(?i)(?P<review>\br\?)|{bots}",
6868
bots = bots.join("|")
6969
))
7070
.unwrap();
@@ -140,13 +140,12 @@ impl<'a> Input<'a> {
140140
&original_tokenizer,
141141
));
142142

143-
if success.len() > 1 {
144-
panic!(
145-
"succeeded parsing {:?} to multiple commands: {:?}",
146-
&self.all[self.parsed..],
147-
success
148-
);
149-
}
143+
assert!(
144+
success.len() <= 1,
145+
"succeeded parsing {:?} to multiple commands: {:?}",
146+
&self.all[self.parsed..],
147+
success
148+
);
150149

151150
let (mut tok, c) = success.pop()?;
152151
// if we errored out while parsing the command do not move the input forwards
@@ -201,7 +200,7 @@ impl<'a> Iterator for Input<'a> {
201200
}
202201
}
203202

204-
impl<'a> Command<'a> {
203+
impl Command<'_> {
205204
pub fn is_ok(&self) -> bool {
206205
match self {
207206
Command::Relabel(r) => r.is_ok(),

parser/src/command/assign.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,12 @@ impl AssignCommand {
4848
let mut toks = input.clone();
4949
if let Some(Token::Word("claim")) = toks.peek_token()? {
5050
toks.next_token()?;
51-
if let Some(Token::Dot) | Some(Token::EndOfLine) = toks.peek_token()? {
51+
if let Some(Token::Dot | Token::EndOfLine) = toks.peek_token()? {
5252
toks.next_token()?;
5353
*input = toks;
54-
return Ok(Some(AssignCommand::Claim));
54+
Ok(Some(AssignCommand::Claim))
5555
} else {
56-
return Err(toks.error(ParseError::ExpectedEnd));
56+
Err(toks.error(ParseError::ExpectedEnd))
5757
}
5858
} else if let Some(Token::Word("assign")) = toks.peek_token()? {
5959
toks.next_token()?;
@@ -63,22 +63,22 @@ impl AssignCommand {
6363
username: user[1..].to_owned(),
6464
}))
6565
} else {
66-
return Err(toks.error(ParseError::MentionUser));
66+
Err(toks.error(ParseError::MentionUser))
6767
}
6868
} else {
69-
return Err(toks.error(ParseError::NoUser));
69+
Err(toks.error(ParseError::NoUser))
7070
}
7171
} else if let Some(Token::Word("release-assignment" | "unclaim")) = toks.peek_token()? {
7272
toks.next_token()?;
73-
if let Some(Token::Dot) | Some(Token::EndOfLine) = toks.peek_token()? {
73+
if let Some(Token::Dot | Token::EndOfLine) = toks.peek_token()? {
7474
toks.next_token()?;
7575
*input = toks;
76-
return Ok(Some(AssignCommand::ReleaseAssignment));
76+
Ok(Some(AssignCommand::ReleaseAssignment))
7777
} else {
78-
return Err(toks.error(ParseError::ExpectedEnd));
78+
Err(toks.error(ParseError::ExpectedEnd))
7979
}
8080
} else {
81-
return Ok(None);
81+
Ok(None)
8282
}
8383
}
8484

parser/src/command/concern.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ impl ConcernCommand {
2828
if let Some(Token::Word(mut action @ ("concern" | "resolve"))) = toks.peek_token()? {
2929
toks.next_token()?;
3030

31-
if action == "concern" {
32-
if let Some(Token::Word(sub_action @ "resolve")) = toks.peek_token()? {
33-
toks.next_token()?;
34-
action = sub_action;
35-
}
31+
if action == "concern"
32+
&& let Some(Token::Word(sub_action @ "resolve")) = toks.peek_token()?
33+
{
34+
toks.next_token()?;
35+
action = sub_action;
3636
}
3737

3838
let title = toks.take_line()?.trim().to_string();

parser/src/command/nominate.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,26 +55,23 @@ impl NominateCommand {
5555
let style = match toks.peek_token()? {
5656
Some(Token::Word("beta-nominate")) => Style::Beta,
5757
Some(Token::Word("nominate")) => Style::Decision,
58-
Some(Token::Word("beta-accept")) => Style::BetaApprove,
59-
Some(Token::Word("beta-approve")) => Style::BetaApprove,
58+
Some(Token::Word("beta-accept" | "beta-approve")) => Style::BetaApprove,
6059
None | Some(_) => return Ok(None),
6160
};
6261
toks.next_token()?;
63-
let team = if style != Style::BetaApprove {
64-
if let Some(Token::Word(team)) = toks.next_token()? {
65-
team.to_owned()
66-
} else {
67-
return Err(toks.error(ParseError::NoTeam));
68-
}
69-
} else {
62+
let team = if style == Style::BetaApprove {
7063
String::new()
64+
} else if let Some(Token::Word(team)) = toks.next_token()? {
65+
team.to_owned()
66+
} else {
67+
return Err(toks.error(ParseError::NoTeam));
7168
};
72-
if let Some(Token::Dot) | Some(Token::EndOfLine) = toks.peek_token()? {
69+
if let Some(Token::Dot | Token::EndOfLine) = toks.peek_token()? {
7370
toks.next_token()?;
7471
*input = toks;
75-
return Ok(Some(NominateCommand { team, style }));
72+
Ok(Some(NominateCommand { team, style }))
7673
} else {
77-
return Err(toks.error(ParseError::ExpectedEnd));
74+
Err(toks.error(ParseError::ExpectedEnd))
7875
}
7976
}
8077
}

parser/src/command/ping.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ impl PingCommand {
4444
} else {
4545
return Err(toks.error(ParseError::NoTeam));
4646
};
47-
if let Some(Token::Dot) | Some(Token::EndOfLine) = toks.peek_token()? {
47+
if let Some(Token::Dot | Token::EndOfLine) = toks.peek_token()? {
4848
toks.next_token()?;
4949
*input = toks;
50-
return Ok(Some(PingCommand { team }));
50+
Ok(Some(PingCommand { team }))
5151
} else {
52-
return Err(toks.error(ParseError::ExpectedEnd));
52+
Err(toks.error(ParseError::ExpectedEnd))
5353
}
5454
} else {
55-
return Ok(None);
55+
Ok(None)
5656
}
5757
}
5858
}

parser/src/command/relabel.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ impl Label {
5151
}
5252

5353
impl std::ops::Deref for Label {
54-
type Target = String;
55-
fn deref(&self) -> &String {
56-
&self.0
54+
type Target = str;
55+
fn deref(&self) -> &str {
56+
self.0.as_str()
5757
}
5858
}
5959

@@ -68,13 +68,13 @@ impl LabelDelta {
6868
return Err(input.error(ParseError::ExpectedLabelDelta));
6969
}
7070
};
71-
if delta.starts_with('+') {
71+
if let Some(label) = delta.strip_prefix('+') {
7272
Ok(LabelDelta::Add(
73-
Label::parse(&delta[1..]).map_err(|e| input.error(e))?,
73+
Label::parse(label).map_err(|e| input.error(e))?,
7474
))
75-
} else if delta.starts_with('-') {
75+
} else if let Some(label) = delta.strip_prefix('-') {
7676
Ok(LabelDelta::Remove(
77-
Label::parse(&delta[1..]).map_err(|e| input.error(e))?,
77+
Label::parse(label).map_err(|e| input.error(e))?,
7878
))
7979
} else {
8080
Ok(LabelDelta::Add(
@@ -85,8 +85,7 @@ impl LabelDelta {
8585

8686
pub fn label(&self) -> &Label {
8787
match self {
88-
LabelDelta::Add(l) => l,
89-
LabelDelta::Remove(l) => l,
88+
LabelDelta::Add(l) | LabelDelta::Remove(l) => l,
9089
}
9190
}
9291
}
@@ -130,9 +129,7 @@ impl RelabelCommand {
130129
toks.eat_token(Token::Comma)?;
131130
toks.eat_token(Token::Word("and"))?;
132131

133-
if let Some(Token::Semi) | Some(Token::Dot) | Some(Token::EndOfLine) =
134-
toks.peek_token()?
135-
{
132+
if let Some(Token::Semi | Token::Dot | Token::EndOfLine) = toks.peek_token()? {
136133
toks.next_token()?;
137134
*input = toks;
138135
return Ok(Some(RelabelCommand(deltas)));

parser/src/command/shortcut.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,21 @@ impl fmt::Display for ParseError {
3333

3434
impl ShortcutCommand {
3535
pub fn parse<'a>(input: &mut Tokenizer<'a>) -> Result<Option<Self>, Error<'a>> {
36-
let mut shortcuts = HashMap::new();
37-
shortcuts.insert("ready", ShortcutCommand::Ready);
38-
shortcuts.insert("review", ShortcutCommand::Ready);
39-
shortcuts.insert("reviewer", ShortcutCommand::Ready);
40-
shortcuts.insert("author", ShortcutCommand::Author);
41-
shortcuts.insert("blocked", ShortcutCommand::Blocked);
36+
let shortcuts = HashMap::from([
37+
("ready", ShortcutCommand::Ready),
38+
("review", ShortcutCommand::Ready),
39+
("reviewer", ShortcutCommand::Ready),
40+
("author", ShortcutCommand::Author),
41+
("blocked", ShortcutCommand::Blocked),
42+
]);
4243

4344
let mut toks = input.clone();
4445
if let Some(Token::Word(word)) = toks.peek_token()? {
45-
if !shortcuts.contains_key(word) {
46+
let Some(command) = shortcuts.get(word) else {
4647
return Ok(None);
47-
}
48+
};
4849
toks.next_token()?;
4950
*input = toks;
50-
let command = shortcuts.get(word).unwrap();
5151
return Ok(Some(*command));
5252
}
5353
Ok(None)
@@ -57,7 +57,7 @@ impl ShortcutCommand {
5757
#[cfg(test)]
5858
fn parse(input: &str) -> Result<Option<ShortcutCommand>, Error<'_>> {
5959
let mut toks = Tokenizer::new(input);
60-
Ok(ShortcutCommand::parse(&mut toks)?)
60+
ShortcutCommand::parse(&mut toks)
6161
}
6262

6363
#[test]

parser/src/error.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,25 @@ pub struct Error<'a> {
88
pub source: Box<dyn error::Error + Send>,
99
}
1010

11-
impl<'a> PartialEq for Error<'a> {
11+
impl PartialEq for Error<'_> {
1212
fn eq(&self, other: &Self) -> bool {
1313
self.input == other.input && self.position == other.position
1414
}
1515
}
1616

17-
impl<'a> error::Error for Error<'a> {
17+
impl error::Error for Error<'_> {
1818
fn source(&self) -> Option<&(dyn error::Error + 'static)> {
1919
Some(&*self.source)
2020
}
2121
}
2222

23-
impl<'a> Error<'a> {
23+
impl Error<'_> {
2424
pub fn position(&self) -> usize {
2525
self.position
2626
}
2727
}
2828

29-
impl<'a> fmt::Display for Error<'a> {
29+
impl fmt::Display for Error<'_> {
3030
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
3131
let space = 10;
3232
let end = std::cmp::min(self.input.len(), self.position + space);

0 commit comments

Comments
 (0)