adding array reformatting rule

This commit is contained in:
Jakub Doka 2024-10-27 16:07:46 +01:00
parent b429534d23
commit 83d3fb4919
No known key found for this signature in database
GPG key ID: C6E9A89936B8C143
2 changed files with 16 additions and 4 deletions

View file

@ -3,7 +3,7 @@ use {
lexer::{self, Lexer, TokenKind}, lexer::{self, Lexer, TokenKind},
parser::{self, CommentOr, CtorField, Expr, Poser, Radix, StructField}, parser::{self, CommentOr, CtorField, Expr, Poser, Radix, StructField},
}, },
core::fmt, core::fmt::{self},
}; };
pub fn display_radix(radix: Radix, mut value: u64, buf: &mut [u8; 64]) -> &str { pub fn display_radix(radix: Radix, mut value: u64, buf: &mut [u8; 64]) -> &str {
@ -263,6 +263,20 @@ impl<'a> Formatter<'a> {
}, },
) )
} }
Expr::Tupl {
pos,
ty: Some(&Expr::Slice { pos: spos, size: Some(&Expr::Number { value, .. }), item }),
fields,
trailing_comma,
} if value as usize == fields.len() => self.fmt(
&Expr::Tupl {
pos,
ty: Some(&Expr::Slice { pos: spos, size: None, item }),
fields,
trailing_comma,
},
f,
),
Expr::Tupl { ty, fields, trailing_comma, .. } => { Expr::Tupl { ty, fields, trailing_comma, .. } => {
if let Some(ty) = ty { if let Some(ty) = ty {
self.fmt_paren(ty, f, unary)?; self.fmt_paren(ty, f, unary)?;

View file

@ -155,9 +155,7 @@ impl<'a, 'b> Parser<'a, 'b> {
fn bin_expr(&mut self, mut fold: Expr<'a>, min_prec: u8, top_level: bool) -> Option<Expr<'a>> { fn bin_expr(&mut self, mut fold: Expr<'a>, min_prec: u8, top_level: bool) -> Option<Expr<'a>> {
loop { loop {
let Some(prec) = self.token.kind.precedence() else { let Some(prec) = self.token.kind.precedence() else { break };
break;
};
if prec <= min_prec { if prec <= min_prec {
break; break;