Skip to content

Commit 86a5087

Browse files
committed
[assembler] Fixed some Clippy warnings.
1 parent 283043d commit 86a5087

File tree

3 files changed

+18
-21
lines changed

3 files changed

+18
-21
lines changed

assembler/src/asmlib/lexer.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -186,9 +186,9 @@ fn extract_sign(cap: &Captures) -> Result<Option<Sign>, String> {
186186
(false, false) => Ok(None),
187187
(false, true) => Ok(Some(Sign::Minus)),
188188
(true, false) => Ok(Some(Sign::Plus)),
189-
(true, true) => Err(format!(
189+
(true, true) => Err(
190190
"expected to find a single optional leading sign in a numeric literal but found both + and -"
191-
)),
191+
.to_string()),
192192
}
193193
}
194194

@@ -199,7 +199,7 @@ fn capture_subscript_digits(lex: &mut logos::Lexer<Token>) -> NumericLiteral {
199199
lex.slice()
200200
);
201201
};
202-
const RX_PARTS: LazyRegex = LazyRegex::new(concat!(
202+
static CAPTURE_SUBSCRIPT_DIGITS_RX_PARTS: LazyRegex = LazyRegex::new(concat!(
203203
"((?<plus>\u{208A})|(?<minus>\u{208B}))?",
204204
"(?<digits>",
205205
"([₀₁₂₃₄₅₆₇₈₉]",
@@ -208,18 +208,18 @@ fn capture_subscript_digits(lex: &mut logos::Lexer<Token>) -> NumericLiteral {
208208
")+)",
209209
"(?<dot>@sub_dot@)?",
210210
));
211-
const RX_DIGIT: LazyRegex = LazyRegex::new(concat!(
211+
static RX_DIGIT: LazyRegex = LazyRegex::new(concat!(
212212
"(?<sub>[₀₁₂₃₄₅₆₇₈₉])",
213213
"|",
214214
"(@sub_(?<markup_digit>[0-9])@)",
215215
));
216-
let parts_cap = match (*RX_PARTS).captures(lex.slice()) {
216+
let parts_cap = match (*CAPTURE_SUBSCRIPT_DIGITS_RX_PARTS).captures(lex.slice()) {
217217
Some(cap) => cap,
218218
None => {
219219
internal_error(format!(
220220
"token {} does not match parts regex {}",
221221
lex.slice(),
222-
RX_PARTS.as_str()
222+
CAPTURE_SUBSCRIPT_DIGITS_RX_PARTS.as_str()
223223
));
224224
}
225225
};
@@ -294,7 +294,7 @@ fn capture_superscript_digits(lex: &mut logos::Lexer<Token>) -> NumericLiteral {
294294
lex.slice()
295295
);
296296
};
297-
const RX_PARTS: LazyRegex = LazyRegex::new(concat!(
297+
static RX_PARTS: LazyRegex = LazyRegex::new(concat!(
298298
"((?<plus>\u{207A})|(?<minus>\u{207B}))?",
299299
"(?<digits>",
300300
"([\u{2070}\u{00B9}\u{00B2}\u{00B3}\u{2074}\u{2075}\u{2076}\u{2077}\u{2078}\u{2079}]",
@@ -303,7 +303,7 @@ fn capture_superscript_digits(lex: &mut logos::Lexer<Token>) -> NumericLiteral {
303303
")+)",
304304
"(?<dot>@sup_dot@)?",
305305
));
306-
const RX_DIGIT: LazyRegex = LazyRegex::new(concat!(
306+
static RX_DIGIT: LazyRegex = LazyRegex::new(concat!(
307307
"(?<sup>[\u{2070}\u{00B9}\u{00B2}\u{00B3}\u{2074}\u{2075}\u{2076}\u{2077}\u{2078}\u{2079}])",
308308
"|",
309309
"(@sup_(?<markup_digit>[0-9])@)",
@@ -382,7 +382,7 @@ fn capture_superscript_digits(lex: &mut logos::Lexer<Token>) -> NumericLiteral {
382382
}
383383

384384
fn capture_name(lex: &mut logos::Lexer<Token>) -> String {
385-
const RX_GREEK_GLYPHS: LazyRegex =
385+
static RX_GREEK_GLYPHS: LazyRegex =
386386
LazyRegex::new("(@(?<glyph>alpha|beta|gamma|delta|eps|lambda|apostrophe)@|[^@])+");
387387
let slice = lex.slice();
388388
let mut name: String = String::with_capacity(slice.len());
@@ -562,30 +562,30 @@ fn decode_glyphs_by_regex(tokname: &'static str, rx: &Regex, text: &str, script:
562562
}
563563

564564
fn capture_possible_subscript_glyphs(lex: &mut logos::Lexer<Token>) -> String {
565-
const RX_GLYPHS: LazyRegex = LazyRegex::new("(@sub_(?<glyphname>[^@]+)@)|(?<asis>[^@])");
565+
static RX_GLYPHS: LazyRegex = LazyRegex::new("(@sub_(?<glyphname>[^@]+)@)|(?<asis>[^@])");
566566
decode_glyphs_by_regex(
567567
"SubscriptSymexSyllable",
568-
&*RX_GLYPHS,
568+
&RX_GLYPHS,
569569
lex.slice(),
570570
Script::Sub,
571571
)
572572
}
573573

574574
fn capture_possible_superscript_glyphs(lex: &mut logos::Lexer<Token>) -> String {
575-
const RX_GLYPHS: LazyRegex = LazyRegex::new("(@sup_(?<glyphname>[^@]+)@)|(?<asis>[^@])");
575+
static RX_GLYPHS: LazyRegex = LazyRegex::new("(@sup_(?<glyphname>[^@]+)@)|(?<asis>[^@])");
576576
decode_glyphs_by_regex(
577577
"SuperscriptSymexSyllable",
578-
&*RX_GLYPHS,
578+
&RX_GLYPHS,
579579
lex.slice(),
580580
Script::Super,
581581
)
582582
}
583583

584584
fn capture_possible_normal_glyphs(lex: &mut logos::Lexer<Token>) -> String {
585-
const RX_GLYPHS: LazyRegex = LazyRegex::new("(@(?<glyphname>[^@]+)@)|(?<asis>[^@])");
585+
static RX_GLYPHS: LazyRegex = LazyRegex::new("(@(?<glyphname>[^@]+)@)|(?<asis>[^@])");
586586
decode_glyphs_by_regex(
587587
"NormalSymexSyllable",
588-
&*RX_GLYPHS,
588+
&RX_GLYPHS,
589589
lex.slice(),
590590
Script::Normal,
591591
)

assembler/src/asmlib/parser.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ where
171171

172172
symex::symex_syllable(Script::Normal)
173173
.filter(|mnemonic| opcode_code(mnemonic).is_some())
174-
.try_map_with(|mnemonic, extra| match opcode_code(&mnemonic.as_str()) {
174+
.try_map_with(|mnemonic, extra| match opcode_code(mnemonic.as_str()) {
175175
Some(code) => Ok(opcode_to_literal(code, extra.span())),
176176
None => Err(Rich::custom(
177177
extra.span(),
@@ -720,8 +720,7 @@ where
720720
0,
721721
tokens.iter().map(|(_, span)| span.end).max().unwrap_or(0),
722722
);
723-
let token_stream: Mi =
724-
Stream::from_iter(tokens.into_iter()).map(end_span, |unchanged| unchanged);
723+
let token_stream: Mi = Stream::from_iter(tokens).map(end_span, |unchanged| unchanged);
725724
parser
726725
.parse_with_state(token_stream, &mut state)
727726
.into_output_errors()

assembler/src/asmlib/parser/helpers.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,9 +520,7 @@ pub(crate) fn at_glyph(script: Script, name: &str) -> Option<char> {
520520
Script::Sub => "sub_",
521521
Script::Super => "super_",
522522
};
523-
name.strip_prefix(prefix)
524-
.map(|tail| glyph_from_name(tail))
525-
.flatten()
523+
name.strip_prefix(prefix).and_then(glyph_from_name)
526524
}
527525

528526
#[test]

0 commit comments

Comments
 (0)